Move login_as after creating data for a test

It doesn't really affect the tests, but it helps isolate useless
assignments, and we already did it this way 94% of the time.
This commit is contained in:
Javi Martín
2019-09-23 00:51:37 +02:00
parent 24aa4744f1
commit 5cbd160f11
15 changed files with 64 additions and 84 deletions

View File

@@ -3,9 +3,8 @@ require "rails_helper"
describe "Admin Notifications" do describe "Admin Notifications" do
before do before do
admin = create(:administrator)
login_as(admin.user)
create(:budget) create(:budget)
login_as(create(:administrator).user)
end end
context "Show" do context "Show" do

View File

@@ -3,9 +3,8 @@ require "rails_helper"
describe "Admin newsletter emails" do describe "Admin newsletter emails" do
before do before do
admin = create(:administrator)
login_as(admin.user)
create(:budget) create(:budget)
login_as(create(:administrator).user)
end end
context "Show" do context "Show" do

View File

@@ -3,13 +3,13 @@ require "rails_helper"
describe "Homepage" do describe "Homepage" do
before do before do
admin = create(:administrator).user
login_as(admin)
Setting["homepage.widgets.feeds.proposals"] = false Setting["homepage.widgets.feeds.proposals"] = false
Setting["homepage.widgets.feeds.debates"] = false Setting["homepage.widgets.feeds.debates"] = false
Setting["homepage.widgets.feeds.processes"] = false Setting["homepage.widgets.feeds.processes"] = false
Setting["feature.user.recommendations"] = false Setting["feature.user.recommendations"] = false
admin = create(:administrator).user
login_as(admin)
end end
let!(:proposals_feed) { create(:widget_feed, kind: "proposals") } let!(:proposals_feed) { create(:widget_feed, kind: "proposals") }

View File

@@ -2,8 +2,8 @@ require "rails_helper"
describe "Admin edit translatable records" do describe "Admin edit translatable records" do
before do before do
login_as(create(:administrator).user)
translatable.update(attributes) translatable.update(attributes)
login_as(create(:administrator).user)
end end
let(:fields) { translatable.translated_attribute_names } let(:fields) { translatable.translated_attribute_names }

View File

@@ -19,11 +19,10 @@ describe "Polls" do
context "Admin index" do context "Admin index" do
scenario "Budget polls should not appear in the list" do scenario "Budget polls should not appear in the list" do
login_as(create(:administrator).user)
poll = create(:poll) poll = create(:poll)
budget_poll = create(:poll, :for_budget) budget_poll = create(:poll, :for_budget)
login_as(create(:administrator).user)
visit admin_polls_path visit admin_polls_path
expect(page).to have_content(poll.name) expect(page).to have_content(poll.name)

View File

