Implement simplified commercials workflow

It's now possible to simply enter the url of the third party provider to enter a commercial.
This commit is contained in:
chrisbr 2015-04-22 21:30:32 +02:00
parent e6bb168c5e
commit 58974d6914
26 changed files with 194 additions and 188 deletions

View file

@ -124,6 +124,8 @@ gem 'acts_as_list'
# for switch checkboxes # for switch checkboxes
gem 'bootstrap-switch-rails', '~> 3.0.0' gem 'bootstrap-switch-rails', '~> 3.0.0'
gem 'ruby-oembed'
# Use guard and spring for testing in development # Use guard and spring for testing in development
group :development do group :development do
# rspec Guard rules # rspec Guard rules

View file

@ -367,6 +367,7 @@ GEM
powerpack (~> 0.0.6) powerpack (~> 0.0.6)
rainbow (>= 1.99.1, < 3.0) rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4) ruby-progressbar (~> 1.4)
ruby-oembed (0.8.12)
ruby-openid (2.5.0) ruby-openid (2.5.0)
ruby-progressbar (1.5.1) ruby-progressbar (1.5.1)
rubyzip (1.0.0) rubyzip (1.0.0)
@ -495,6 +496,7 @@ DEPENDENCIES
rspec-activemodel-mocks rspec-activemodel-mocks
rspec-rails rspec-rails
rubocop rubocop
ruby-oembed
sass-rails (>= 4.0.2) sass-rails (>= 4.0.2)
shoulda shoulda
spring-commands-rspec spring-commands-rspec

View file

