diff --git a/app/controllers/crud/csv_uploads_controller.rb b/app/controllers/crud/csv_uploads_controller.rb index 1e46319..a230ab8 100644 --- a/app/controllers/crud/csv_uploads_controller.rb +++ b/app/controllers/crud/csv_uploads_controller.rb @@ -4,6 +4,10 @@ class Crud::CsvUploadsController < ApplicationController CsvUpload.order(created_at: :desc).page(params[:page]) end + def show + redirect_to crud_csv_upload_path(CsvUpload.random) if params[:id] == "random" + end + def create if csv_upload.save ParseCsvUploadJob.perform_later(csv_upload.id) diff --git a/app/controllers/crud/financial_accounts_controller.rb b/app/controllers/crud/financial_accounts_controller.rb index 8783ace..889db66 100644 --- a/app/controllers/crud/financial_accounts_controller.rb +++ b/app/controllers/crud/financial_accounts_controller.rb @@ -4,6 +4,10 @@ class Crud::FinancialAccountsController < ApplicationController FinancialAccount.order(created_at: :desc).page(params[:page]) end + def show + redirect_to crud_financial_account_path(FinancialAccount.random) if params[:id] == "random" + end + def create if financial_account.save flash.notice = "Financial Account created" diff --git a/app/controllers/crud/gift_ideas_controller.rb b/app/controllers/crud/gift_ideas_controller.rb index b12527c..2ef2366 100644 --- a/app/controllers/crud/gift_ideas_controller.rb +++ b/app/controllers/crud/gift_ideas_controller.rb @@ -4,6 +4,10 @@ class Crud::GiftIdeasController < ApplicationController GiftIdea.order(created_at: :desc).page(params[:page]) end + def show + redirect_to crud_gift_idea_path(GiftIdea.random) if params[:id] == "random" + end + def create if gift_idea.save flash.notice = "Gift Idea created" diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba..5a68703 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,7 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true + + def self.random + order("RANDOM()").limit(1).first + end end diff --git a/app/views/crud/csv_uploads/index.html.haml b/app/views/crud/csv_uploads/index.html.haml index bac6711..f838e87 100644 --- a/app/views/crud/csv_uploads/index.html.haml +++ b/app/views/crud/csv_uploads/index.html.haml @@ -2,6 +2,8 @@ %p= link_to "New CSV Upload", new_crud_csv_upload_path +%p= link_to "Random CSV Upload", crud_csv_upload_path("random") + %table %thead %tr diff --git a/app/views/crud/financial_accounts/index.html.haml b/app/views/crud/financial_accounts/index.html.haml index 126bdb3..1989214 100644 --- a/app/views/crud/financial_accounts/index.html.haml +++ b/app/views/crud/financial_accounts/index.html.haml @@ -2,6 +2,8 @@ %p= link_to "New Financial Account", new_crud_financial_account_path +%p= link_to "Random Financial Account", crud_financial_account_path("random") + %table %thead %tr diff --git a/app/views/crud/gift_ideas/index.html.haml b/app/views/crud/gift_ideas/index.html.haml index be1ff7f..71e98b4 100644 --- a/app/views/crud/gift_ideas/index.html.haml +++ b/app/views/crud/gift_ideas/index.html.haml @@ -2,6 +2,8 @@ %p= link_to "New Gift Idea", new_crud_gift_idea_path +%p= link_to "Random Gift Idea", crud_gift_idea_path("random") + %table %thead %tr diff --git a/spec/system/auth/admin_auth_spec.rb b/spec/system/auth/admin_auth_spec.rb index e7dd1c0..f3f0b43 100644 --- a/spec/system/auth/admin_auth_spec.rb +++ b/spec/system/auth/admin_auth_spec.rb @@ -6,7 +6,7 @@ fill_in "admin_password", with: "shhh" click_on "sign in" expect(page).to have_content "Password saved to session" - expect(current_path).to eq dashboard_path + expect(page).to have_current_path dashboard_path end scenario "signing in with redirect_to works" do @@ -14,7 +14,7 @@ fill_in "admin_password", with: "shhh" click_on "sign in" expect(page).to have_content "Password saved to session" - expect(current_path).to eq "/crud/projects" + expect(page).to have_current_path crud_projects_path end scenario "signing out clears session" do @@ -25,6 +25,6 @@ visit "/sign_out" expect(page).to have_content "Password removed from session" visit "/dashboard" - expect(current_path).to eq sign_in_path + expect(page).to have_current_path sign_in_path end end diff --git a/spec/system/crud/csv_uploads/admin_creates_csv_upload_spec.rb b/spec/system/crud/csv_uploads/admin_creates_csv_upload_spec.rb index d2328d8..fe9fdf9 100644 --- a/spec/system/crud/csv_uploads/admin_creates_csv_upload_spec.rb +++ b/spec/system/crud/csv_uploads/admin_creates_csv_upload_spec.rb @@ -8,7 +8,7 @@ click_on "New CSV Upload" expect(page).to have_css "h1", text: "New CSV Upload" expect(page).to have_css "a", text: "CSV Upload List" - expect(current_path).to eq new_crud_csv_upload_path + expect(page).to have_current_path new_crud_csv_upload_path end scenario "create with parser error" do @@ -35,7 +35,7 @@ click_on "create" expect(page).to have_content "Data can't be blank" expect(page).to have_css ".alert", text: "Data can't be blank" - expect(current_path).to eq new_crud_csv_upload_path + expect(page).to have_current_path new_crud_csv_upload_path end scenario "create successfully" do @@ -48,7 +48,7 @@ expect(ParseCsvUploadJob).to have_been_enqueued csv_upload = CsvUpload.last - expect(current_path).to eq crud_csv_upload_path(csv_upload) + expect(page).to have_current_path crud_csv_upload_path(csv_upload) actual_values = page.all("tr").map do |table_row| table_row.all("td").map(&:text) diff --git a/spec/system/crud/csv_uploads/admin_deletes_csv_upload_spec.rb b/spec/system/crud/csv_uploads/admin_deletes_csv_upload_spec.rb index f917597..27d20aa 100644 --- a/spec/system/crud/csv_uploads/admin_deletes_csv_upload_spec.rb +++ b/spec/system/crud/csv_uploads/admin_deletes_csv_upload_spec.rb @@ -11,7 +11,7 @@ dismiss_confirm { click_on "Delete CSV Upload" } expect(CsvUpload.count).to eq 1 - expect(current_path).to eq crud_csv_upload_path(csv_upload) + expect(page).to have_current_path crud_csv_upload_path(csv_upload) end scenario "confirms delete" do @@ -22,6 +22,6 @@ expect(page).to have_css ".notice", text: "CSV Upload deleted" expect(CsvUpload.count).to eq 0 - expect(current_path).to eq crud_csv_uploads_path + expect(page).to have_current_path crud_csv_uploads_path end end diff --git a/spec/system/crud/csv_uploads/admin_edits_financial_account_spec.rb b/spec/system/crud/csv_uploads/admin_edits_financial_account_spec.rb index e05b626..2c9036b 100644 --- a/spec/system/crud/csv_uploads/admin_edits_financial_account_spec.rb +++ b/spec/system/crud/csv_uploads/admin_edits_financial_account_spec.rb @@ -9,7 +9,7 @@ click_on "Edit CSV Upload" expect(page).to have_css "h1", text: "Edit CSV Upload #{csv_upload.id}" expect(page).to have_css "a", text: "Show CSV Upload" - expect(current_path).to eq edit_crud_csv_upload_path(csv_upload) + expect(page).to have_current_path edit_crud_csv_upload_path(csv_upload) end scenario "edit with errors" do @@ -30,7 +30,7 @@ click_on "update" expect(page).to have_css ".notice", text: "CSV Upload updated" - expect(current_path).to eq crud_csv_upload_path(csv_upload) + expect(page).to have_current_path crud_csv_upload_path(csv_upload) expect(page).to have_css "td", text: "some-great-data.csv" end end diff --git a/spec/system/crud/csv_uploads/admin_views_csv_upload_spec.rb b/spec/system/crud/csv_uploads/admin_views_csv_upload_spec.rb index c954760..de58662 100644 --- a/spec/system/crud/csv_uploads/admin_views_csv_upload_spec.rb +++ b/spec/system/crud/csv_uploads/admin_views_csv_upload_spec.rb @@ -9,10 +9,10 @@ click_on csv_upload.id.to_s expect(page).to have_css "h1", text: "CSV Upload #{csv_upload.id}" expect(page).to have_css "a", text: "CSV Upload List" - expect(current_path).to eq crud_csv_upload_path(csv_upload) + expect(page).to have_current_path crud_csv_upload_path(csv_upload) end - scenario "views CsvUpload" do + scenario "viewing a record" do csv_upload = FactoryBot.create( :csv_upload, data: "foo,bar,baz", @@ -37,4 +37,15 @@ expect(page.find("code").text).to eq csv_upload.data end + + scenario "views random record" do + csv_upload = FactoryBot.create(:csv_upload) + expect(CsvUpload).to receive(:random).and_return(csv_upload) + + visit "/crud/csv_uploads" + click_on "Random CSV Upload" + + expect(page).to have_css "h1", text: "CSV Upload #{csv_upload.id}" + expect(page).to have_current_path crud_csv_upload_path(csv_upload) + end end diff --git a/spec/system/crud/csv_uploads/admin_views_csv_uploads_spec.rb b/spec/system/crud/csv_uploads/admin_views_csv_uploads_spec.rb index 7ee10c2..cb3584d 100644 --- a/spec/system/crud/csv_uploads/admin_views_csv_uploads_spec.rb +++ b/spec/system/crud/csv_uploads/admin_views_csv_uploads_spec.rb @@ -1,13 +1,13 @@ require "rails_helper" -describe "Admin views CsvUploads" do +describe "Admin views csv uploads" do include_context "admin password matches" scenario "from dashboard" do visit "/dashboard" click_on "CSV Uploads" expect(page).to have_css "h1", text: "CSV Uploads" - expect(current_path).to eq crud_csv_uploads_path + expect(page).to have_current_path crud_csv_uploads_path end scenario "with no records" do diff --git a/spec/system/crud/financial_accounts/admin_creates_financial_account_spec.rb b/spec/system/crud/financial_accounts/admin_creates_financial_account_spec.rb index 9cf230a..1c8bb3d 100644 --- a/spec/system/crud/financial_accounts/admin_creates_financial_account_spec.rb +++ b/spec/system/crud/financial_accounts/admin_creates_financial_account_spec.rb @@ -8,14 +8,14 @@ click_on "New Financial Account" expect(page).to have_css "h1", text: "New Financial Account" expect(page).to have_css "a", text: "Financial Account List" - expect(current_path).to eq new_crud_financial_account_path + expect(page).to have_current_path new_crud_financial_account_path end scenario "create with errors" do visit "/crud/financial_accounts/new" click_on "create" expect(page).to have_css ".alert", text: "Name can't be blank" - expect(current_path).to eq new_crud_financial_account_path + expect(page).to have_current_path new_crud_financial_account_path end scenario "create successfully" do @@ -26,7 +26,7 @@ expect(page).to have_css ".notice", text: "Financial Account created" financial_account = FinancialAccount.last - expect(current_path).to eq crud_financial_account_path(financial_account) + expect(page).to have_current_path crud_financial_account_path(financial_account) actual_values = page.all("tr").map do |table_row| table_row.all("td").map(&:text) diff --git a/spec/system/crud/financial_accounts/admin_deletes_financial_account_spec.rb b/spec/system/crud/financial_accounts/admin_deletes_financial_account_spec.rb index e27d444..4d71d6f 100644 --- a/spec/system/crud/financial_accounts/admin_deletes_financial_account_spec.rb +++ b/spec/system/crud/financial_accounts/admin_deletes_financial_account_spec.rb @@ -11,7 +11,7 @@ dismiss_confirm { click_on "Delete Financial Account" } expect(FinancialAccount.count).to eq 1 - expect(current_path).to eq crud_financial_account_path(financial_account) + expect(page).to have_current_path crud_financial_account_path(financial_account) end scenario "confirms delete" do @@ -22,6 +22,6 @@ expect(page).to have_css ".notice", text: "Financial Account deleted" expect(FinancialAccount.count).to eq 0 - expect(current_path).to eq crud_financial_accounts_path + expect(page).to have_current_path crud_financial_accounts_path end end diff --git a/spec/system/crud/financial_accounts/admin_edits_financial_account_spec.rb b/spec/system/crud/financial_accounts/admin_edits_financial_account_spec.rb index 90dc36c..433ff08 100644 --- a/spec/system/crud/financial_accounts/admin_edits_financial_account_spec.rb +++ b/spec/system/crud/financial_accounts/admin_edits_financial_account_spec.rb @@ -9,7 +9,7 @@ click_on "Edit Financial Account" expect(page).to have_css "h1", text: "Edit Financial Account #{financial_account.id}" expect(page).to have_css "a", text: "Show Financial Account" - expect(current_path).to eq edit_crud_financial_account_path(financial_account) + expect(page).to have_current_path edit_crud_financial_account_path(financial_account) end scenario "edit with errors" do @@ -30,7 +30,7 @@ click_on "update" expect(page).to have_css ".notice", text: "Financial Account updated" - expect(current_path).to eq crud_financial_account_path(financial_account) + expect(page).to have_current_path crud_financial_account_path(financial_account) expect(page).to have_css "td", text: "Brand new account" end end diff --git a/spec/system/crud/financial_accounts/admin_views_financial_account_spec.rb b/spec/system/crud/financial_accounts/admin_views_financial_account_spec.rb index a62908f..f70ce03 100644 --- a/spec/system/crud/financial_accounts/admin_views_financial_account_spec.rb +++ b/spec/system/crud/financial_accounts/admin_views_financial_account_spec.rb @@ -9,7 +9,7 @@ click_on financial_account.id.to_s expect(page).to have_css "h1", text: "Financial Account #{financial_account.id}" expect(page).to have_css "a", text: "Financial Account List" - expect(current_path).to eq crud_financial_account_path(financial_account) + expect(page).to have_current_path crud_financial_account_path(financial_account) end scenario "viewing a record" do @@ -32,4 +32,15 @@ ] ) end + + scenario "views random record" do + financial_account = FactoryBot.create(:financial_account) + expect(FinancialAccount).to receive(:random).and_return(financial_account) + + visit "/crud/financial_accounts" + click_on "Random Financial Account" + + expect(page).to have_css "h1", text: "Financial Account #{financial_account.id}" + expect(page).to have_current_path crud_financial_account_path(financial_account) + end end diff --git a/spec/system/crud/financial_accounts/admin_views_financial_accounts_spec.rb b/spec/system/crud/financial_accounts/admin_views_financial_accounts_spec.rb index 97ca559..ccde8f9 100644 --- a/spec/system/crud/financial_accounts/admin_views_financial_accounts_spec.rb +++ b/spec/system/crud/financial_accounts/admin_views_financial_accounts_spec.rb @@ -7,7 +7,7 @@ visit "/dashboard" click_on "Financial Accounts" expect(page).to have_css "h1", text: "Financial Accounts" - expect(current_path).to eq crud_financial_accounts_path + expect(page).to have_current_path crud_financial_accounts_path end scenario "with no records" do diff --git a/spec/system/crud/gift_ideas/admin_creates_gift_idea_spec.rb b/spec/system/crud/gift_ideas/admin_creates_gift_idea_spec.rb index 82df5cb..c69e179 100644 --- a/spec/system/crud/gift_ideas/admin_creates_gift_idea_spec.rb +++ b/spec/system/crud/gift_ideas/admin_creates_gift_idea_spec.rb @@ -8,14 +8,14 @@ click_on "New Gift Idea" expect(page).to have_css "h1", text: "New Gift Idea" expect(page).to have_css "a", text: "Gift Idea List" - expect(current_path).to eq new_crud_gift_idea_path + expect(page).to have_current_path new_crud_gift_idea_path end scenario "create with errors" do visit "/crud/gift_ideas/new" click_on "create" expect(page).to have_css ".alert", text: "Title can't be blank and Website url can't be blank" - expect(current_path).to eq new_crud_gift_idea_path + expect(page).to have_current_path new_crud_gift_idea_path end scenario "create successfully" do @@ -28,7 +28,7 @@ expect(page).to have_css ".notice", text: "Gift Idea created" gift_idea = GiftIdea.last - expect(current_path).to eq crud_gift_idea_path(gift_idea) + expect(page).to have_current_path crud_gift_idea_path(gift_idea) actual_values = page.all("tr").map do |table_row| table_row.all("td").map(&:text) diff --git a/spec/system/crud/gift_ideas/admin_deletes_gift_idea_spec.rb b/spec/system/crud/gift_ideas/admin_deletes_gift_idea_spec.rb index 4c7f551..b85a478 100644 --- a/spec/system/crud/gift_ideas/admin_deletes_gift_idea_spec.rb +++ b/spec/system/crud/gift_ideas/admin_deletes_gift_idea_spec.rb @@ -11,7 +11,7 @@ dismiss_confirm { click_on "Delete Gift Idea" } expect(GiftIdea.count).to eq 1 - expect(current_path).to eq crud_gift_idea_path(gift_idea) + expect(page).to have_current_path crud_gift_idea_path(gift_idea) end scenario "confirms delete" do @@ -22,6 +22,6 @@ expect(page).to have_css ".notice", text: "Gift Idea deleted" expect(GiftIdea.count).to eq 0 - expect(current_path).to eq crud_gift_ideas_path + expect(page).to have_current_path crud_gift_ideas_path end end diff --git a/spec/system/crud/gift_ideas/admin_edits_gift_idea_spec.rb b/spec/system/crud/gift_ideas/admin_edits_gift_idea_spec.rb index 897ebc6..602b3d6 100644 --- a/spec/system/crud/gift_ideas/admin_edits_gift_idea_spec.rb +++ b/spec/system/crud/gift_ideas/admin_edits_gift_idea_spec.rb @@ -9,7 +9,7 @@ click_on "Edit Gift Idea" expect(page).to have_css "h1", text: "Edit Gift Idea #{gift_idea.id}" expect(page).to have_css "a", text: "Show Gift Idea" - expect(current_path).to eq edit_crud_gift_idea_path(gift_idea) + expect(page).to have_current_path edit_crud_gift_idea_path(gift_idea) end scenario "edit with errors" do @@ -30,7 +30,7 @@ click_on "update" expect(page).to have_css ".notice", text: "Gift Idea updated" - expect(current_path).to eq crud_gift_idea_path(gift_idea) + expect(page).to have_current_path crud_gift_idea_path(gift_idea) expect(page).to have_css "td", text: "New Mario Game" end end diff --git a/spec/system/crud/gift_ideas/admin_views_gift_idea_spec.rb b/spec/system/crud/gift_ideas/admin_views_gift_idea_spec.rb index 50e3d7e..d4e038f 100644 --- a/spec/system/crud/gift_ideas/admin_views_gift_idea_spec.rb +++ b/spec/system/crud/gift_ideas/admin_views_gift_idea_spec.rb @@ -9,7 +9,7 @@ click_on gift_idea.id.to_s expect(page).to have_css "h1", text: "Gift Idea #{gift_idea.id}" expect(page).to have_css "a", text: "Gift Idea List" - expect(current_path).to eq crud_gift_idea_path(gift_idea) + expect(page).to have_current_path crud_gift_idea_path(gift_idea) end scenario "viewing a record" do @@ -36,4 +36,15 @@ ] ) end + + scenario "views random record" do + gift_idea = FactoryBot.create(:gift_idea) + expect(GiftIdea).to receive(:random).and_return(gift_idea) + + visit "/crud/gift_ideas" + click_on "Random Gift Idea" + + expect(page).to have_css "h1", text: "Gift Idea #{gift_idea.id}" + expect(page).to have_current_path crud_gift_idea_path(gift_idea) + end end diff --git a/spec/system/crud/gift_ideas/admin_views_gift_ideas_spec.rb b/spec/system/crud/gift_ideas/admin_views_gift_ideas_spec.rb index 5803344..23a0035 100644 --- a/spec/system/crud/gift_ideas/admin_views_gift_ideas_spec.rb +++ b/spec/system/crud/gift_ideas/admin_views_gift_ideas_spec.rb @@ -7,7 +7,7 @@ visit "/dashboard" click_on "Gift Ideas" expect(page).to have_css "h1", text: "Gift Ideas" - expect(current_path).to eq crud_gift_ideas_path + expect(page).to have_current_path crud_gift_ideas_path end scenario "with no records" do