Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec Factory Girl Model Singular Plural (uninitialized constant [ModelName])

Getting an error when I try to test my model called Settings, I have a feeling it has something to do with singular and plural model names, but how do I fix it?

here is the spec settings_spec.rb:

require 'spec_helper'

describe Settings do
  let!(:settings) { Factory(:settings) }

  describe "has a valid factory" do
    specify { should be_an_instance_of(Settings) }
  end

end


1) Settings has a valid factory 
     Failure/Error: let!(:settings) { Factory(:settings) }
     NameError:
       uninitialized constant Setting
     # ./spec/models/settings_spec.rb:4:in `block (2 levels) in <top (required)>'

My model is truly named Settings, the file name is settings.rb. Thanks!

like image 561
botbot Avatar asked Jan 25 '26 12:01

botbot


1 Answers

It expects model name to be Setting. Either rename model app/model/setting.rb to Setting or goto the file config/initializers/inflections.rb and add settings to uncountable configuration.

ActiveSupport::Inflector.inflections do |inflect|
  inflect.uncountable %w(settings)
end
like image 70
Sandip Ransing Avatar answered Jan 28 '26 02:01

Sandip Ransing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!