@ -37,6 +37,7 @@
//= require bootstrap-switch //= require bootstrap-switch
//= require osem-switch //= require osem-switch
//= require osem-bootstrap //= require osem-bootstrap
//= require osem-commercials
$(document).ready(function() { $(document).ready(function() {
$('a[disabled=disabled]').click(function(event){ $('a[disabled=disabled]').click(function(event){

View file

@ -0,0 +1,17 @@
$(function () {
$(document).ready(function() {
$('#commercial_url').focusout(function(){
var url = $('#new_commercial').attr('action');
url = url + '/get_html'
$.ajax({
method: 'GET',
url: url,
data: { url: $(this).val() }
})
.done(function( msg ) {
$('#resource-content').html(msg);
});
});
});
});

View file

@ -5,15 +5,11 @@ module Admin
def index def index
@commercials = @conference.commercials @commercials = @conference.commercials
end
def new
@commercial = @conference.commercials.build @commercial = @conference.commercials.build
authorize! :create, @conference.commercials.new authorize! :create, @commercial
end end
def edit; end
def create def create
@commercial = @conference.commercials.build(commercial_params) @commercial = @conference.commercials.build(commercial_params)
authorize! :create, @commercial authorize! :create, @commercial
@ -22,8 +18,8 @@ module Admin
redirect_to admin_conference_commercials_path, redirect_to admin_conference_commercials_path,
notice: 'Commercial was successfully created.' notice: 'Commercial was successfully created.'
else else
flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." redirect_to admin_conference_commercials_path,
render :new error: "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}."
end end
end end
@ -32,8 +28,8 @@ module Admin
redirect_to admin_conference_commercials_path, redirect_to admin_conference_commercials_path,
notice: 'Commercial was successfully updated.' notice: 'Commercial was successfully updated.'
else else
flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." redirect_to admin_conference_commercials_path,
render :edit error: "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}."
end end
end end
@ -42,6 +38,10 @@ module Admin
redirect_to admin_conference_commercials_path, notice: 'Commercial was successfully destroyed.' redirect_to admin_conference_commercials_path, notice: 'Commercial was successfully destroyed.'
end end
def get_html
render text: Commercial.get_content(params[:url])
end
private private
def commercial_params def commercial_params

View file

@ -3,13 +3,6 @@ class CommercialsController < ApplicationController
before_action :set_event before_action :set_event
load_and_authorize_resource through: :event load_and_authorize_resource through: :event
def new
@commercial = @event.commercials.build
authorize! :new, @commercial
end
def edit; end
def create def create
@commercial = @event.commercials.build(commercial_params) @commercial = @event.commercials.build(commercial_params)
authorize! :create, @commercial authorize! :create, @commercial
@ -35,10 +28,14 @@ class CommercialsController < ApplicationController
def destroy def destroy
@commercial.destroy @commercial.destroy
redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id), redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'),
notice: 'Commercial was successfully destroyed.' notice: 'Commercial was successfully destroyed.'
end end
def get_html
render text: Commercial.get_content(params[:url])
end
private private
def set_event def set_event

View file

@ -20,6 +20,8 @@ class ProposalController < ApplicationController
def edit def edit
authorize! :edit, @event authorize! :edit, @event
@url = conference_proposal_path(@conference.short_title, params[:id]) @url = conference_proposal_path(@conference.short_title, params[:id])
@commercial = @event.commercials.build
authorize! :new, @commercial
end end
def create def create

View file

@ -1,10 +1,43 @@
class Commercial < ActiveRecord::Base class Commercial < ActiveRecord::Base
require 'oembed'
belongs_to :commercialable, polymorphic: true belongs_to :commercialable, polymorphic: true
attr_accessible :commercial_id, :commercial_type attr_accessible :url
validates :commercial_id, presence: true validates :url, presence: true
validates :commercial_type, presence: true validates :url, format: URI::regexp(%w(http https))
validates :commercial_type, inclusion: { in: CONFIG['commercial_types'].values } def self.provider
{
youtube: 'YouTube',
slideshare: 'SlideShare',
flickr: 'Flickr',
vimeo: 'Vimeo',
speakerdeck: 'Speakerdeck',
instagram: 'Instagram'
}
end
def self.get_content(url)
speakerdeck = OEmbed::Provider.new('http://speakerdeck.com/oembed.json')
speakerdeck << 'https://speakerdeck.com/*'
speakerdeck << 'http://speakerdeck.com/*'
OEmbed::Providers.register(
OEmbed::Providers::Youtube,
OEmbed::Providers::Vimeo,
OEmbed::Providers::Slideshare,
OEmbed::Providers::Flickr,
OEmbed::Providers::Instagram,
speakerdeck
)
begin
resource = OEmbed::Providers.get(url, maxwidth: 560, maxheight: 315)
resource.html
rescue StandardError
''
end
end
end end

View file

@ -1,15 +0,0 @@
.row
.col-md-12
.page-header
%h1
-if @commercial.new_record?
New
Commercial
.row
.col-md-8
= semantic_form_for(@commercial, :url => (@commercial.new_record? ? admin_conference_commercials_path : admin_conference_commercial_path(@conference.short_title, @commercial))) do |f|
= f.input :commercial_type, as: :select, label: 'Conference Promo Media Type', input_html: { class: 'select-help-toggle' }, collection: CONFIG['commercial_types'].values, include_blank: false, hint: 'This media-item will be used to represent this conference at various places in OSEM.'
= f.input :commercial_id, label: 'Conference Promo Media ID', as: :string
= render partial: 'commercials/commercial_help'
%p.text-right
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }

View file

@ -6,22 +6,33 @@
Conference commercials will be displayed on the events in the Conference commercials will be displayed on the events in the
= link_to "schedule,", schedule_conference_path(@conference.short_title) = link_to "schedule,", schedule_conference_path(@conference.short_title)
if the event speaker didn't add an event commercial. if the event speaker didn't add an event commercial.
- if can? :create, @conference.commercials.new
.row
.col-md-6
= semantic_form_for @commercial, url: admin_conference_commercials_path(conference_id: @conference.short_title) do |f|
= f.input :url, label: 'URL', as: :string, input_html: { required: 'required' }, hint: 'Just paste the url of your video/photo provider'
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right' }
.col-md-6
#resource-content
%hr
- @commercials.each_slice(3) do |slice| - @commercials.each_slice(3) do |slice|
.row .row
- slice.each do |commercial| - slice.each do |commercial|
.col-md-4 - if commercial.persisted?
.thumbnail .col-md-4
%h3.text-center .thumbnail
= commercial.commercial_type .flexvideo{ id: "resource-content-#{commercial.id}"}
.flexvideo -# This is for backward compatibility
= render partial: 'shared/media_item', locals: { commercial_type: commercial.commercial_type, commercial_id: commercial.commercial_id } - if commercial.url
.caption = Commercial.get_content(commercial.url).html_safe
- if can? :update, commercial - else
= link_to 'Edit', edit_admin_conference_commercial_path(@conference.short_title, commercial.id), class: 'btn btn-primary' = render partial: 'shared/media_item', locals: { commercial_type: commercial.commercial_type, commercial_id: commercial.commercial_id }
- if can? :destroy, commercial .caption
= link_to 'Delete', admin_conference_commercial_path(@conference.short_title, commercial.id), - if can? :update, commercial
method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' = semantic_form_for commercial, url: admin_conference_commercial_path(conference_id: @conference.short_title, id: commercial) do |f|
.row = f.input :url, label: 'URL', as: :string, input_html: { id: "commercial_url_#{commercial.id}", required: 'required' }, hint: 'Just paste the url of your video/photo provider'
.col-md-12.text-right = f.action :submit, as: :button, button_html: { class: 'btn btn-success' }, label: 'Update'
- if can? :create, @conference.commercials.new - if can? :destroy, commercial
= link_to 'Add Commercial', new_admin_conference_commercial_path, class: 'btn btn-primary' = link_to 'Delete', admin_conference_commercial_path(@conference.short_title, commercial.id),
method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger'

View file

@ -1,6 +0,0 @@
%p{ class: 'help-block commercial_commercial_type collapse in', id: 'YouTube-help' } Go to your YouTube video, click on "share" and copy everything behind http://youtu.be/"
%p{ class: 'help-block commercial_commercial_type collapse', id: 'SlideShare-help' } Go to your SlideShare, click on "share" -> "embed" and copy the id
%p{ class: 'help-block commercial_commercial_type collapse', id: 'Flickr-help' } Go to your flickr image, click on "Grab the link" -> "Show short url" and copy everything behind https://flic.kr/p/
%p{ class: 'help-block commercial_commercial_type collapse', id: 'Vimeo-help' } Go to your vimeo video, click on "share" and copy everything behind http://vimeo.com/
%p{ class: 'help-block commercial_commercial_type collapse', id: 'Speakerdeck-help' } Go to your SpeakerDeck, click on "share" -> "embed" and copy the data-id
%p{ class: 'help-block commercial_commercial_type collapse', id: 'Instagram-help' } Go to your Instagram photo page and copy everything behind instagram.com/p/ (without trailing /# hash symbol)

View file

@ -1,4 +0,0 @@
= f.input :commercial_type, as: :select, label: 'Type', input_html: { class: 'form-control select-help-toggle' }, collection: CONFIG['commercial_types'].values, include_blank: false, hint: 'This media-item will be used to represent this conference at various places in OSEM.'
= f.input :commercial_id, label: 'ID', as: :string, input_html: { required: 'required' }
= render partial: 'commercial_help'
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right' }

View file

@ -1,9 +0,0 @@
.container
.row
.col-md-12
.page-header
%h1 Editing Commercial
.row
.col-md-12
= semantic_form_for @commercial, url: conference_proposal_commercial_path(conference_id: @conference.short_title, proposal_id: @event.id, id: @commercial.id) do |f|
= render 'form', f: f

View file

@ -1,9 +0,0 @@
.container
.row
.col-md-12
.page-header
%h1 New Commercial
.row
.col-md-12
= semantic_form_for @commercial, url: conference_proposal_commercials_path(conference_id: @conference.short_title, proposal_id: @event.id) do |f|
= render 'form', f: f

View file

@ -15,21 +15,33 @@
You can add commercials for your proposal. These commercials will be displayed on the You can add commercials for your proposal. These commercials will be displayed on the
= link_to 'public proposal page.', conference_proposal_path(@conference.short_title, @event) = link_to 'public proposal page.', conference_proposal_path(@conference.short_title, @event)
If you don't add a commercial, the conference commercial will be displayed! If you don't add a commercial, the conference commercial will be displayed!
- if can? :create, @event.commercials.new
.row
.col-md-6
= semantic_form_for @commercial, url: conference_proposal_commercials_path(conference_id: @conference.short_title, proposal_id: @event) do |f|
= f.input :url, label: 'URL', as: :string, input_html: { required: 'required', type: 'url' },
hint: 'Just paste the url of your video/photo provider. Currently supported: YouTupe, Vimeo, SpeakerDeck, SlideShare, Instagram, Flickr.'
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right' }
.col-md-6
#resource-content
%hr
- @event.commercials.each_slice(3) do |slice| - @event.commercials.each_slice(3) do |slice|
.row .row
- slice.each do |commercial| - slice.each do |commercial|
.col-md-4 - if commercial.persisted?
.thumbnail .col-md-4
%h3.text-center .thumbnail
= commercial.commercial_type .flexvideo{ id: "resource-content-#{commercial.id}"}
.flexvideo -# This is for backward compatibility
= render partial: 'shared/media_item', locals: { commercial_type: commercial.commercial_type, commercial_id: commercial.commercial_id } - if commercial.url
- if can? :update, commercial = Commercial.get_content(commercial.url).html_safe
= link_to 'Edit', edit_conference_proposal_commercial_path(@conference.short_title, @event.id, commercial.id), class: 'btn btn-primary' - else
- if can? :destroy, commercial = render partial: 'shared/media_item', locals: { commercial_type: commercial.commercial_type, commercial_id: commercial.commercial_id }
= link_to 'Delete', conference_proposal_commercial_path(@conference.short_title, @event.id, commercial.id), .caption
:method => :delete, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-danger' - if can? :update, commercial
- if can? :create, @event.commercials.new = semantic_form_for commercial, url: conference_proposal_commercial_path(conference_id: @conference.short_title, proposal_id: @event, id: commercial) do |f|
%hr = f.input :url, label: 'URL', as: :string, input_html: { id: "commercial_url_#{commercial.id}", required: 'required', type: 'url' }
= link_to 'Add Commercial', new_conference_proposal_commercial_path(@conference.short_title, @event.id), class: 'btn btn-primary' = f.action :submit, as: :button, button_html: { class: 'btn btn-success' }, label: 'Update'
- if can? :destroy, commercial
= link_to 'Delete', conference_proposal_commercial_path(@conference.short_title, @event.id, commercial.id),
:method => :delete, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-danger'

View file

@ -26,7 +26,7 @@
- if progress_status['commercials'] - if progress_status['commercials']
= link_to 'Edit the commercials', edit_conference_proposal_path(event.conference.short_title, event, anchor: 'commercials-content') = link_to 'Edit the commercials', edit_conference_proposal_path(event.conference.short_title, event, anchor: 'commercials-content')
- else - else
= link_to 'Add a commercial', new_conference_proposal_commercial_path(event.conference.short_title, event) = link_to 'Add a commercial', edit_conference_proposal_path(event.conference.short_title, event, anchor: 'commercials-content')
%li{'class'=>class_for_todo(progress_status['difficulty_level'])} %li{'class'=>class_for_todo(progress_status['difficulty_level'])}
%span{'class'=>icon_for_todo(progress_status['difficulty_level'])} %span{'class'=>icon_for_todo(progress_status['difficulty_level'])}

View file

@ -1,12 +1,12 @@
-if commercial_type == CONFIG['commercial_types']['slideshare'] -if commercial_type == Commercial.provider['slideshare']
%iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :src=> (request.ssl? ? "https://" : "http://") + "www.slideshare.net/slideshow/embed_code/#{commercial_id}"} %iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :src=> (request.ssl? ? "https://" : "http://") + "www.slideshare.net/slideshow/embed_code/#{commercial_id}"}
-elsif commercial_type == CONFIG['commercial_types']['flickr'] -elsif commercial_type == Commercial.provider['flickr']
%iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :src=> (request.ssl? ? "https://" : "http://") + "flic.kr/p/#{commercial_id}/player/268a054da2"} %iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :src=> (request.ssl? ? "https://" : "http://") + "flic.kr/p/#{commercial_id}/player/268a054da2"}
-elsif commercial_type == CONFIG['commercial_types']['vimeo'] -elsif commercial_type == Commercial.provider['vimeo']
%iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :src=> "//player.vimeo.com/video/#{commercial_id}"} %iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :src=> "//player.vimeo.com/video/#{commercial_id}"}
-elsif commercial_type == CONFIG['commercial_types']['speakerdeck'] -elsif commercial_type == Commercial.provider['speakerdeck']
%iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :src=> "//speakerdeck.com/player/#{commercial_id}?"} %iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :src=> "//speakerdeck.com/player/#{commercial_id}?"}
-elsif commercial_type == CONFIG['commercial_types']['instagram'] -elsif commercial_type == Commercial.provider['instagram']
%iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :scrolling =>"no", :allowtransparency=>"true", :src=> "//instagram.com/p/#{commercial_id}/embed/"} %iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :scrolling =>"no", :allowtransparency=>"true", :src=> "//instagram.com/p/#{commercial_id}/embed/"}
-else -else
%iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :src=> (request.ssl? ? "https://" : "http://") + "www.youtube.com/embed/#{commercial_id}?rel=0"} %iframe{:width=>"560", :height=>"315", :frameborder=>"0", :allowfullscreen=>"true", :src=> (request.ssl? ? "https://" : "http://") + "www.youtube.com/embed/#{commercial_id}?rel=0"}

