Skip to content

Fix fixtures path for model generator when using namespaced models #2077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Feb 12, 2019
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
2 changes: 1 addition & 1 deletion lib/generators/rspec/model/model_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create_model_spec

def create_fixture_file
return unless missing_fixture_replacement?
template 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
template 'fixtures.yml', File.join('spec/fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
end

private
Expand Down
23 changes: 3 additions & 20 deletions spec/generators/rspec/model/model_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,10 @@
gen.invoke_all
end

describe 'the generated files' do
describe 'with fixtures' do
before do
run_generator %w(posts --fixture)
end

describe 'the spec' do
subject { file('spec/models/posts_spec.rb') }

it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/^RSpec.describe Posts, #{type_metatag(:model)}/) }
end

describe 'the fixtures' do
subject { file('spec/fixtures/posts.yml') }

it { is_expected.to contain(Regexp.new('# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html')) }
end
end
it_behaves_like 'a model generator with fixtures', 'admin/posts', 'Admin::Posts'
it_behaves_like 'a model generator with fixtures', 'posts', 'Posts'

describe 'the generated files' do
describe 'without fixtures' do
before do
run_generator %w(posts)
Expand Down
18 changes: 18 additions & 0 deletions spec/support/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ def self.included(klass)
klass.extend(Macros)
end

shared_examples_for 'a model generator with fixtures' do |name, class_name|
before { run_generator [name, '--fixture'] }

describe 'the spec' do
subject { file("spec/models/#{name}_spec.rb") }

it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/^RSpec.describe #{class_name}, #{type_metatag(:model)}/) }
end

describe 'the fixtures' do
subject { file("spec/fixtures/#{name}.yml") }

it { is_expected.to contain(Regexp.new('# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html')) }
end
end

shared_examples_for "a request spec generator" do
describe 'generated with flag `--no-request-specs`' do
before do
Expand Down