Skip to content

Commit 6f08845

Browse files
committed
Simplify Rails specs from dummy app to single file app
1 parent ae5f696 commit 6f08845

50 files changed

Lines changed: 393 additions & 914 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gemfile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,4 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
44
# Specify your gem's dependencies in restomatic.gemspec.
55
gemspec
66

7-
gem "sqlite3"
8-
9-
gem "sprockets-rails"
10-
11-
# Start debugger with binding.b [https://github.com/ruby/debug]
12-
# gem "debug", ">= 1.0.0"
13-
14-
gem "rspec-rails", "~> 5.1"
7+
gem "rspec-rails", "~> 5.1"

Gemfile.lock

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,6 @@ GEM
199199
rspec-support (~> 3.10)
200200
rspec-support (3.13.6)
201201
securerandom (0.4.1)
202-
sprockets (4.2.2)
203-
concurrent-ruby (~> 1.0)
204-
logger
205-
rack (>= 2.2.4, < 4)
206-
sprockets-rails (3.5.2)
207-
actionpack (>= 6.1)
208-
activesupport (>= 6.1)
209-
sprockets (>= 3.0.0)
210-
sqlite3 (2.8.0-arm64-darwin)
211-
sqlite3 (2.8.0-x86_64-darwin)
212202
stringio (3.1.8)
213203
thor (1.4.0)
214204
timeout (0.4.4)
@@ -232,8 +222,6 @@ PLATFORMS
232222
DEPENDENCIES
233223
restomatic!
234224
rspec-rails (~> 5.1)
235-
sprockets-rails
236-
sqlite3
237225

238226
BUNDLED WITH
239227
2.3.13

lib/restomatic/routing_mapper.rb

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,78 @@ def nest(name = nil, *args, except: nil, **kwargs, &block)
99
end
1010

1111
if name.nil?
12-
scope module: parent_resource.name, &block
12+
scope module: parent_module_name, &block
1313
elsif is_singular_resource_name? name
14-
scope module: parent_resource.name do
14+
scope module: parent_module_name do
1515
except ||= %i[edit update destroy]
1616
resource name, *args, except: except, **kwargs, &block
1717
end
1818
else
19-
scope module: parent_resource.name do
19+
scope module: parent_module_name do
2020
except ||= %i[show edit update destroy]
2121
resources name, *args, except: except, **kwargs, &block
2222
end
2323
end
2424
end
2525

2626
def create(name, *args, **kwargs, &block)
27-
inflect_resource_plurality name, *args, only: %i[new create], **kwargs, &block
27+
if resource_scope? && !@scope[:module]
28+
scope module: parent_module_name do
29+
resource name, *args, only: %i[new create], **kwargs, &block
30+
end
31+
else
32+
resource name, *args, only: %i[new create], **kwargs, &block
33+
end
2834
end
2935

3036
def edit(name, *args, **kwargs, &block)
31-
inflect_resource_plurality name, *args, only: %i[edit update], **kwargs, &block
37+
if resource_scope? && !@scope[:module]
38+
scope module: parent_module_name do
39+
resource name, *args, only: %i[edit update], **kwargs, &block
40+
end
41+
else
42+
resource name, *args, only: %i[edit update], **kwargs, &block
43+
end
3244
end
3345

3446
def show(name, *args, **kwargs, &block)
35-
inflect_resource_plurality name, *args, only: :show, **kwargs, &block
47+
if resource_scope? && !@scope[:module]
48+
scope module: parent_module_name do
49+
resource name, *args, only: :show, **kwargs, &block
50+
end
51+
else
52+
resource name, *args, only: :show, **kwargs, &block
53+
end
3654
end
3755

3856
def destroy(name, *args, **kwargs, &block)
39-
inflect_resource_plurality name, *args, only: :destroy, **kwargs, &block
57+
if resource_scope? && !@scope[:module]
58+
scope module: parent_module_name do
59+
resource name, *args, only: :destroy, **kwargs, &block
60+
end
61+
else
62+
resource name, *args, only: :destroy, **kwargs, &block
63+
end
4064
end
4165

42-
def list(name, *args, **kwargs, &block)
43-
inflect_resource_plurality name, *args, only: :index, **kwargs, &block
66+
def index(name, *args, **kwargs, &block)
67+
if resource_scope? && !@scope[:module]
68+
scope module: parent_module_name do
69+
resources name, *args, only: :index, **kwargs, &block
70+
end
71+
else
72+
resources name, *args, only: :index, **kwargs, &block
73+
end
4474
end
4575

4676
private
4777

78+
def parent_module_name
79+
# For singular resources (resource :account), Rails uses plural controller names (AccountsController)
80+
# So we need to pluralize the parent resource name for the module scope
81+
parent_resource.singular ? parent_resource.name.to_s.pluralize : parent_resource.name
82+
end
83+
4884
def is_singular_resource_name?(name)
4985
name_string = name.to_s
5086
name_string.singularize == name_string

spec/dummy/Rakefile

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

spec/dummy/app/assets/config/manifest.js

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

spec/dummy/app/assets/images/.keep

Whitespace-only changes.

spec/dummy/app/assets/stylesheets/application.css

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

spec/dummy/app/channels/application_cable/channel.rb

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

spec/dummy/app/channels/application_cable/connection.rb

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

spec/dummy/app/controllers/application_controller.rb

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

0 commit comments

Comments
 (0)