View file

@ -1,25 +1,37 @@
- unless commercials.empty? - unless commercials.empty?
- if commercials.length == 1 - if commercials.length == 1
.flexvideo .flexvideo
= render partial: 'shared/media_item', locals: { commercial_type: commercials.first.commercial_type, commercial_id: commercials.first.commercial_id } -# This is for backward compatibility
- if commercials.first.url
= Commercial.get_content(commercials.first.url).html_safe
- else
= render partial: 'shared/media_item', locals: { commercial_type: commercials.first.commercial_type, commercial_id: commercials.first.commercial_id }
- else - else
%ul.nav.nav-tabs{ 'role'=>'tablist' } %ul.nav.nav-tabs{ 'role'=>'tablist' }
- commercials.each_with_index do |commercial, index| - commercials.each.with_index(1) do |commercial, index|
- if index == 0 - if index == 1
%li.active %li.active
%a{ 'href'=>"##{index}", 'role'=>'tab', 'data-toggle'=>'tab' } %a{ 'href'=>"##{index}", 'role'=>'tab', 'data-toggle'=>'tab' }
= commercial.commercial_type = index
- else - else
%li %li
%a{ 'href'=>"##{index}",' "role"'=>'tab', 'data-toggle'=>'tab' } %a{ 'href'=>"##{index}",' "role"'=>'tab', 'data-toggle'=>'tab' }
= commercial.commercial_type = index
.tab-content .tab-content
- commercials.each_with_index do |commercial, index| - commercials.each.with_index(1) do |commercial, index|
- if index == 0 - if index == 1
%div.tab-pane.active{'id'=>"#{index}"} %div.tab-pane.active{'id'=>"#{index}"}
.flexvideo .flexvideo
= render partial: 'shared/media_item', locals: { commercial_type: commercial.commercial_type, commercial_id: commercial.commercial_id } -# This is for backward compatibility
- if commercial.url
= Commercial.get_content(commercial.url).html_safe
- else
= render partial: 'shared/media_item', locals: { commercial_type: commercial.commercial_type, commercial_id: commercial.commercial_id }
- else - else
%div.tab-pane{'id'=>"#{index}"} %div.tab-pane{'id'=>"#{index}"}
.flexvideo .flexvideo
= render partial: 'shared/media_item', locals: { commercial_type: commercial.commercial_type, commercial_id: commercial.commercial_id } -# This is for backward compatibility
- if commercial.url
= Commercial.get_content(commercial.url).html_safe
- else
= render partial: 'shared/media_item', locals: { commercial_type: commercial.commercial_type, commercial_id: commercial.commercial_id }

