Skip to content

Commit

Permalink
Admin views random records
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Feb 24, 2024
1 parent 95787c1 commit 75372be
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/crud/csv_uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/crud/financial_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/crud/gift_ideas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions app/views/crud/csv_uploads/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/views/crud/financial_accounts/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/views/crud/gift_ideas/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/system/crud/csv_uploads/admin_views_csv_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,15 @@

expect(page.find("code").text).to eq csv_upload.data
end

scenario "views random CsvUpload" 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions spec/system/crud/gift_ideas/admin_views_gift_idea_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 75372be

Please sign in to comment.