From 5ad221eb7ee48f57c3870c342de39a4c19487c66 Mon Sep 17 00:00:00 2001 From: Chrisbr Date: Tue, 13 May 2014 09:01:05 +0200 Subject: [PATCH 1/3] renaming proposal feature tests --- spec/features/proposal_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/features/proposal_spec.rb b/spec/features/proposal_spec.rb index 3f4a2050..5d032dd0 100644 --- a/spec/features/proposal_spec.rb +++ b/spec/features/proposal_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' feature Event do - shared_examples 'participant' do |user| + shared_examples 'proposal' do |user| scenario 'submitts a new proposal and updates account', feature: true, js: true do expected_count = Event.count + 1 conference = create(:conference) @@ -43,9 +43,9 @@ feature Event do end end - describe 'participant' do - it_behaves_like 'participant', :participant - it_behaves_like 'participant', :organizer - it_behaves_like 'participant', :admin + describe 'proposal workflow' do + it_behaves_like 'proposal', :participant + it_behaves_like 'proposal', :organizer + it_behaves_like 'proposal', :admin end end From 656ded9d96e2da5c4acddd268fb8e2ffb04e5fcb Mon Sep 17 00:00:00 2001 From: Chrisbr Date: Tue, 13 May 2014 15:45:39 +0200 Subject: [PATCH 2/3] Implements feature test for proposal workflog - submitt proposal - accept proposal - confirm proposal --- app/views/admin/events/index.html.haml | 14 +++--- .../register.html.haml | 4 +- app/views/proposal/index.html.haml | 9 ++-- spec/factories/email_settings.rb | 10 ++++ spec/features/proposal_spec.rb | 49 ++++++++++++++++--- spec/support/login_macros.rb | 6 +++ 6 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 spec/factories/email_settings.rb diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index 6b608947..0c0d9d75 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -108,32 +108,32 @@ - if event.transition_possible? :accept %li= link_to 'Accept event (no email)', update_state_admin_conference_event_path(@conference.short_title, event, transition: :accept, send_mail: false), - method: :patch, hint: 'Accept this event without sending an automated email.' + method: :patch, hint: 'Accept this event without sending an automated email.', id: 'accept_event' %li= link_to 'Accept event (WITH email)', update_state_admin_conference_event_path(@conference.short_title, event, transition: :accept, send_mail: true), - method: :patch, hint: 'Accept this event and send an automated email.' + method: :patch, hint: 'Accept this event and send an automated email.', id: 'accept_event_mail' - if event.transition_possible? :reject %li= link_to 'Reject event (no email)', update_state_admin_conference_event_path(@conference.short_title, event, transition: :reject, send_mail: false), method: :patch, confirm: 'Are you sure?', - hint: 'Reject this event without sending an automated email.' + hint: 'Reject this event without sending an automated email.', id: 'reject_event' %li= link_to 'Reject event (WITH email)', update_state_admin_conference_event_path(@conference.short_title, event, transition: :reject, send_mail: true), method: :patch, confirm: 'Are you sure?', - hint: 'Reject this event and send an automated email.' + hint: 'Reject this event and send an automated email.', id: 'reject_event_mail' - if event.transition_possible? :start_review %li= link_to 'Start review', update_state_admin_conference_event_path(@conference.short_title, event, transition: :start_review), - method: :patch + method: :patch, id: 'review_event' - if event.transition_possible? :confirm %li= link_to 'Confirm event', update_state_admin_conference_event_path(@conference.short_title, event, transition: :confirm), - method: :patch, + method: :patch, id: 'confirm_event', hint: 'Confirm that the speaker(s) will be present and that the event will actually take place.' - if event.transition_possible? :cancel %li= link_to 'Cancel event', update_state_admin_conference_event_path(@conference.short_title, event, :transition => :cancel), - method: :patch, + method: :patch, id: 'cancel_event', hint: 'Mark this event as cancelled. Usually this means that the speakers had to cancel their appearance.' :javascript diff --git a/app/views/conference_registration/register.html.haml b/app/views/conference_registration/register.html.haml index df55dcc1..13b6b568 100644 --- a/app/views/conference_registration/register.html.haml +++ b/app/views/conference_registration/register.html.haml @@ -1,6 +1,6 @@ .row .col-md-12 - = semantic_form_for(@registration, :url => register_conference_path(@conference.short_title), :html => { :method => :put }) do |f| + = semantic_form_for(@registration, :url => register_conference_path(@conference.short_title), :html => { :method => :patch }) do |f| .tabbable %ul.nav.nav-tabs %li.active @@ -19,4 +19,4 @@ = link_to "Unregister", register_conference_path(@conference.short_title),:method => :delete, :class => "btn btn-danger", :confirm => "Are you sure you want to unregister?" - else - = f.action :submit, :button_html => { :value => "Register", :class => "btn btn-primary" } + = f.action :submit, :button_html => { :value => "Register", :class => "btn btn-primary", id: 'register' } diff --git a/app/views/proposal/index.html.haml b/app/views/proposal/index.html.haml index 3d820f50..0edf1c8c 100644 --- a/app/views/proposal/index.html.haml +++ b/app/views/proposal/index.html.haml @@ -29,7 +29,10 @@ .pull-right - if event.transition_possible? :confirm = link_to 'Confirm', - conference_proposal_confirm_path(@conference.short_title, event, send_mail: false), method: :patch, class: 'btn btn-mini btn-success' - = link_to 'Edit', edit_conference_proposal_path(@conference.short_title, event.id), class: 'btn btn-mini btn-primary' + conference_proposal_confirm_path(@conference.short_title, event, send_mail: false), + method: :patch, class: 'btn btn-mini btn-success', id: 'confirm_proposal' + = link_to 'Edit', edit_conference_proposal_path(@conference.short_title, event.id), + class: 'btn btn-mini btn-primary', id: 'edit_proposal' = link_to 'Withdraw', conference_proposal_path(@conference.short_title, event.id), method: :delete, - confirm: 'Are you sure you want to withdraw this proposal?', class: 'btn btn-mini btn-danger' + confirm: 'Are you sure you want to withdraw this proposal?', class: 'btn btn-mini btn-danger', + id: 'delete_proposal' diff --git a/spec/factories/email_settings.rb b/spec/factories/email_settings.rb new file mode 100644 index 00000000..e7cd0f76 --- /dev/null +++ b/spec/factories/email_settings.rb @@ -0,0 +1,10 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :email_settings do + send_on_registration false + send_on_accepted false + send_on_rejected false + send_on_confirmed_without_registration false + end +end diff --git a/spec/features/proposal_spec.rb b/spec/features/proposal_spec.rb index 5d032dd0..30ae3883 100644 --- a/spec/features/proposal_spec.rb +++ b/spec/features/proposal_spec.rb @@ -2,14 +2,19 @@ require 'spec_helper' feature Event do - shared_examples 'proposal' do |user| - scenario 'submitts a new proposal and updates account', feature: true, js: true do + shared_examples 'proposal workflow' do + scenario 'submitts a new proposal, accepts and confirms', feature: true, js: true do + admin = create(:admin, email: 'admin@example.com') + participant = create(:participant, email: 'participant@example.com') + expected_count = Event.count + 1 conference = create(:conference) conference.call_for_papers = create(:call_for_papers) + conference.email_settings = create(:email_settings) conference.event_types = [create(:event_type)] - sign_in create(user) + #Submit a new proposal as participant + sign_in participant visit conference_proposal_index_path(conference.short_title) click_link 'New Proposal' @@ -33,6 +38,7 @@ feature Event do fill_in 'user_person_attributes_first_name', with: 'Example' fill_in 'user_person_attributes_last_name', with: 'User' + fill_in 'user_person_attributes_biography', with: 'Lorem ipsum biography' click_button 'Update' @@ -40,12 +46,41 @@ feature Event do to eq('You updated your account successfully.') expect(Event.count).to eq(expected_count) + + visit conference_proposal_index_path(conference.short_title) + expect(page.has_content?('Example Proposal')).to be true + + sign_out + + #Accept proposal as admin + sign_in admin + + visit admin_conference_events_path(conference.short_title) + expect(page.has_content?('Example Proposal')).to be true + + click_link 'New' + click_link 'accept_event' + + expect(page.has_content?('Unconfirmed')).to be true + sign_out + + #Confirm proposal as participant + sign_in participant + visit conference_proposal_index_path(conference.short_title) + expect(page.has_content?('Example Proposal')).to be true + expect(page.has_content?('Accepted (confirmation pending)')).to be true + click_link 'confirm_proposal' + expect(page.find('#flash_notice').text). + to eq('Event was confirmed. Please register to attend the conference.') + + find('#register').click + + expect(page.find('#flash_notice').text). + to eq('You are now registered.') end end - describe 'proposal workflow' do - it_behaves_like 'proposal', :participant - it_behaves_like 'proposal', :organizer - it_behaves_like 'proposal', :admin + describe 'proposal' do + it_behaves_like 'proposal workflow' end end diff --git a/spec/support/login_macros.rb b/spec/support/login_macros.rb index ad6abe3c..f4608fc5 100644 --- a/spec/support/login_macros.rb +++ b/spec/support/login_macros.rb @@ -8,4 +8,10 @@ module LoginMacros expect(page.has_content?('Signed in successfully')).to be true end + + def sign_out + Capybara.current_session.driver.browser.clear_cookies + visit root_path + expect(page.has_content?('Sign In')).to be true + end end From 12fd3b7d5acdd0fbf5c9a4b5c7492e592c4e9b05 Mon Sep 17 00:00:00 2001 From: Chrisbr Date: Tue, 13 May 2014 16:45:43 +0200 Subject: [PATCH 3/3] Fix id in forloop --- app/views/admin/events/index.html.haml | 15 ++++++++------- app/views/proposal/index.html.haml | 6 +++--- spec/features/proposal_spec.rb | 18 +++++++++++------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index 0953f934..35fa81b7 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -108,32 +108,33 @@ - if event.transition_possible? :accept %li= link_to 'Accept event', update_state_admin_conference_event_path(@conference.short_title, event, transition: :accept), - method: :patch, id: 'accept_event' + method: :patch, id: "accept_event_#{event.id}" - if @conference.email_settings.send_on_accepted? %li= link_to 'Accept event (without email)', update_state_admin_conference_event_path(@conference.short_title, event, transition: :accept, send_mail: false), - method: :patch, hint: 'Accept this event without sending an automated email.', id: 'accept_event_without_mail' + method: :patch, hint: 'Accept this event without sending an automated email.', + id: "accept_event_without_mail_#{event.id}" - if event.transition_possible? :reject %li= link_to 'Reject event', update_state_admin_conference_event_path(@conference.short_title, event, transition: :reject), - method: :patch, confirm: 'Are you sure?', id: 'reject_event' + method: :patch, confirm: 'Are you sure?', id: "reject_event_#{event.id}" - if @conference.email_settings.send_on_rejected? %li= link_to 'Reject event (without email)', update_state_admin_conference_event_path(@conference.short_title, event, transition: :reject, send_mail: false), - method: :patch, confirm: 'Are you sure?', id: 'reject_event_without_mail' + method: :patch, confirm: 'Are you sure?', id: "reject_event_without_mail_#{event.id}" - if event.transition_possible? :start_review %li= link_to 'Start review', update_state_admin_conference_event_path(@conference.short_title, event, transition: :start_review), - method: :patch, id: 'review_event' + method: :patch, id: "review_event_#{event.id}" - if event.transition_possible? :confirm %li= link_to 'Confirm event', update_state_admin_conference_event_path(@conference.short_title, event, transition: :confirm), - method: :patch, id: 'confirm_event', + method: :patch, id: "confirm_event_#{event.id}", hint: 'Confirm that the speaker(s) will be present and that the event will actually take place.' - if event.transition_possible? :cancel %li= link_to 'Cancel event', update_state_admin_conference_event_path(@conference.short_title, event, :transition => :cancel), - method: :patch, id: 'cancel_event', + method: :patch, id: "cancel_event_#{event.id}", hint: 'Mark this event as cancelled. Usually this means that the speakers had to cancel their appearance.' :javascript diff --git a/app/views/proposal/index.html.haml b/app/views/proposal/index.html.haml index 0edf1c8c..629e2299 100644 --- a/app/views/proposal/index.html.haml +++ b/app/views/proposal/index.html.haml @@ -30,9 +30,9 @@ - if event.transition_possible? :confirm = link_to 'Confirm', conference_proposal_confirm_path(@conference.short_title, event, send_mail: false), - method: :patch, class: 'btn btn-mini btn-success', id: 'confirm_proposal' + method: :patch, class: 'btn btn-mini btn-success', id: "confirm_proposal_#{event.id}" = link_to 'Edit', edit_conference_proposal_path(@conference.short_title, event.id), - class: 'btn btn-mini btn-primary', id: 'edit_proposal' + class: 'btn btn-mini btn-primary', id: "edit_proposal_#{event.id}" = link_to 'Withdraw', conference_proposal_path(@conference.short_title, event.id), method: :delete, confirm: 'Are you sure you want to withdraw this proposal?', class: 'btn btn-mini btn-danger', - id: 'delete_proposal' + id: "delete_proposal_#{event.id}" diff --git a/spec/features/proposal_spec.rb b/spec/features/proposal_spec.rb index 1c832f66..4f8a62f6 100644 --- a/spec/features/proposal_spec.rb +++ b/spec/features/proposal_spec.rb @@ -7,7 +7,9 @@ feature Event do let!(:admin_role) { create(:admin_role) } shared_examples 'proposal workflow' do - scenario 'submitts a new proposal, accepts and confirms', feature: true, js: true do + scenario 'submitts a proposal, accepts and confirms', + feature: true, js: true do + admin = create(:admin, email: 'admin@example.com') participant = create(:participant, email: 'participant@example.com') @@ -17,7 +19,7 @@ feature Event do conference.email_settings = create(:email_settings) conference.event_types = [create(:event_type)] - #Submit a new proposal as participant + # Submit a new proposal as participant sign_in participant visit conference_proposal_index_path(conference.short_title) @@ -51,31 +53,33 @@ feature Event do expect(Event.count).to eq(expected_count) + event = Event.where(title: 'Example Proposal').first + visit conference_proposal_index_path(conference.short_title) expect(page.has_content?('Example Proposal')).to be true sign_out - #Accept proposal as admin + # Accept proposal as admin sign_in admin visit admin_conference_events_path(conference.short_title) expect(page.has_content?('Example Proposal')).to be true click_link 'New' - click_link 'accept_event' + click_link "accept_event_#{event.id}" expect(page.has_content?('Unconfirmed')).to be true sign_out - #Confirm proposal as participant + # Confirm proposal as participant sign_in participant visit conference_proposal_index_path(conference.short_title) expect(page.has_content?('Example Proposal')).to be true expect(page.has_content?('Accepted (confirmation pending)')).to be true - click_link 'confirm_proposal' + click_link "confirm_proposal_#{event.id}" expect(page.find('#flash_notice').text). - to eq('Event was confirmed. Please register to attend the conference.') + to eq('Event was confirmed. Please register to attend the conference.') find('#register').click