From 48828f8930b70049f4d9b915ceada830b3b479c1 Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Fri, 29 Jul 2016 20:09:16 +0530 Subject: [PATCH] Display who added commercial for event Activate versioning for tests The tests were failing because of the lack of versioning.By default, versioning is off for tests. As a result, here (app/views/proposal/_form.html.haml L43) commercial,versions.last returns nil as there are no versions. --- app/helpers/application_helper.rb | 10 +++++----- app/views/admin/events/show.html.haml | 2 +- app/views/admin/versions/index.html.haml | 2 +- app/views/proposal/_form.html.haml | 3 +++ spec/features/commercials_spec.rb | 8 ++++---- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index adea355d..4b7b1699 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -383,7 +383,7 @@ module ApplicationHelper reverse.sub(',', ' dna ').reverse end - def change_creator_link(user_id) + def link_to_user(user_id) user = User.find_by(id: user_id) if user link_to user.name, admin_user_path(id: user_id) @@ -479,16 +479,16 @@ module ApplicationHelper def user_change_description(version) if version.event == 'create' - change_creator_link(version.item_id) + ' signed up' + link_to_user(version.item_id) + ' signed up' elsif version.event == 'update' if version.changeset.keys.include?('reset_password_sent_at') 'Someone requested password reset of' elsif version.changeset.keys.include?('confirmed_at') && version.changeset['confirmed_at'][0].nil? - (version.whodunnit.nil? ? change_creator_link(version.item_id) : change_creator_link(version.whodunnit)) + ' confirmed account of' + (version.whodunnit.nil? ? link_to_user(version.item_id) : link_to_user(version.whodunnit)) + ' confirmed account of' elsif version.changeset.keys.include?('confirmed_at') && version.changeset['confirmed_at'][1].nil? - change_creator_link(version.whodunnit) + ' unconfirmed account of' + link_to_user(version.whodunnit) + ' unconfirmed account of' else - change_creator_link(version.whodunnit) + " updated #{updated_attributes(version)} of" + link_to_user(version.whodunnit) + " updated #{updated_attributes(version)} of" end end end diff --git a/app/views/admin/events/show.html.haml b/app/views/admin/events/show.html.haml index 02dd85c7..8d08be2c 100644 --- a/app/views/admin/events/show.html.haml +++ b/app/views/admin/events/show.html.haml @@ -21,7 +21,7 @@ = version.id %td %p - = change_creator_link(version.whodunnit) + = link_to_user(version.whodunnit) - if version.item_type == 'Event' = event_change_description(version) diff --git a/app/views/admin/versions/index.html.haml b/app/views/admin/versions/index.html.haml index 2929b497..63244ac4 100644 --- a/app/views/admin/versions/index.html.haml +++ b/app/views/admin/versions/index.html.haml @@ -17,7 +17,7 @@ = version.id %td.col-md-9 %p - = change_creator_link(version.whodunnit) unless version.item_type == 'User' + = link_to_user(version.whodunnit) unless version.item_type == 'User' - case version.item_type - when 'Event' diff --git a/app/views/proposal/_form.html.haml b/app/views/proposal/_form.html.haml index 563cf957..d42174b0 100644 --- a/app/views/proposal/_form.html.haml +++ b/app/views/proposal/_form.html.haml @@ -40,3 +40,6 @@ - if can? :destroy, commercial = link_to 'Delete', conference_program_proposal_commercial_path(@conference.short_title, @event.id, commercial.id), :method => :delete, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-danger' + .text-right + = "added by " + = link_to_user(commercial.versions.last.whodunnit) diff --git a/spec/features/commercials_spec.rb b/spec/features/commercials_spec.rb index 90dd566d..9b530c49 100644 --- a/spec/features/commercials_spec.rb +++ b/spec/features/commercials_spec.rb @@ -58,7 +58,7 @@ feature Commercial do sign_out end - scenario 'adds a valid commercial of an event', feature: true, js: true do + scenario 'adds a valid commercial of an event', feature: true, versioning: true, js: true do visit edit_conference_program_proposal_path(conference.short_title, event.id) click_link 'Commercials' fill_in 'commercial_url', with: 'https://www.youtube.com/watch?v=M9bq_alk-sw' @@ -85,7 +85,7 @@ feature Commercial do expect(event.commercials.count).to eq 0 end - scenario 'updates a commercial of an event', feature: true, js: true do + scenario 'updates a commercial of an event', feature: true, versioning: true, js: true do commercial = create(:commercial, commercialable_id: event.id, commercialable_type: 'Event') @@ -99,7 +99,7 @@ feature Commercial do expect(commercial.url).to eq('https://www.youtube.com/watch?v=M9bq_alk-sw') end - scenario 'does not update a commercial of an event with invalid data', feature: true, js: true do + scenario 'does not update a commercial of an event with invalid data', feature: true, versioning: true, js: true do commercial = create(:commercial, commercialable_id: event.id, commercialable_type: 'Event') @@ -113,7 +113,7 @@ feature Commercial do expect(commercial.url).to eq('https://www.youtube.com/watch?v=BTTygyxuGj8') end - scenario 'deletes a commercial of an event', feature: true, js: true do + scenario 'deletes a commercial of an event', feature: true, versioning: true, js: true do create(:commercial, commercialable_id: event.id, commercialable_type: 'Event')