View file

@ -9,12 +9,6 @@ defaults: &defaults
#errbit_key: See config/secrets.yml #errbit_key: See config/secrets.yml
#errbit_host: errbit.exmaple.com #errbit_host: errbit.exmaple.com
# These are the currently supported commercial types for conference and events # These are the currently supported commercial types for conference and events
commercial_types: { youtube: 'YouTube',
slideshare: 'SlideShare',
flickr: 'Flickr',
vimeo: 'Vimeo',
speakerdeck: 'Speakerdeck',
instagram: 'Instagram' }
# If you want to use iChain to handle registration and authentication enable the next lines # If you want to use iChain to handle registration and authentication enable the next lines
authentication: authentication:

View file

@ -25,7 +25,8 @@ Osem::Application.routes.draw do
resource :contact, except: [:index, :new, :create, :show, :destroy] resource :contact, except: [:index, :new, :create, :show, :destroy]
resources :photos, except: [:show] resources :photos, except: [:show]
resource :schedule, only: [:show, :update] resource :schedule, only: [:show, :update]
resources :commercials, except: [:show] get 'commercials/get_html' => 'commercials#get_html'
resources :commercials, only: [:index, :create, :update, :destroy]
get '/stats' => 'stats#index' get '/stats' => 'stats#index'
get '/dietary_choices' => 'dietchoices#show', as: 'dietary_list' get '/dietary_choices' => 'dietchoices#show', as: 'dietary_list'
patch '/dietary_choices' => 'dietchoices#update', as: 'dietary_update' patch '/dietary_choices' => 'dietchoices#update', as: 'dietary_update'
@ -88,7 +89,8 @@ Osem::Application.routes.draw do
resources :conference, only: [:index, :show] do resources :conference, only: [:index, :show] do
resources :proposal do resources :proposal do
resources :commercials, except: [:show, :index] get 'commercials/get_html' => 'commercials#get_html'
resources :commercials, only: [:create, :update, :destroy]
resources :event_attachment, controller: 'event_attachments' resources :event_attachment, controller: 'event_attachments'
member do member do
patch '/confirm' => 'proposal#confirm' patch '/confirm' => 'proposal#confirm'