@@ -786,7 +786,6 @@ describe "Budget Investments" do
scenario "Set votes for investments randomized with a seed" do scenario "Set votes for investments randomized with a seed" do
voter = create(:user, :level_two) voter = create(:user, :level_two)
login_as(voter)
per_page.times { create(:budget_investment, heading: heading) } per_page.times { create(:budget_investment, heading: heading) }
@@ -797,6 +796,7 @@ describe "Budget Investments" do
voted_investments << investment voted_investments << investment
end end
login_as(voter)
visit budget_investments_path(budget, heading_id: heading.id) visit budget_investments_path(budget, heading_id: heading.id)
voted_investments.each do |investment| voted_investments.each do |investment|
@@ -927,13 +927,12 @@ describe "Budget Investments" do
factory = :budget_investment factory = :budget_investment
scenario "Show up to 5 suggestions", :js do scenario "Show up to 5 suggestions", :js do
login_as(author)
%w[first second third fourth fifth sixth].each do |ordinal| %w[first second third fourth fifth sixth].each do |ordinal|
create(factory, title: "#{ordinal.titleize} #{factory}, has search term", budget: budget) create(factory, title: "#{ordinal.titleize} #{factory}, has search term", budget: budget)
end end
create(factory, title: "This is the last #{factory}", budget: budget) create(factory, title: "This is the last #{factory}", budget: budget)
login_as(author)
visit new_budget_investment_path(budget) visit new_budget_investment_path(budget)
fill_in "Title", with: "search" fill_in "Title", with: "search"
@@ -943,12 +942,11 @@ describe "Budget Investments" do
end end
scenario "No found suggestions", :js do scenario "No found suggestions", :js do
login_as(author)
%w[first second third fourth fifth sixth].each do |ordinal| %w[first second third fourth fifth sixth].each do |ordinal|
create(factory, title: "#{ordinal.titleize} #{factory}, has search term", budget: budget) create(factory, title: "#{ordinal.titleize} #{factory}, has search term", budget: budget)
end end
login_as(author)
visit new_budget_investment_path(budget) visit new_budget_investment_path(budget)
fill_in "Title", with: "item" fill_in "Title", with: "item"
@@ -958,12 +956,11 @@ describe "Budget Investments" do
end end
scenario "Don't show suggestions from a different budget", :js do scenario "Don't show suggestions from a different budget", :js do
login_as(author)
%w[first second third fourth fifth sixth].each do |ordinal| %w[first second third fourth fifth sixth].each do |ordinal|
create(factory, title: "#{ordinal.titleize} #{factory}, has search term", budget: budget) create(factory, title: "#{ordinal.titleize} #{factory}, has search term", budget: budget)
end end
login_as(author)
visit new_budget_investment_path(other_budget) visit new_budget_investment_path(other_budget)
fill_in "Title", with: "search" fill_in "Title", with: "search"
@@ -1005,11 +1002,11 @@ describe "Budget Investments" do
end end
scenario "Show" do scenario "Show" do
investment = create(:budget_investment, heading: heading)
user = create(:user) user = create(:user)
login_as(user) login_as(user)
investment = create(:budget_investment, heading: heading)
visit budget_investment_path(budget, id: investment.id) visit budget_investment_path(budget, id: investment.id)
expect(page).to have_content(investment.title) expect(page).to have_content(investment.title)
@@ -1146,9 +1143,6 @@ describe "Budget Investments" do
end end
scenario "Show (unfeasible budget investment) only when valuation finished" do scenario "Show (unfeasible budget investment) only when valuation finished" do
user = create(:user)
login_as(user)
investment = create(:budget_investment, investment = create(:budget_investment,
:unfeasible, :unfeasible,
budget: budget, budget: budget,
@@ -1164,6 +1158,9 @@ describe "Budget Investments" do
heading: heading, heading: heading,
unfeasibility_explanation: "The unfeasible explanation") unfeasibility_explanation: "The unfeasible explanation")
user = create(:user)
login_as(user)
visit budget_investment_path(budget, id: investment.id) visit budget_investment_path(budget, id: investment.id)
expect(page).not_to have_content("Unfeasibility explanation") expect(page).not_to have_content("Unfeasibility explanation")
@@ -1180,9 +1177,6 @@ describe "Budget Investments" do
end end
scenario "Show (selected budget investment)" do scenario "Show (selected budget investment)" do
user = create(:user)
login_as(user)
investment = create(:budget_investment, investment = create(:budget_investment,
:feasible, :feasible,
:finished, :finished,
@@ -1191,6 +1185,9 @@ describe "Budget Investments" do
group: group, group: group,
heading: heading) heading: heading)
user = create(:user)
login_as(user)
visit budget_investment_path(budget, id: investment.id) visit budget_investment_path(budget, id: investment.id)
expect(page).to have_content("This investment project has been selected for balloting phase") expect(page).to have_content("This investment project has been selected for balloting phase")
@@ -1198,8 +1195,6 @@ describe "Budget Investments" do
scenario "Show (winner budget investment) only if budget is finished" do scenario "Show (winner budget investment) only if budget is finished" do
budget.update(phase: "balloting") budget.update(phase: "balloting")
user = create(:user)
login_as(user)
investment = create(:budget_investment, investment = create(:budget_investment,
:feasible, :feasible,
@@ -1210,6 +1205,9 @@ describe "Budget Investments" do
group: group, group: group,
heading: heading) heading: heading)
user = create(:user)
login_as(user)
visit budget_investment_path(budget, id: investment.id) visit budget_investment_path(budget, id: investment.id)
expect(page).not_to have_content("Winning investment project") expect(page).not_to have_content("Winning investment project")
@@ -1223,8 +1221,6 @@ describe "Budget Investments" do
scenario "Show (not selected budget investment)" do scenario "Show (not selected budget investment)" do
budget.update(phase: "balloting") budget.update(phase: "balloting")
user = create(:user)
login_as(user)
investment = create(:budget_investment, investment = create(:budget_investment,
:feasible, :feasible,
@@ -1233,15 +1229,15 @@ describe "Budget Investments" do
group: group, group: group,
heading: heading) heading: heading)
user = create(:user)
login_as(user)
visit budget_investment_path(budget, id: investment.id) visit budget_investment_path(budget, id: investment.id)
expect(page).to have_content("This investment project has not been selected for balloting phase") expect(page).to have_content("This investment project has not been selected for balloting phase")
end end
scenario "Show title (no message)" do scenario "Show title (no message)" do
user = create(:user)
login_as(user)
investment = create(:budget_investment, investment = create(:budget_investment,
:feasible, :feasible,
:finished, :finished,
@@ -1249,6 +1245,9 @@ describe "Budget Investments" do
group: group, group: group,
heading: heading) heading: heading)
user = create(:user)
login_as(user)
visit budget_investment_path(budget, id: investment.id) visit budget_investment_path(budget, id: investment.id)
within("aside") do within("aside") do
@@ -1258,9 +1257,6 @@ describe "Budget Investments" do
end end
scenario "Show (unfeasible budget investment with valuation not finished)" do scenario "Show (unfeasible budget investment with valuation not finished)" do
user = create(:user)
login_as(user)
investment = create(:budget_investment, investment = create(:budget_investment,
:unfeasible, :unfeasible,
:unfinished, :unfinished,
@@ -1269,6 +1265,9 @@ describe "Budget Investments" do
heading: heading, heading: heading,
unfeasibility_explanation: "Local government is not competent in this matter") unfeasibility_explanation: "Local government is not competent in this matter")
user = create(:user)
login_as(user)
visit budget_investment_path(budget, id: investment.id) visit budget_investment_path(budget, id: investment.id)
expect(page).not_to have_content("Unfeasibility explanation") expect(page).not_to have_content("Unfeasibility explanation")
@@ -1309,11 +1308,10 @@ describe "Budget Investments" do
context "Destroy" do context "Destroy" do
scenario "Admin cannot destroy budget investments" do scenario "Admin cannot destroy budget investments" do
admin = create(:administrator)
user = create(:user, :level_two) user = create(:user, :level_two)
investment = create(:budget_investment, heading: heading, author: user) investment = create(:budget_investment, heading: heading, author: user)
login_as(admin.user) login_as(create(:administrator).user)
visit user_path(user) visit user_path(user)
within("#budget_investment_#{investment.id}") do within("#budget_investment_#{investment.id}") do

