jam-cloud/ruby/spec/jam_ruby/models/retailer_spec.rb

53 lines
1.4 KiB
Ruby

require 'spec_helper'
describe Retailer do
it "created by factory" do
FactoryGirl.create(:retailer)
end
it "doesn't match uuid password" do
retailer= FactoryGirl.create(:retailer)
retailer.reload
retailer.matches_password('hha').should be false
end
it "automatic slug creation" do
retailer= FactoryGirl.create(:retailer, slug: nil)
retailer.id.should_not be_blank
retailer.slug.should eql retailer.id.to_s
end
it "has correct associations" do
retailer = FactoryGirl.create(:retailer)
retailer.should eql retailer.user.owned_retailer
teacher = FactoryGirl.create(:teacher, retailer: retailer)
retailer.reload
retailer.teachers.to_a.should eql [teacher]
teacher.retailer.should eql retailer
end
it "updates" do
retailer = FactoryGirl.create(:retailer)
retailer.update_from_params({name: 'hahah'})
retailer.errors.any?.should be false
end
it "updates password" do
retailer = FactoryGirl.create(:retailer)
retailer.update_from_params({name: 'hahah', password: 'abc'})
retailer.errors.any?.should be true
retailer.errors[:password].should eql ['is too short (minimum is 6 characters)']
retailer.update_from_params({name: 'hahah', password: 'abcdef'})
retailer.errors.any?.should be false
retailer.matches_password('abcdef').should be true
retailer = Retailer.find_by_id(retailer.id)
retailer.matches_password('abcdef').should be true
end
end