View file

@ -0,0 +1,11 @@
class AddUrlToCommercial < ActiveRecord::Migration
class TempCommercial< ActiveRecord::Base
self.table_name = 'commercials'
end
def change
add_column :commercials, :url, :string
# Don't delete commercial_type and commercial_id for backward compatibility
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150415121038) do ActiveRecord::Schema.define(version: 20150417050953) do
create_table "ahoy_events", force: true do |t| create_table "ahoy_events", force: true do |t|
t.uuid "visit_id" t.uuid "visit_id"
@ -79,6 +79,7 @@ ActiveRecord::Schema.define(version: 20150415121038) do
t.string "commercialable_type" t.string "commercialable_type"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "url"
end end
create_table "conferences", force: true do |t| create_table "conferences", force: true do |t|

View file

@ -2,8 +2,7 @@
FactoryGirl.define do FactoryGirl.define do
factory :commercial do factory :commercial do
commercial_type 'YouTube' url 'https://www.youtube.com/watch?v=BTTygyxuGj8'
commercial_id 'test'
factory :conference_commercial do factory :conference_commercial do
association :commercialable, factory: :conference association :commercialable, factory: :conference

View file

@ -167,7 +167,7 @@ feature 'Has correct abilities' do
expect(current_path).to eq(root_path) expect(current_path).to eq(root_path)
visit admin_conference_commercials_path(conference2.short_title) visit admin_conference_commercials_path(conference2.short_title)
expect(current_path).to eq(admin_conference_commercials_path(conference2.short_title)) expect(current_path).to eq(root_path)
end end
scenario 'when user is info desk' do scenario 'when user is info desk' do
@ -238,6 +238,6 @@ feature 'Has correct abilities' do
expect(current_path).to eq(admin_conference_questions_path(conference3.short_title)) expect(current_path).to eq(admin_conference_questions_path(conference3.short_title))
visit admin_conference_commercials_path(conference3.short_title) visit admin_conference_commercials_path(conference3.short_title)
expect(current_path).to eq(admin_conference_commercials_path(conference3.short_title)) expect(current_path).to eq(root_path)
end end
end end

