Skip to content

Commit 76e5630

Browse files
committed
Refactor routing
1 parent acc9d83 commit 76e5630

File tree

7 files changed

+9
-18
lines changed

7 files changed

+9
-18
lines changed

app/controllers/hotsheet/sheets_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def update
2222

2323
def set_sheet
2424
@sheet = Hotsheet.sheets[params[:sheet_name]]
25+
26+
render "hotsheet/home/error", status: :not_found if @sheet.nil?
2527
end
2628

2729
def set_column

app/helpers/hotsheet/application_helper.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/views/hotsheet/shared/_nav.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<% Hotsheet.sheets.each_with_index do |entry, index| %>
77
<li>
88
<% sheet_name, sheet = entry %>
9-
<%= link_to sheet.model.model_name.human(count: 2), sheet_path_for(sheet_name),
9+
<%= link_to sheet.model.model_name.human(count: 2), sheets_path(sheet_name),
1010
class: ("active" if params[:sheet_name] == sheet_name), data: { x: index } %>
1111
</li>
1212
<% end %>

config/routes.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# frozen_string_literal: true
22

33
Hotsheet::Engine.routes.draw do
4-
next unless defined? Rails::Server
5-
64
root "home#show"
75

8-
Hotsheet.sheets.each_key do |sheet_name|
9-
resources sheet_name, sheet_name:, controller: :sheets, only: %i[index update]
6+
scope ":sheet_name" do
7+
resources controller: :sheets, only: %i[index update], as: :sheets
108
end
119

1210
match "*path", to: "home#error", via: :all

spec/requests/hotsheet/sheets_controller_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
describe "#index" do
1414
it "shows a table with all values" do
15-
get hotsheet.users_path
15+
get hotsheet.sheets_path :users
1616
expect(response).to be_successful
1717
expect(response.body).to include user.name
1818
end
1919
end
2020

2121
describe "#update" do
22-
let(:path) { hotsheet.user_path(user.id) }
22+
let(:path) { hotsheet.sheet_path :users, user }
2323

2424
it "updates the resource" do
2525
expect { put path, params: { column_name: :name, value: "Bob" } }
@@ -43,7 +43,7 @@
4343
end
4444

4545
context "with nonexistent id" do
46-
let(:path) { hotsheet.user_path(0) }
46+
let(:path) { hotsheet.sheet_path :users, 0 }
4747

4848
it "does not update the resource" do
4949
expect { put path, params: { column_name: :name, value: "Bob" } }.not_to change(user, :reload)

spec/support/utils.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

33
def prepare(&)
4-
stub_const "Rails::Server", true
54
Hotsheet.instance_variable_set :@sheets, nil # reset memoized sheets
65
yield
7-
Rails.application.reload_routes!
86
end

spec/system/hotsheet/sheets_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
before { prepare { Hotsheet.configure { sheet :User } } }
1111

1212
it "updates the cell value" do
13-
visit hotsheet.users_path
13+
visit hotsheet.sheets_path :users
1414
find(".cell", text: user.name).click.send_keys(:enter).fill_in(with: "Admin").send_keys :enter
1515

1616
expect { find(".cell", text: user.email).click }

0 commit comments

Comments
 (0)