View File

@@ -86,13 +86,12 @@ describe "Votes" do
end end
scenario "Disable voting on investments", :js do scenario "Disable voting on investments", :js do
manuela = create(:user, verified_at: Time.current)
login_as(manuela)
budget.update(phase: "reviewing") budget.update(phase: "reviewing")
investment = create(:budget_investment, budget: budget, heading: heading) investment = create(:budget_investment, budget: budget, heading: heading)
manuela = create(:user, verified_at: Time.current)
login_as(manuela)
visit budget_investments_path(budget, heading_id: heading.id) visit budget_investments_path(budget, heading_id: heading.id)
within("#budget_investment_#{investment.id}") do within("#budget_investment_#{investment.id}") do

View File

@@ -205,9 +205,10 @@ describe "Commenting topics from proposals" do
end end
scenario "Create", :js do scenario "Create", :js do
login_as(user)
community = proposal.community community = proposal.community
topic = create(:topic, community: community) topic = create(:topic, community: community)
login_as(user)
visit community_topic_path(community, topic) visit community_topic_path(community, topic)
fill_in "comment-body-topic_#{topic.id}", with: "Have you thought about...?" fill_in "comment-body-topic_#{topic.id}", with: "Have you thought about...?"
@@ -223,9 +224,10 @@ describe "Commenting topics from proposals" do
end end
scenario "Errors on create", :js do scenario "Errors on create", :js do
login_as(user)
community = proposal.community community = proposal.community
topic = create(:topic, community: community) topic = create(:topic, community: community)
login_as(user)
visit community_topic_path(community, topic) visit community_topic_path(community, topic)
click_button "Publish comment" click_button "Publish comment"
@@ -754,9 +756,10 @@ describe "Commenting topics from budget investments" do
end end
scenario "Create", :js do scenario "Create", :js do
login_as(user)
community = investment.community community = investment.community
topic = create(:topic, community: community) topic = create(:topic, community: community)
login_as(user)
visit community_topic_path(community, topic) visit community_topic_path(community, topic)
fill_in "comment-body-topic_#{topic.id}", with: "Have you thought about...?" fill_in "comment-body-topic_#{topic.id}", with: "Have you thought about...?"
@@ -772,9 +775,10 @@ describe "Commenting topics from budget investments" do
end end
scenario "Errors on create", :js do scenario "Errors on create", :js do
login_as(user)
community = investment.community community = investment.community
topic = create(:topic, community: community) topic = create(:topic, community: community)
login_as(user)
visit community_topic_path(community, topic) visit community_topic_path(community, topic)
click_button "Publish comment" click_button "Publish comment"

