File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
lib/generators/rspec/scaffold
spec/generators/rspec/scaffold Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -73,21 +73,31 @@ def copy_view(view)
73
73
74
74
# support for namespaced-resources
75
75
def ns_file_name
76
- ns_parts . empty? ? file_name : "#{ ns_parts [ 0 ] . underscore } _#{ ns_parts [ 1 ] . singularize . underscore } "
76
+ return file_name if ns_parts . empty?
77
+ "#{ ns_prefix . map ( &:underscore ) . join ( '/' ) } _#{ ns_suffix . singularize . underscore } "
77
78
end
78
79
79
80
# support for namespaced-resources
80
81
def ns_table_name
81
- ns_parts . empty? ? table_name : "#{ ns_parts [ 0 ] . underscore } /#{ ns_parts [ 1 ] . tableize } "
82
+ return table_name if ns_parts . empty?
83
+ "#{ ns_prefix . map ( &:underscore ) . join ( '/' ) } /#{ ns_suffix . tableize } "
82
84
end
83
85
84
86
def ns_parts
85
87
@ns_parts ||= begin
86
- matches = generator_args [ 0 ] . to_s . match ( /\A ( \w +)(?: \ / |::)( \w +) / )
87
- matches ? [ matches [ 1 ] , matches [ 2 ] ] : [ ]
88
+ parts = generator_args [ 0 ] . split ( /\/ |::/ )
89
+ parts . size > 1 ? parts : [ ]
88
90
end
89
91
end
90
92
93
+ def ns_prefix
94
+ @ns_prefix ||= ns_parts [ 0 ..-2 ]
95
+ end
96
+
97
+ def ns_suffix
98
+ @ns_suffix ||= ns_parts [ -1 ]
99
+ end
100
+
91
101
def value_for ( attribute )
92
102
raw_value_for ( attribute ) . inspect
93
103
end
Original file line number Diff line number Diff line change 48
48
it { is_expected . to contain ( /"renders a JSON response with errors for the \w +"/ ) }
49
49
50
50
it { is_expected . not_to contain ( /"redirects to the \w + list"/ ) }
51
-
52
51
end
53
52
end
54
53
226
225
it { is_expected . to contain ( /describe "routing"/ ) }
227
226
it { is_expected . to contain ( /routes to #new/ ) }
228
227
it { is_expected . to contain ( /routes to #edit/ ) }
228
+ it { is_expected . to contain ( 'route_to("posts#new")' ) }
229
229
end
230
230
231
231
describe 'with --no-routing-specs' do
238
238
it { is_expected . not_to contain ( /routes to #new/ ) }
239
239
it { is_expected . not_to contain ( /routes to #edit/ ) }
240
240
end
241
+
242
+ context 'with a namespaced name' do
243
+ subject { file ( 'spec/routing/api/v1/posts_routing_spec.rb' ) }
244
+
245
+ describe 'with default options' do
246
+ before { run_generator %w( api/v1/posts ) }
247
+ it { is_expected . to contain ( /^RSpec.describe Api::V1::PostsController, #{ type_metatag ( :routing ) } / ) }
248
+ it { is_expected . to contain ( 'route_to("api/v1/posts#new")' ) }
249
+ end
250
+ end
241
251
end
242
252
end
You can’t perform that action at this time.
0 commit comments