ruby on rails - Explanation of why "Expected result to have changed by 1, but was changed by 0" error happens and what to do to fix it -


i have feature in user able add new location, , i'm having hard time adding test it. (i'm horrible @ testing, trying hard better.)

i feel close getting test work. error running right

expected result have changed 1, changed 0

now don't know i'm doing wrong. i'm wondering if me allow test pass, kind of explanation of happening when error happens. i'm trying become better testing been i've avoided , until accepted importance of it, , had courage understand it.

here spec file

require 'spec_helper'  describe admin::locationscontroller, type: :controller   let(:admin) { factorygirl.create(:admin) }    context 'super admin'     let!(:super_admin) { factorygirl.create(:super_admin) }    before(:each)     sign_in(:user, super_admin)   end    describe '#create'     'creates new location'        expect{         post :create, location: {           name: 'sample location',           phone: '5555555555',           fax: '5555555555',           location_id: '123456',            address_attributes: {             address1: '12345 st',             city: 'portland',             state: 'or',             zip: '91237'           }         }, format: :json        }.to change {location.count}.by(1)        new_location = location.last       expect(new_location.name).to eq 'sample location'       expect(new_location.phone).to eq '5555555555'       expect(new_location.fax).to eq '5555555555'       expect(new_location.location_id). eq '123456'       expect(new_location.address.address1).to eq '12345 st'       expect(new_location.address.city).to eq 'portland'       expect(new_location.address.state).to eq 'or'       expect(new_location.address.zip).to eq '91237'     end   end end 

and here factory

factorygirl.define   factory :location |c|     c.name 'sample location'     c.phone '5555555555'     c.fax '5555555555'     location_id '123456'     association :address, factory: :address   end end 


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -