Factory-girl create that bypasses my model validation

This isn’t very specific to FactoryGirl, but you can always bypass validations when saving models via save(validate: false): describe “.current” do let!(:current_group) { FactoryGirl.create(:group) } let!(:old_group) do g = FactoryGirl.build(:group, expiry: Time.now – 3.days) g.save(validate: false) g end specify { Group.current.should == [current_group] } end

How is spec/rails_helper.rb different from spec/spec_helper.rb? Do I need it?

rspec-rails 3 generates spec_helper.rb and rails_helper.rb. spec_helper.rb is for specs which don’t depend on Rails (such as specs for classes in the lib directory). rails_helper.rb is for specs which do depend on Rails (in a Rails project, most or all of them). rails_helper.rb requires spec_helper.rb. So no, don’t get rid of rails_helper.rb; require it (and … Read more

RSpec: What is the difference between a feature and a request spec?

The conceptual difference is that you’re usually testing a user story, and all interaction should be driven via the user interface. That’s where Capybara comes in. A request spec is still testing the behavior of your application and doesn’t have the expectation of readability that an acceptance test would have. So, feature is there for … Read more

test a file upload using rspec – rails

You can use fixture_file_upload method to test file uploading: Put your test file in “{Rails.root}/spec/fixtures/files” directory before :each do @file = fixture_file_upload(‘files/test_lic.xml’, ‘text/xml’) end it “can upload a license” do post :uploadLicense, :upload => @file response.should be_success end In case you were expecting the file in the form of params[‘upload’][‘datafile’] it “can upload a license” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)