View File

@@ -961,7 +961,6 @@ describe "Debates" do
scenario "Reorder by recommendations results maintaing search" do scenario "Reorder by recommendations results maintaing search" do
user = create(:user, recommended_debates: true) user = create(:user, recommended_debates: true)
login_as(user)
debate1 = create(:debate, title: "Show you got", cached_votes_total: 10, tag_list: "Sport") debate1 = create(:debate, title: "Show you got", cached_votes_total: 10, tag_list: "Sport")
debate2 = create(:debate, title: "Show what you got", cached_votes_total: 1, tag_list: "Sport") debate2 = create(:debate, title: "Show what you got", cached_votes_total: 1, tag_list: "Sport")
@@ -970,6 +969,7 @@ describe "Debates" do
proposal1 = create(:proposal, tag_list: "Sport") proposal1 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal1, user: user) create(:follow, followable: proposal1, user: user)
login_as(user)
visit debates_path visit debates_path
fill_in "search", with: "Show you got" fill_in "search", with: "Show you got"
click_button "Search" click_button "Search"
@@ -1088,9 +1088,6 @@ describe "Debates" do
context "Suggesting debates" do context "Suggesting debates" do
scenario "Shows up to 5 suggestions", :js do scenario "Shows up to 5 suggestions", :js do
author = create(:user)
login_as(author)
debate1 = create(:debate, title: "First debate has 1 vote", cached_votes_up: 1) debate1 = create(:debate, title: "First debate has 1 vote", cached_votes_up: 1)
debate2 = create(:debate, title: "Second debate has 2 votes", cached_votes_up: 2) debate2 = create(:debate, title: "Second debate has 2 votes", cached_votes_up: 2)
debate3 = create(:debate, title: "Third debate has 3 votes", cached_votes_up: 3) debate3 = create(:debate, title: "Third debate has 3 votes", cached_votes_up: 3)
@@ -1099,6 +1096,7 @@ describe "Debates" do
debate6 = create(:debate, title: "Sixth debate has 6 votes", description: "This is the sixth debate", cached_votes_up: 6) debate6 = create(:debate, title: "Sixth debate has 6 votes", description: "This is the sixth debate", cached_votes_up: 6)
debate7 = create(:debate, title: "This has seven votes, and is not suggest", description: "This is the seven", cached_votes_up: 7) debate7 = create(:debate, title: "This has seven votes, and is not suggest", description: "This is the seven", cached_votes_up: 7)
login_as(create(:user))
visit new_debate_path visit new_debate_path
fill_in "Debate title", with: "debate" fill_in "Debate title", with: "debate"
check "debate_terms_of_service" check "debate_terms_of_service"
@@ -1109,12 +1107,10 @@ describe "Debates" do
end end
scenario "No found suggestions", :js do scenario "No found suggestions", :js do
author = create(:user)
login_as(author)
debate1 = create(:debate, title: "First debate has 10 vote", cached_votes_up: 10) debate1 = create(:debate, title: "First debate has 10 vote", cached_votes_up: 10)
debate2 = create(:debate, title: "Second debate has 2 votes", cached_votes_up: 2) debate2 = create(:debate, title: "Second debate has 2 votes", cached_votes_up: 2)
login_as(create(:user))
visit new_debate_path visit new_debate_path
fill_in "Debate title", with: "proposal" fill_in "Debate title", with: "proposal"
check "debate_terms_of_service" check "debate_terms_of_service"
@@ -1126,11 +1122,9 @@ describe "Debates" do
end end
scenario "Mark/Unmark a debate as featured" do scenario "Mark/Unmark a debate as featured" do
admin = create(:administrator)
login_as(admin.user)
debate = create(:debate) debate = create(:debate)
login_as(create(:administrator).user)
visit debates_path visit debates_path
within("#debates") do within("#debates") do
expect(page).not_to have_content "Featured" expect(page).not_to have_content "Featured"
@@ -1159,12 +1153,10 @@ describe "Debates" do
end end
scenario "Index include featured debates" do scenario "Index include featured debates" do
admin = create(:administrator)
login_as(admin.user)
debate1 = create(:debate, featured_at: Time.current) debate1 = create(:debate, featured_at: Time.current)
debate2 = create(:debate) debate2 = create(:debate)
login_as(create(:administrator).user)
visit debates_path visit debates_path
within("#debates") do within("#debates") do
expect(page).to have_content("Featured") expect(page).to have_content("Featured")
@@ -1172,12 +1164,10 @@ describe "Debates" do
end end
scenario "Index do not show featured debates if none is marked as featured" do scenario "Index do not show featured debates if none is marked as featured" do
admin = create(:administrator)
login_as(admin.user)
debate1 = create(:debate) debate1 = create(:debate)
debate2 = create(:debate) debate2 = create(:debate)
login_as(create(:administrator).user)
visit debates_path visit debates_path
within("#debates") do within("#debates") do
expect(page).not_to have_content("Featured") expect(page).not_to have_content("Featured")

