Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/controllers/hotsheet/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class Hotsheet::HomeController < Hotsheet::ApplicationController
def show; end

def error
render "error", status: :not_found
end
end
6 changes: 2 additions & 4 deletions app/controllers/hotsheet/sheets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ def update
end
end

def error
render "error", status: :not_found
end

private

def set_sheet
@sheet = Hotsheet.sheets[params[:sheet_name]]

render "hotsheet/home/error", status: :not_found if @sheet.nil?
end

def set_column
Expand Down
7 changes: 0 additions & 7 deletions app/helpers/hotsheet/application_helper.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/hotsheet/shared/_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<% Hotsheet.sheets.each_with_index do |entry, index| %>
<li>
<% sheet_name, sheet = entry %>
<%= link_to sheet.model.model_name.human(count: 2), sheet_path_for(sheet_name),
<%= link_to sheet.model.model_name.human(count: 2), sheets_path(sheet_name),
class: ("active" if params[:sheet_name] == sheet_name), data: { x: index } %>
</li>
<% end %>
Expand Down
9 changes: 4 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# frozen_string_literal: true

Hotsheet::Engine.routes.draw do
next unless defined? Rails::Server
root "home#show"

Hotsheet.sheets.each_key do |sheet_name|
resources sheet_name, sheet_name:, controller: :sheets, only: %i[index update]
scope ":sheet_name" do
resources controller: :sheets, only: %i[index update], as: :sheets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resources controller: :sheets, only: %i[index update], as: :sheets
resources :sheets, only: %i[index update]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried this too, but unfortunately it doesn't work (/sheets/):

Routes for Hotsheet::Engine:
  root GET   /                                 hotsheet/home#show
sheets GET   /:sheet_name/sheets(.:format)     hotsheet/sheets#index
 sheet PUT /:sheet_name/sheets/:id(.:format) hotsheet/sheets#update

end
Comment on lines -6 to 8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice refactoring!


root "sheets#root"
match "*path", to: "sheets#error", via: :all
match "*path", to: "home#error", via: :all
end
13 changes: 13 additions & 0 deletions spec/requests/hotsheet/home_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe Hotsheet::HomeController do
describe "#error" do
it "shows an error page" do
get "/hotsheet/invalid/route"
expect(response).to be_not_found
expect(response.body).to include I18n.t("hotsheet.errors.not_found")
end
end
end
24 changes: 12 additions & 12 deletions spec/requests/hotsheet/sheets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@
before { prepare { config } }

describe "#index" do
it "shows a table with all values" do
get hotsheet.users_path
it "shows a spreadsheet with all values" do
get hotsheet.sheets_path :users
expect(response).to be_successful
expect(response.body).to include user.name
end

context "when the sheet does not exist" do
it "shows an error page" do
get "/hotsheet/authors"
expect(response).to be_not_found
expect(response.body).to include I18n.t("hotsheet.errors.not_found")
end
end
end

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

it "updates the resource" do
expect { put path, params: { column_name: :name, value: "Bob" } }
Expand All @@ -43,7 +51,7 @@
end

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

it "does not update the resource" do
expect { put path, params: { column_name: :name, value: "Bob" } }.not_to change(user, :reload)
Expand All @@ -65,12 +73,4 @@
end
end
end

describe "#error" do
it "shows an error page" do
get "/hotsheet/authors"
expect(response).to be_not_found
expect(response.body).to include I18n.t("hotsheet.errors.not_found")
end
end
end
2 changes: 0 additions & 2 deletions spec/support/utils.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

def prepare(&)
stub_const "Rails::Server", true
Hotsheet.instance_variable_set :@sheets, nil # reset memoized sheets
yield
Rails.application.reload_routes!
end
2 changes: 1 addition & 1 deletion spec/system/hotsheet/sheets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
before { prepare { Hotsheet.configure { sheet :User } } }

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

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