diff --git a/spec/controllers/products_controller_spec.rb b/spec/controllers/products_controller_spec.rb index cad1844..e3af36b 100644 --- a/spec/controllers/products_controller_spec.rb +++ b/spec/controllers/products_controller_spec.rb @@ -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 diff --git a/spec/factories/products.rb b/spec/factories/products.rb index 54f45aa..16dfb06 100644 --- a/spec/factories/products.rb +++ b/spec/factories/products.rb @@ -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 } diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index a42e40e..a0d2fdc 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -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) }