More spec fixing
This commit is contained in:
@@ -21,8 +21,8 @@ step "then new product category with proper properties should have been created"
|
||||
#@product_category.week_days.should == [0, 0, 1, 0, 0, 0, 0]
|
||||
@product_category.full_day.should be true
|
||||
expect( @product_category.active_on_monday ).to be true
|
||||
expect( @product_category.active_on_monday ).to be true
|
||||
expect( @product_category.active_on_wednesday ).to be false
|
||||
expect( @product_category.active_on_tuesday ).to be false
|
||||
expect( @product_category.active_on_wednesday ).to be true
|
||||
#@product_category.product_ids.should == [@products.first.id]
|
||||
end
|
||||
|
||||
|
||||
@@ -63,7 +63,9 @@ end
|
||||
|
||||
step "the user order :product_name should be in the order list with price" do |product_name|
|
||||
concerning_product = Product.find_by_name(product_name)
|
||||
ember_order = ember_store['product_orders'].find{|po| po['product_id'] == concerning_product.id}
|
||||
#ember_order = ember_store['product_orders'].find{|po| po['product_id'] == concerning_product.id}
|
||||
ember_order = ember_find('product_order', concerning_product.id)
|
||||
binding.pry
|
||||
quantity = ember_order['quantity']
|
||||
order_price = quantity * concerning_product.price
|
||||
within '.product-orders .product-order' do
|
||||
|
||||
@@ -23,10 +23,6 @@ describe Suppliers::ProductCategoriesController, type: :controller do
|
||||
assigns(:product_categories).should eq([product_category1])
|
||||
end
|
||||
|
||||
it "should render without errors when no objects are present" do
|
||||
get :index
|
||||
expect{ render_template :index }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
@@ -65,8 +61,8 @@ describe Suppliers::ProductCategoriesController, type: :controller do
|
||||
|
||||
it "should not be possible to create a product category for another supplier" do
|
||||
supplier2 = create :supplier
|
||||
expect{ post :create, product_category: valid_attributes.merge(name: 'Trying to hack', supplier_id: supplier2.id) }.to raise_error
|
||||
ProductCategory.find_by_name('Trying to hack').should_not be_present
|
||||
post :create, product_category: valid_attributes.merge(name: 'Trying to hack', supplier_id: supplier2.id)
|
||||
expect( ProductCategory.find_by_name('Trying to hack').supplier_id ).to eq @supplier.id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -76,6 +72,11 @@ describe Suppliers::ProductCategoriesController, type: :controller do
|
||||
post :create, product_category: invalid_attributes
|
||||
}.not_to change{ ProductCategory.count }
|
||||
end
|
||||
|
||||
it 'returns an error object' do
|
||||
post :create, format: :json, product_category: invalid_attributes
|
||||
expect( JSON.parse(response.body)['errors'] ).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -99,10 +100,10 @@ describe Suppliers::ProductCategoriesController, type: :controller do
|
||||
|
||||
it "should not be possible to update a product category to another supplier" do
|
||||
supplier2 = create :supplier
|
||||
expect{
|
||||
put :update, id: @product_category, product_category: valid_attributes.merge(name: "Trying to hack", supplier_id: supplier2.id)
|
||||
}.to raise_error
|
||||
ProductCategory.find_by_name('Trying to hack').should_not be_present
|
||||
put :update, id: @product_category, product_category: valid_attributes.merge(name: "Trying to hack", supplier_id: supplier2.id)
|
||||
@product_category.reload
|
||||
expect( @product_category.name ).to eq 'Trying to hack'
|
||||
expect( @product_category.supplier_id ).to eq @supplier.id
|
||||
end
|
||||
|
||||
it "should not be possible to update a product_category of another supplier" do
|
||||
@@ -113,6 +114,13 @@ describe Suppliers::ProductCategoriesController, type: :controller do
|
||||
product_category.name.should == 'Other supplier product_category'
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid attributes" do
|
||||
it "returns an error response" do
|
||||
put :update, id: @product_category, format: :json, product_category: invalid_attributes
|
||||
expect( JSON.parse( response.body )['errors']).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
|
||||
@@ -22,11 +22,6 @@ describe Suppliers::ProductsController, type: :controller do
|
||||
get :index
|
||||
assigns(:products).should eq([product1])
|
||||
end
|
||||
|
||||
it "should render without errors when no objects are present" do
|
||||
get :index
|
||||
expect{ render_template :index }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
@@ -65,8 +60,8 @@ describe Suppliers::ProductsController, type: :controller do
|
||||
|
||||
it "should not be possible to create a product for another supplier" do
|
||||
supplier2 = create :supplier
|
||||
expect{ post :create, product: valid_attributes.merge(name: 'Trying to hack', supplier_id: supplier2.id) }.to raise_error
|
||||
Product.find_by_name('Trying to hack').should_not be_present
|
||||
post :create, product: valid_attributes.merge(name: 'Trying to hack', supplier_id: supplier2.id)
|
||||
expect( Product.find_by_name('Trying to hack').supplier_id ).to eq @supplier.id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -77,9 +72,9 @@ describe Suppliers::ProductsController, type: :controller do
|
||||
}.to_not change(Product, :count)
|
||||
end
|
||||
|
||||
it "re-renders the new method" do
|
||||
post :create, product: invalid_attributes
|
||||
response.should render_template :new
|
||||
it 'returns an error object' do
|
||||
post :create, format: :json, product: invalid_attributes
|
||||
expect( JSON.parse(response.body)['errors'] ).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -104,27 +99,22 @@ describe Suppliers::ProductsController, type: :controller do
|
||||
|
||||
it "should not be possible to update a product to another supplier" do
|
||||
supplier2 = create :supplier
|
||||
expect{ put :update, id: @product, product: valid_attributes.merge(name: "Trying to hack", supplier_id: supplier2.id) }.to raise_error
|
||||
expect( Product.find_by_name 'Trying to hack' ).not_to be_present
|
||||
put :update, id: @product, product: valid_attributes.merge(name: "Trying to hack", supplier_id: supplier2.id)
|
||||
expect( Product.find_by_name('Trying to hack' ).supplier_id ).to eq @supplier.id
|
||||
end
|
||||
|
||||
it "should not be possible to update a product of another supplier" do
|
||||
product = create :product, name: 'Other supplier product'
|
||||
put :update, id: product, product: {name: "Trying to hack"}
|
||||
product.reload
|
||||
product.name.should == 'Other supplier product'
|
||||
expect( product.name ).to eq 'Other supplier product'
|
||||
end
|
||||
end
|
||||
|
||||
context "invalid attributes" do
|
||||
it "locates the requested product" do
|
||||
put :update, id: @product, product: invalid_attributes
|
||||
assigns(:product).should eq(@product)
|
||||
end
|
||||
|
||||
it "re-renders the edit method" do
|
||||
put :update, id: @product, product: invalid_attributes
|
||||
response.should render_template :edit
|
||||
context "with invalid attributes" do
|
||||
it "returns an error response" do
|
||||
put :update, id: @product, format: :json, product: invalid_attributes
|
||||
expect( JSON.parse( response.body )['errors']).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module SpecEmberHelpers
|
||||
def ember_store
|
||||
h = page.evaluate_script <<-SCRIPT
|
||||
$s = App.__container__.lookup('controller:application').store;
|
||||
$s = App.__container__.lookup('store:main');
|
||||
JSON.stringify({
|
||||
lists: $s.all('list').invoke('serialize'),
|
||||
orders: $s.all('order').invoke('serialize'),
|
||||
@@ -15,6 +15,14 @@ module SpecEmberHelpers
|
||||
JSON.parse(h)
|
||||
end
|
||||
|
||||
def ember_find(typeKey, id)
|
||||
h = page.evaluate_script <<-SCRIPT
|
||||
$s = App.__container__.lookup('store:main');
|
||||
record = $s.all('#{typeKey}').findBy('id', '#{id}');
|
||||
record ? record.serialize() : null
|
||||
SCRIPT
|
||||
end
|
||||
|
||||
def js_path
|
||||
page.evaluate_script 'location.pathname + location.hash'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user