diff --git a/app/views/proposals/_preview.html.erb b/app/views/proposals/_preview.html.erb index af6b178e9..7769bddcf 100644 --- a/app/views/proposals/_preview.html.erb +++ b/app/views/proposals/_preview.html.erb @@ -128,7 +128,7 @@

<%= t("proposals.show.author") %>

- <%= link_to proposal_dashboard_index_path(@proposal), class: 'button hollow expanded' do %> + <%= link_to proposal_dashboard_index_path(@proposal), class: 'button hollow expanded', id: "proposal-dashboard-#{@proposal.id}" do %> <%= t("proposals.show.dashboard_proposal_link") %> <% end %> diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 92e9a2d58..82a9fd624 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -7,7 +7,7 @@ <%= simple_format text_with_links(@proposal.retired_explanation), {}, sanitize: false %>
<% end %> -d + <% if feature?(:allow_attached_documents) %> <%= render 'documents/documents', documents: @proposal.documents, diff --git a/spec/features/admin/proposal_dashboard_actions_spec.rb b/spec/features/admin/proposal_dashboard_actions_spec.rb index 2156a7711..07ca3a1de 100644 --- a/spec/features/admin/proposal_dashboard_actions_spec.rb +++ b/spec/features/admin/proposal_dashboard_actions_spec.rb @@ -75,7 +75,7 @@ feature 'Admin proposal dasboard actions' do it 'deletes the action', js: true do page.accept_confirm do - click_button 'Delete' + click_link 'Delete' end expect(page).not_to have_content(action.title) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index bb1286e7a..e0103f430 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -1082,6 +1082,7 @@ feature 'Budget Investments' do it_behaves_like "followable", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" } it_behaves_like "imageable", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" } + it_behaves_like "imageable destroy", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" } it_behaves_like "nested imageable", "budget_investment", diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index 647ad88c8..c8aae750e 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -2,26 +2,28 @@ require 'rails_helper' feature 'Proposal Notifications' do - scenario "Send a notification" do + scenario 'Send a notification' do author = create(:user) proposal = create(:proposal, author: author) login_as(author) visit root_path - click_link "My activity" + click_link 'My activity' within("#proposal_#{proposal.id}") do - click_link "Send notification" + click_link 'Dashboard' end - fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal" - fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!" + click_link 'Send notification' + + fill_in 'proposal_notification_title', with: 'Thank you for supporting my proposal' + fill_in 'proposal_notification_body', with: 'Please share it with others so we can make it happen!' click_button "Send message" - expect(page).to have_content "Your message has been sent correctly." - expect(page).to have_content "Thank you for supporting my proposal" - expect(page).to have_content "Please share it with others so we can make it happen!" + expect(page).to have_content 'Your message has been sent correctly.' + expect(page).to have_content 'Thank you for supporting my proposal' + expect(page).to have_content 'Please share it with others so we can make it happen!' end scenario "Send a notification (Active voter)" do @@ -167,18 +169,8 @@ feature 'Proposal Notifications' do proposal = create(:proposal, author: author) login_as(author) - visit user_path(author) - - within("#proposal_#{proposal.id}") do - expect(page).to have_link "Send notification" - end - - login_as(user) - visit user_path(author) - - within("#proposal_#{proposal.id}") do - expect(page).not_to have_link "Send message" - end + visit proposal_dashboard_index_path(proposal) + expect(page).to have_link "Send notification" end scenario "Accessing form directly" do diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index d3d51a96b..47b3657b9 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -206,7 +206,7 @@ feature 'Proposals' do expect(page).to have_css "meta[property='og:title'][content=\"#{proposal.title}\"]", visible: false end - scenario 'Create' do + scenario 'Create and publish' do author = create(:user) login_as(author) @@ -225,8 +225,10 @@ feature 'Proposals' do expect(page).to have_content 'Proposal created successfully.' expect(page).to have_content 'Help refugees' - expect(page).not_to have_content 'You can also see more information about improving your campaign' + click_link 'No, I want to publish the proposal' + + expect(page).to have_content 'Improve your campaign and get more support' click_link 'Not now, go to my proposal' expect(page).to have_content 'Help refugees' @@ -260,8 +262,9 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' - expect(page).to have_content 'Improve your campaign and get more supports' + click_link 'No, I want to publish the proposal' + expect(page).to have_content 'Improve your campaign and get more supports' click_link 'Not now, go to my proposal' expect(page).to have_content 'Help refugees' @@ -329,7 +332,7 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' - + click_link 'No, I want to publish the proposal' click_link 'Not now, go to my proposal' expect(Proposal.last.responsible_name).to eq('Isabel Garcia') @@ -351,7 +354,7 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' - + click_link 'No, I want to publish the proposal' click_link 'Not now, go to my proposal' expect(Proposal.last.responsible_name).to eq(author.document_number) @@ -383,7 +386,7 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' - + click_link 'No, I want to publish the proposal' click_link 'Not now, go to my proposal' expect(page).to have_content 'Testing an attack' @@ -407,7 +410,7 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' - + click_link 'No, I want to publish the proposal' click_link 'Not now, go to my proposal' expect(page).to have_content 'Testing auto link' @@ -430,7 +433,7 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' - + click_link 'No, I want to publish the proposal' click_link 'Not now, go to my proposal' expect(page).to have_content 'Testing auto link' @@ -438,6 +441,7 @@ feature 'Proposals' do expect(page).not_to have_link('click me') expect(page.html).not_to include "" + click_link 'Dashboard' click_link 'Edit' expect(page).to have_current_path(edit_proposal_path(Proposal.last)) @@ -465,7 +469,7 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' - + click_link 'No, I want to publish the proposal' click_link 'Not now, go to my proposal' within "#geozone" do @@ -494,7 +498,7 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' - + click_link 'No, I want to publish the proposal' click_link 'Not now, go to my proposal' within "#geozone" do @@ -511,8 +515,10 @@ feature 'Proposals' do visit user_path(proposal.author) within("#proposal_#{proposal.id}") do - click_link 'Retire' + click_link 'Dashboard' end + + click_link 'Retire' expect(page).to have_current_path(retire_form_proposal_path(proposal)) select 'Duplicated', from: 'proposal_retired_reason' diff --git a/spec/features/tags/proposals_spec.rb b/spec/features/tags/proposals_spec.rb index 7c8a5c026..93cbf61ee 100644 --- a/spec/features/tags/proposals_spec.rb +++ b/spec/features/tags/proposals_spec.rb @@ -80,7 +80,7 @@ feature 'Tags' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' - + click_link 'No, I want to publish the proposal' click_link 'Not now, go to my proposal' expect(page).to have_content 'Economía' @@ -110,6 +110,7 @@ feature 'Tags' do expect(page).to have_content 'Proposal created successfully.' + click_link 'No, I want to publish the proposal' click_link 'Not now, go to my proposal' within "#tags_proposal_#{Proposal.last.id}" do @@ -155,6 +156,7 @@ feature 'Tags' do expect(page).to have_content 'Proposal created successfully.' + click_link 'No, I want to publish the proposal' click_link 'Not now, go to my proposal' expect(page).to have_content 'user_id1' diff --git a/spec/shared/features/imageable.rb b/spec/shared/features/imageable.rb index ccaa30cc6..2af52d419 100644 --- a/spec/shared/features/imageable.rb +++ b/spec/shared/features/imageable.rb @@ -37,58 +37,6 @@ shared_examples "imageable" do |imageable_factory_name, imageable_path, imageabl end end - - context "Destroy" do - - background do - create(:image, imageable: imageable, user: imageable.author) - end - - scenario "Administrators cannot destroy imageables they have not authored" do - login_as(administrator) - - visit send(imageable_path, imageable_arguments) - expect(page).not_to have_link "Remove image" - end - - scenario "Users cannot destroy imageables they have not authored" do - login_as(create(:user)) - - visit send(imageable_path, imageable_arguments) - expect(page).not_to have_link "Remove image" - end - - scenario "Should show success notice after successful deletion" do - login_as imageable.author - - visit send(imageable_path, imageable_arguments) - click_on "Remove image" - - expect(page).to have_content "Image was deleted successfully." - end - - scenario "Should not show image after successful deletion" do - login_as imageable.author - - visit send(imageable_path, imageable_arguments) - click_on "Remove image" - - expect(page).not_to have_selector "figure img" - end - - scenario "Should redirect to imageable path after successful deletion" do - login_as imageable.author - - visit send(imageable_path, imageable_arguments) - click_on "Remove image" - - within "##{dom_id(imageable)}" do - expect(page).to have_selector "h1", text: imageable.title - end - end - - end - end def attach_image(path, success = true) diff --git a/spec/shared/features/imageable_destroy.rb b/spec/shared/features/imageable_destroy.rb new file mode 100644 index 000000000..78f8a7d6a --- /dev/null +++ b/spec/shared/features/imageable_destroy.rb @@ -0,0 +1,72 @@ +shared_examples "imageable destroy" do |imageable_factory_name, imageable_path, imageable_path_arguments| + include ActionView::Helpers + include ImagesHelper + include ImageablesHelper + + let!(:administrator) { create(:user) } + let!(:user) { create(:user) } + let!(:imageable_arguments) { {} } + let!(:imageables_arguments) { {} } + let!(:imageable) { create(imageable_factory_name, author: user) } + let!(:imageable_dom_name) { imageable_factory_name.parameterize } + + before do + create(:administrator, user: administrator) + + imageable_path_arguments.each do |argument_name, path_to_value| + imageable_arguments.merge!("#{argument_name}": imageable.send(path_to_value)) + end + end + + context "Destroy" do + + background do + create(:image, imageable: imageable, user: imageable.author) + end + + scenario "Administrators cannot destroy imageables they have not authored" do + login_as(administrator) + + visit send(imageable_path, imageable_arguments) + expect(page).not_to have_link "Remove image" + end + + scenario "Users cannot destroy imageables they have not authored" do + login_as(create(:user)) + + visit send(imageable_path, imageable_arguments) + expect(page).not_to have_link "Remove image" + end + + scenario "Should show success notice after successful deletion" do + login_as imageable.author + + visit send(imageable_path, imageable_arguments) + click_on "Remove image" + + expect(page).to have_content "Image was deleted successfully." + end + + scenario "Should not show image after successful deletion" do + login_as imageable.author + + visit send(imageable_path, imageable_arguments) + click_on "Remove image" + + expect(page).not_to have_selector "figure img" + end + + scenario "Should redirect to imageable path after successful deletion" do + login_as imageable.author + + visit send(imageable_path, imageable_arguments) + click_on "Remove image" + + within "##{dom_id(imageable)}" do + expect(page).to have_selector "h1", text: imageable.title + end + end + + end + +end