Skip to content

Commit 7487c8b

Browse files
Michel Oconbenoittgt
authored andcommitted
Fix fixtures path for model generator when using namespaced models
1 parent dd1fae6 commit 7487c8b

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

lib/generators/rspec/model/model_generator.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ def create_model_spec
2323

2424
def create_fixture_file
2525
return unless missing_fixture_replacement?
26-
27-
template 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
26+
template 'fixtures.yml', File.join('spec/fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
2827
end
2928

3029
private

spec/generators/rspec/model/model_generator_spec.rb

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,10 @@
1212
gen.invoke_all
1313
end
1414

15-
describe 'the generated files' do
16-
describe 'with fixtures' do
17-
before do
18-
run_generator %w(posts --fixture)
19-
end
20-
21-
describe 'the spec' do
22-
subject { file('spec/models/posts_spec.rb') }
23-
24-
it { is_expected.to exist }
25-
it { is_expected.to contain(/require 'rails_helper'/) }
26-
it { is_expected.to contain(/^RSpec.describe Posts, #{type_metatag(:model)}/) }
27-
end
28-
29-
describe 'the fixtures' do
30-
subject { file('spec/fixtures/posts.yml') }
31-
32-
it { is_expected.to contain(Regexp.new('# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html')) }
33-
end
34-
end
15+
it_behaves_like 'a model generator with fixtures', 'admin/posts', 'Admin::Posts'
16+
it_behaves_like 'a model generator with fixtures', 'posts', 'Posts'
3517

18+
describe 'the generated files' do
3619
describe 'without fixtures' do
3720
before do
3821
run_generator %w(posts)

spec/support/generators.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ def self.included(klass)
1919
klass.extend(Macros)
2020
end
2121

22+
shared_examples_for 'a model generator with fixtures' do |name, class_name|
23+
before { run_generator [name, '--fixture'] }
24+
25+
describe 'the spec' do
26+
subject { file("spec/models/#{name}_spec.rb") }
27+
28+
it { is_expected.to exist }
29+
it { is_expected.to contain(/require 'rails_helper'/) }
30+
it { is_expected.to contain(/^RSpec.describe #{class_name}, #{type_metatag(:model)}/) }
31+
end
32+
33+
describe 'the fixtures' do
34+
subject { file("spec/fixtures/#{name}.yml") }
35+
36+
it { is_expected.to contain(Regexp.new('# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html')) }
37+
end
38+
end
39+
2240
shared_examples_for "a request spec generator" do
2341
describe 'generated with flag `--no-request-specs`' do
2442
before do

0 commit comments

Comments
 (0)