View File

@@ -7,10 +7,10 @@ describe "Voters" do
let(:officer) { create(:poll_officer) } let(:officer) { create(:poll_officer) }
before do before do
login_as(officer.user)
create(:geozone, :in_census) create(:geozone, :in_census)
create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection) create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection)
create(:poll_officer_assignment, officer: officer, poll: poll, booth: booth) create(:poll_officer_assignment, officer: officer, poll: poll, booth: booth)
login_as(officer.user)
set_officing_booth(booth) set_officing_booth(booth)
end end

View File

@@ -1481,7 +1481,6 @@ describe "Proposals" do
scenario "Reorder by recommendations results maintaing search" do scenario "Reorder by recommendations results maintaing search" do
user = create(:user, recommended_proposals: true) user = create(:user, recommended_proposals: true)
login_as(user)
proposal1 = create(:proposal, title: "Show you got", cached_votes_up: 10, tag_list: "Sport") proposal1 = create(:proposal, title: "Show you got", cached_votes_up: 10, tag_list: "Sport")
proposal2 = create(:proposal, title: "Show what you got", cached_votes_up: 1, tag_list: "Sport") proposal2 = create(:proposal, title: "Show what you got", cached_votes_up: 1, tag_list: "Sport")
@@ -1490,6 +1489,7 @@ describe "Proposals" do
proposal5 = create(:proposal, tag_list: "Sport") proposal5 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal5, user: user) create(:follow, followable: proposal5, user: user)
login_as(user)
visit proposals_path visit proposals_path
fill_in "search", with: "Show you got" fill_in "search", with: "Show you got"
click_button "Search" click_button "Search"
@@ -1726,9 +1726,6 @@ describe "Proposals" do
context "Suggesting proposals" do context "Suggesting proposals" do
scenario "Show up to 5 suggestions", :js do scenario "Show up to 5 suggestions", :js do
author = create(:user)
login_as(author)
create(:proposal, title: "First proposal, has search term") create(:proposal, title: "First proposal, has search term")
create(:proposal, title: "Second title") create(:proposal, title: "Second title")
create(:proposal, title: "Third proposal, has search term") create(:proposal, title: "Third proposal, has search term")
@@ -1737,6 +1734,7 @@ describe "Proposals" do
create(:proposal, title: "Sixth proposal, has search term") create(:proposal, title: "Sixth proposal, has search term")
create(:proposal, title: "Seventh proposal, has search term") create(:proposal, title: "Seventh proposal, has search term")
login_as(create(:user))
visit new_proposal_path visit new_proposal_path
fill_in "Proposal title", with: "search" fill_in "Proposal title", with: "search"
check "proposal_terms_of_service" check "proposal_terms_of_service"
@@ -1747,12 +1745,10 @@ describe "Proposals" do
end end
scenario "No found suggestions", :js do scenario "No found suggestions", :js do
author = create(:user)
login_as(author)
create(:proposal, title: "First proposal").update_column(:confidence_score, 10) create(:proposal, title: "First proposal").update_column(:confidence_score, 10)
create(:proposal, title: "Second proposal").update_column(:confidence_score, 8) create(:proposal, title: "Second proposal").update_column(:confidence_score, 8)
login_as(create(:user))
visit new_proposal_path visit new_proposal_path
fill_in "Proposal title", with: "debate" fill_in "Proposal title", with: "debate"
check "proposal_terms_of_service" check "proposal_terms_of_service"

