I'm trying to test a method on my model. Running in the console works, but my rspec test does not pass. Checkout the code:
Model:
def import(master)
hsh = master.attributes.delete_if { |k,v| k == 'id' }
self.update_attributes(hsh)
end
Rspec test:
describe "#import" do
let(:master) { Factory(:sheet, :work_order => 'M1234', :sample_size => 10, :sample_scheme => 'TEST#') }
let(:wo) { Factory(:sheet, :work_order => 'W1234', :sample_scheme => 'ORIG#' ) }
it "imports all of the attributes from the master" do
expect { wo.import(master) }.to change( wo, :sample_scheme ).to(master.sample_scheme)
end
end
I can't figure this out, here is the output:
'Sheet#import imports all of the attributes from the master' FAILED
sample_scheme should have been changed to "TEST#", but is now "ORIG#"
As I said, the code correctly imports the attributes from the master when run in the console. It's just the rspec test is failing. What am I doing wrong?
change to import function results in passing:
def import(master)
hsh = master.attributes.delete_if { |k,v| k == 'id' }
hsh.each do |k,v|
self.update_attribute(k, v)
end
#self.update_attribute(:sample_scheme, hsh['sample_scheme'])
#self.update_attributes(hsh)
end