Add spring and fix controller specs

This commit is contained in:
2014-07-14 14:09:35 +02:00
parent 96841116c5
commit 6420b428a7
13 changed files with 147 additions and 185 deletions
@@ -1,10 +1,10 @@
# encoding: UTF-8
require 'spec_helper'
describe Suppliers::TablesController do
describe Suppliers::TablesController, type: :controller do
before :each do
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
controller.stub(:table_params){ controller.params.require(:table).permit! } # allow all parameters since cross parameter injection is tested
#controller.stub(:table_params){ controller.params.require(:table).permit! } # allow all parameters since cross parameter injection is tested
sign_in @supplier
end
@@ -69,19 +69,19 @@ describe Suppliers::TablesController do
context "with valid attributes" do
it "creates a new table" do
expect{
post :create, table: attributes_for(:table, supplier: @supplier)
post :create, table: {number: 22}
}.to change(Table, :count).by(1)
end
it "redirects to the new table" do
post :create, table: attributes_for(:table, supplier: @supplier)
post :create, table: {number: 22}
response.should redirect_to [:suppliers, Table.last]
end
it "should not be possible to create a table for another supplier" do
supplier2 = create :supplier
post :create, table: attributes_for(:table, number: 6, supplier: supplier2)
Table.find_by_number(6).supplier_id.should == @supplier.id
expect { post :create, table: {number: 6, supplier_id: supplier2.id} }.to raise_error
Table.find_by_number(6).should_not be_present
end
end
@@ -106,25 +106,29 @@ describe Suppliers::TablesController do
context "valid attributes" do
it "located the requested table" do
put :update, id: @table, table: attributes_for(:table, supplier: @supplier)
put :update, id: @table, table: {number: 22}
@table.reload
assigns(:table).should eq(@table)
end
it "changes @table's attributes" do
put :update, id: @table, table: attributes_for(:table, number: "14", supplier: @supplier)
it "changes @table's number attribute" do
put :update, id: @table, table: {number: "14"}
@table.reload
@table.number.should eq(14)
end
it "redirects to the updated table" do
put :update, id: @table, table: attributes_for(:table, supplier: @supplier)
put :update, id: @table, table: {number: 22}
response.should redirect_to [:suppliers, @table]
end
it "should not be possible to update a table to another supplier" do
supplier2 = create :supplier
put :update, id: @table, table: attributes_for(:table, number: 6, supplier: supplier2)
Table.find_by_number(6).supplier_id.should == @supplier.id
expect{
put :update, id: @table.id, table: {number: 6, supplier_id: supplier2.id}
}.to raise_error
@table.reload
@table.supplier_id.should == @supplier.id
end
it "should not be possible to update a table of another supplier" do