View File

@@ -101,11 +101,10 @@ describe "Tags" do
end end
scenario "Turbolinks sanity check from budget's show", :js do scenario "Turbolinks sanity check from budget's show", :js do
login_as(author)
education = create(:tag, name: "Education", kind: "category") education = create(:tag, name: "Education", kind: "category")
health = create(:tag, name: "Health", kind: "category") health = create(:tag, name: "Health", kind: "category")
login_as(author)
visit budget_path(budget) visit budget_path(budget)
click_link "Create a budget investment" click_link "Create a budget investment"
@@ -126,11 +125,10 @@ describe "Tags" do
end end
scenario "Turbolinks sanity check from budget heading's show", :js do scenario "Turbolinks sanity check from budget heading's show", :js do
login_as(author)
education = create(:tag, name: "Education", kind: "category") education = create(:tag, name: "Education", kind: "category")
health = create(:tag, name: "Health", kind: "category") health = create(:tag, name: "Health", kind: "category")
login_as(author)
visit budget_investments_path(budget, heading_id: heading.id) visit budget_investments_path(budget, heading_id: heading.id)
click_link "Create a budget investment" click_link "Create a budget investment"

View File

@@ -83,12 +83,10 @@ describe "Tags" do
end end
scenario "Category with category tags", :js do scenario "Category with category tags", :js do
user = create(:user)
login_as(user)
education = create(:tag, :category, name: "Education") education = create(:tag, :category, name: "Education")
health = create(:tag, :category, name: "Health") health = create(:tag, :category, name: "Health")
login_as(create(:user))
visit new_proposal_path visit new_proposal_path
fill_in "Proposal title", with: "Help refugees" fill_in "Proposal title", with: "Help refugees"

View File

@@ -253,8 +253,8 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
if path.include? "edit" if path.include? "edit"
scenario "Should show persisted documents and remove nested_field" do scenario "Should show persisted documents and remove nested_field" do
login_as user_to_login
create(:document, documentable: documentable) create(:document, documentable: documentable)
login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_css ".document", count: 1 expect(page).to have_css ".document", count: 1
@@ -262,16 +262,16 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should not show add document button when scenario "Should not show add document button when
documentable has reached maximum of documents allowed", :js do documentable has reached maximum of documents allowed", :js do
login_as user_to_login
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable) create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_css "#new_document_link", visible: false expect(page).to have_css "#new_document_link", visible: false
end end
scenario "Should show add document button after destroy one document", :js do scenario "Should show add document button after destroy one document", :js do
login_as user_to_login
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable) create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
last_document = all("#nested-documents .document").last last_document = all("#nested-documents .document").last
within last_document do within last_document do
@@ -282,8 +282,8 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
scenario "Should remove nested field after remove document", :js do scenario "Should remove nested field after remove document", :js do
login_as user_to_login
create(:document, documentable: documentable) create(:document, documentable: documentable)
login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
click_on "Remove document" click_on "Remove document"

View File

@@ -216,24 +216,24 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
if path.include? "edit" if path.include? "edit"
scenario "Should show persisted image" do scenario "Should show persisted image" do
login_as user
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_css ".image", count: 1 expect(page).to have_css ".image", count: 1
end end
scenario "Should not show add image button when image already exists", :js do scenario "Should not show add image button when image already exists", :js do
login_as user
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_css "a#new_image_link", visible: false expect(page).to have_css "a#new_image_link", visible: false
end end
scenario "Should remove nested field after remove image", :js do scenario "Should remove nested field after remove image", :js do
login_as user
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user
visit send(path, arguments) visit send(path, arguments)
click_on "Remove image" click_on "Remove image"
@@ -241,8 +241,8 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should show add image button after remove image", :js do scenario "Should show add image button after remove image", :js do
login_as user
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user
visit send(path, arguments) visit send(path, arguments)
click_on "Remove image" click_on "Remove image"