make more specs work

This commit is contained in:
2025-09-23 17:45:00 -05:00
parent 6596693238
commit 7dadb28004
7 changed files with 84 additions and 52 deletions
@@ -38,19 +38,19 @@ describe Suppliers::ListsController, type: :controller do
describe "GET #show" do
it "assigns the requested list to @list" do
list = create :list, supplier: @supplier
get :show, id: list
get :show, params: {id: list.id}
assigns(:list).should eq(list)
end
it "should not display a list of another supplier" do
list = create :list
get :show, id: list
get :show, params: {id: list.id}
response.status.should == 404
end
it "renders the #show view" do
list = create :list, supplier: @supplier
get :show, id: list
get :show, params: {id: list.id}
response.body.should include 'orders'
end
end
@@ -66,13 +66,13 @@ describe Suppliers::ListsController, type: :controller do
context "with valid attributes" do
it "creates a new list" do
expect{
post :create, list: valid_attributes
post :create, params: {list: valid_attributes}
}.to change(List, :count).by(1)
end
it "should not be possible to create a list for another supplier" do
supplier2 = create :supplier
post :create, list: valid_attributes.merge(price: '6.66', supplier_id: supplier2.id)
post :create, params: {list: valid_attributes.merge(price: '6.66', supplier_id: supplier2.id)}
expect( List.find_by_price(6.66).supplier_id ).to eq @supplier.id
end
end
@@ -80,13 +80,13 @@ describe Suppliers::ListsController, type: :controller do
context "with invalid attributes", broken: true do
it "does not save the new list" do
expect{
post :create, format: :json, list: invalid_params
post :create, params: {list: invalid_params}, format: :json
}.not_to change{ List.count }
List.count.should be_zero
end
it 'returns an error object' do
post :create, format: :json, list: invalid_params
post :create, params: {list: invalid_params}, format: :json
expect( JSON.parse(response.body)['errors'] ).to be_present
end
end
@@ -99,27 +99,27 @@ describe Suppliers::ListsController, type: :controller do
context "valid attributes" do
it "located the requested list" do
put :update, id: @list, list: valid_attributes
put :update, params: {id: @list.id, list: valid_attributes}
@list.reload
assigns(:list).should eq(@list)
end
it "changes @list's price attribute" do
put :update, id: @list, list: valid_attributes.merge(price: '7.22')
put :update, params: {id: @list.id, list: valid_attributes.merge(price: '7.22')}
@list.reload
@list.price.should eq(7.22)
end
it "should not be possible to update a list to another supplier" do
supplier2 = create :supplier
put :update, id: @list, list: valid_attributes.merge(supplier_id: supplier2.id)
put :update, params: {id: @list.id, list: valid_attributes.merge(supplier_id: supplier2.id)}
@list.reload
@list.supplier_id.should == @supplier.id
end
it "should not be possible to update a list of another supplier" do
list = create :list, price: '7.22'
put :update, id: list, list: {price: '6.66'}
put :update, params: {id: list.id, list: {price: '6.66'}}
list.reload
list.price.should == 7.22
end
@@ -127,7 +127,7 @@ describe Suppliers::ListsController, type: :controller do
context "invalid attributes", broken: true do
it "returns an error response" do
put :update, id: @list, format: :json, list: invalid_params
put :update, params: {id: @list, list: invalid_params}, format: :json
expect( JSON.parse( response.body )['errors']).to be_present
end
end
@@ -140,14 +140,14 @@ describe Suppliers::ListsController, type: :controller do
it "deletes the list" do
expect{
delete :destroy, id: @list
delete :destroy, params: {id: @list.id}
}.to change(List, :count).by(-1)
end
it "should not be possible to delete a list of another supplier" do
list = create :list
expect{
delete :destroy, id: list
delete :destroy, params: {id: list.id}
}.to_not change(List, :count)
end
end