Fixes and add label to tables
This commit is contained in:
@@ -24,13 +24,13 @@ describe Suppliers::TablesController, type: :controller do
|
||||
describe "GET #show" do
|
||||
it "assigns the requested table to @table" do
|
||||
table = create :table, supplier: @supplier
|
||||
get :show, id: table, format: :json
|
||||
get :show, params: {id: table}, format: :json
|
||||
assigns(:table).should eq(table)
|
||||
end
|
||||
|
||||
it "should not display a table of another supplier" do
|
||||
table = create :table
|
||||
get :show, id: table, format: :json
|
||||
get :show, params: {id: table}, format: :json
|
||||
response.status.should == 404
|
||||
end
|
||||
end
|
||||
@@ -39,13 +39,13 @@ describe Suppliers::TablesController, type: :controller do
|
||||
context "with valid attributes" do
|
||||
it "creates a new table" do
|
||||
expect{
|
||||
post :create, table: {number: 22}
|
||||
post :create, params: {table: {number: 22}}
|
||||
}.to change(Table, :count).by(1)
|
||||
end
|
||||
|
||||
it "should not be possible to create a table for another supplier, linked to signed in supplier instead" do
|
||||
supplier2 = create :supplier
|
||||
expect { post :create, table: {number: 6, supplier_id: supplier2.id} }.to change{ Table.count }.by(1)
|
||||
expect { post :create, params: {table: {number: 6, supplier_id: supplier2.id}} }.to change{ Table.count }.by(1)
|
||||
created_table = Table.find_by_number(6)
|
||||
expect( created_table.supplier_id ).to eq @supplier.id
|
||||
end
|
||||
@@ -59,27 +59,27 @@ describe Suppliers::TablesController, type: :controller do
|
||||
|
||||
context "valid attributes" do
|
||||
it "located the requested table" do
|
||||
put :update, id: @table.id, table: {number: 22}
|
||||
put :update, params: {id: @table.id, table: {number: 22}}
|
||||
@table.reload
|
||||
assigns(:table).should eq(@table)
|
||||
end
|
||||
|
||||
it "changes @table's number attribute" do
|
||||
put :update, id: @table, table: {number: "14"}
|
||||
put :update, params: {id: @table, table: {number: "14"}}
|
||||
@table.reload
|
||||
@table.number.should eq(14)
|
||||
end
|
||||
|
||||
it "should not be possible to update a table to another supplier" do
|
||||
supplier2 = create :supplier
|
||||
put :update, id: @table.id, table: {number: 6, supplier_id: supplier2.id}
|
||||
put :update, params: {id: @table.id, table: {number: 6, supplier_id: supplier2.id}}
|
||||
@table.reload
|
||||
expect( @table.supplier_id ).to eq @supplier.id
|
||||
end
|
||||
|
||||
it "should not be possible to update a table of another supplier" do
|
||||
table = create :table, number: 11
|
||||
put :update, id: table.id, table: {number: 6}
|
||||
put :update, params: {id: table.id, table: {number: 6}}
|
||||
table.reload
|
||||
table.number.should == 11
|
||||
end
|
||||
@@ -87,7 +87,7 @@ describe Suppliers::TablesController, type: :controller do
|
||||
|
||||
context "invalid attributes" do
|
||||
it "returns an error response" do
|
||||
#put :update, id: @table, format: :json, table: {number: 'aaa'}
|
||||
#put :update, params: {id: @table, format: :json, table: {number: 'aaa'}}
|
||||
#TODO: when proper invalid tables exist expect( JSON.parse(response.body)['errors'] ).to be_present
|
||||
end
|
||||
end
|
||||
@@ -100,14 +100,14 @@ describe Suppliers::TablesController, type: :controller do
|
||||
|
||||
it "deletes the table" do
|
||||
expect{
|
||||
delete :destroy, id: @table
|
||||
delete :destroy, params: {id: @table}
|
||||
}.to change(Table, :count).by(-1)
|
||||
end
|
||||
|
||||
it "should not be possible to delete a table of another supplier" do
|
||||
table = create :table
|
||||
expect{
|
||||
delete :destroy, id: table
|
||||
delete :destroy, params: {id: table}
|
||||
}.to_not change(Table, :count)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user