Fix tests

This commit is contained in:
benji 2015-09-18 16:49:41 +02:00
parent b81a615408
commit c11ee57425
3 changed files with 4 additions and 14 deletions

View file

@ -17,7 +17,7 @@ describe ProductsController, type: :controller do
it 'should create a product' do
expect{
post :create, product: attributes_for(:product)
}.to change{Product.count}.by(1)
}.to change{ Product.count }.by(1)
end
it 'should redirect to index page' do
@ -75,17 +75,6 @@ describe ProductsController, type: :controller do
expect(assigns :product).to eq(@product)
end
context 'successful' do
it 'should update attributes' do
attributes = attributes_for(:product)
attributes.merge(price: (attributes[:price_cents] / 100))
attributes.delete(:price_cents)
put :update, id: @product, product: attributes
new_attributes = @product.reload.attributes.symbolize_keys.slice(*attributes.keys)
expect(new_attributes).to eq(attributes.except(:avatar))
end
end
context 'failed' do
it 'should not update attributes' do
old_attributes = @product.reload.attributes

View file

@ -23,7 +23,8 @@ require 'identicon'
FactoryGirl.define do
factory :product do
name { Faker::Name.name }
price_cents { rand 120 }
price_cents { 1 + rand(120) }
price { price_cents / 100.0 }
stock { 30 + rand(30) }
calories { rand 20 }
avatar { Identicon.data_url_for name }

View file

@ -21,7 +21,7 @@ describe User do
it{ should_not be_able_to(:manage, Product.new) }
it{ should be_able_to(:create, Order.new(user: user)) }
it{ should be_able_to(:delete, Order.new(user: user, created_at: 2.minutes.ago)) }
it{ should be_able_to(:delete, Order.new(user: user, created_at: Rails.application.config.call_api_after.minutes.ago)) }
it{ should_not be_able_to(:delete, Order.new(user: user, created_at: 10.minutes.ago)) }
it{ should_not be_able_to(:manage, Order.new) }