View file

@ -14,41 +14,24 @@ feature Commercial do
sign_in organizer sign_in organizer
visit admin_conference_commercials_path(conference.short_title) visit admin_conference_commercials_path(conference.short_title)
click_link 'Add Commercial'
# Create without an commercial id
select('SlideShare', from: 'commercial_commercial_type')
click_button 'Create Commercial' click_button 'Create Commercial'
expect(flash).to eq("An error prohibited this Commercial from being saved: Commercial can't be blank.")
expect(conference.commercials.count).to eq(expected_count - 1) expect(conference.commercials.count).to eq(expected_count - 1)
# Create valid commercial # Create valid commercial
select('SlideShare', from: 'commercial_commercial_type') fill_in 'commercial_url', with: 'https://www.youtube.com/watch?v=12345'
fill_in 'commercial_commercial_id', with: '12345'
click_button 'Create Commercial' click_button 'Create Commercial'
expect(flash).to eq('Commercial was successfully created.') expect(flash).to eq('Commercial was successfully created.')
expect(conference.commercials.count).to eq(expected_count) expect(conference.commercials.count).to eq(expected_count)
expect(page.has_content?('SlideShare')).to be true
click_link 'Edit' commercial = conference.commercials.where(url: 'https://www.youtube.com/watch?v=12345').first
fill_in "commercial_url_#{commercial.id}", with: 'https://www.youtube.com/watch?v=6789'
click_button 'Update'
# Update without an commercial id
select('YouTube', from: 'commercial_commercial_type')
fill_in 'commercial_commercial_id', with: ''
click_button 'Update Commercial'
expect(flash).to eq("An error prohibited this Commercial from being saved: Commercial can't be blank.")
expect(conference.commercials.count).to eq(expected_count)
# Update valid commercial
select('YouTube', from: 'commercial_commercial_type')
fill_in 'commercial_commercial_id', with: '678910'
click_button 'Update Commercial'
expect(flash).to eq('Commercial was successfully updated.') expect(flash).to eq('Commercial was successfully updated.')
expect(conference.commercials.count).to eq(expected_count) expect(conference.commercials.count).to eq(expected_count)
commercial.reload
expect(commercial.url).to eq 'https://www.youtube.com/watch?v=6789'
# Delete commercial # Delete commercial
click_link 'Delete' click_link 'Delete'
@ -75,59 +58,30 @@ feature Commercial do
sign_out sign_out
end end
scenario 'adds a valid commercial to an event', feature: true, js: true do scenario 'adds a commercial of an event', feature: true, js: true do
visit edit_conference_proposal_path(conference.short_title, event.id) visit edit_conference_proposal_path(conference.short_title, event.id)
click_link 'Commercials' click_link 'Commercials'
click_link 'Add Commercial' fill_in 'commercial_url', with: 'https://www.youtube.com/watch?v=12345'
select('SlideShare', from: 'commercial_commercial_type')
fill_in 'commercial_commercial_id', with: '12345'
click_button 'Create Commercial' click_button 'Create Commercial'
expect(flash).to eq('Commercial was successfully created.') expect(flash).to eq('Commercial was successfully created.')
expect(event.commercials.count).to eq(@expected_count) expect(event.commercials.count).to eq(@expected_count)
end end
scenario 'adds an invalid commercial to an event', feature: true, js: true do scenario 'updates a commercial of an event', feature: true, js: true do
commercial = create(:commercial,
commercialable_id: event.id,
commercialable_type: 'Event')
visit edit_conference_proposal_path(conference.short_title, event.id) visit edit_conference_proposal_path(conference.short_title, event.id)
click_link 'Commercials' click_link 'Commercials'
click_link 'Add Commercial' fill_in "commercial_url_#{commercial.id}", with: 'https://www.youtube.com/watch?v=6789'
click_button 'Update'
select('SlideShare', from: 'commercial_commercial_type')
click_button 'Create Commercial'
expect(event.commercials.count).to eq(@expected_count - 1)
end
scenario 'updates a valid commercial to an event', feature: true, js: true do
create(:commercial,
commercialable_id: event.id,
commercialable_type: 'Event')
visit edit_conference_proposal_path(conference.short_title, event.id)
click_link 'Commercials'
click_link 'Edit'
select('SlideShare', from: 'commercial_commercial_type')
fill_in 'commercial_commercial_id', with: '56789'
click_button 'Update Commercial'
expect(flash).to eq('Commercial was successfully updated.') expect(flash).to eq('Commercial was successfully updated.')
expect(event.commercials.count).to eq(@expected_count) expect(event.commercials.count).to eq(@expected_count)
commercial.reload
expect(commercial.url).to eq('https://www.youtube.com/watch?v=6789')
end end
scenario 'updates a invalid commercial to an event', feature: true, js: true do scenario 'deletes a commercial of an event', feature: true, js: true do
create(:commercial,
commercialable_id: event.id,
commercialable_type: 'Event')
visit edit_conference_proposal_path(conference.short_title, event.id)
click_link 'Commercials'
click_link 'Edit'
select('SlideShare', from: 'commercial_commercial_type')
fill_in 'commercial_commercial_id', with: ''
click_button 'Update Commercial'
expect(event.commercials.count).to eq(@expected_count)
end
scenario 'deletes a commercial to an event', feature: true, js: true do
create(:commercial, create(:commercial,
commercialable_id: event.id, commercialable_id: event.id,
commercialable_type: 'Event') commercialable_type: 'Event')

View file

@ -2,7 +2,6 @@ require 'spec_helper'
describe Commercial do describe Commercial do
it { should validate_presence_of(:commercial_id) } it { should validate_presence_of(:url) }
it { should validate_presence_of(:commercial_type) }
end end