Add spring and fix controller specs
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Suppliers::ListsController do
|
||||
describe Suppliers::ListsController, type: :controller do
|
||||
before :each do
|
||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
|
||||
ActionController::Parameters.permit_all_parameters = false
|
||||
controller.stub(:list_params){ controller.params.require(:list).permit! } # allow all parameters since cross parameter injection is tested
|
||||
#controller.stub(:list_params){ controller.params.require(:list).permit! } # allow all parameters since cross parameter injection is tested
|
||||
sign_in @supplier
|
||||
end
|
||||
|
||||
def valid_attributes
|
||||
{state: 'active'}
|
||||
end
|
||||
|
||||
def invalid_params
|
||||
{foo: 'bar'}
|
||||
end
|
||||
|
||||
#after :each do
|
||||
#ActionController::Parameters.permit_all_parameters = true
|
||||
#end
|
||||
|
||||
describe "GET #index" do
|
||||
it "populates an array of lists" do
|
||||
list = create :list, supplier: @supplier
|
||||
get :index
|
||||
assigns(:lists).should eq([list])
|
||||
end
|
||||
|
||||
it "has pagination options if show_all is given" do
|
||||
list = create :list, supplier: @supplier
|
||||
get :index, show_all: 'yes'
|
||||
@@ -81,32 +83,28 @@ describe Suppliers::ListsController do
|
||||
context "with valid attributes" do
|
||||
it "creates a new list" do
|
||||
expect{
|
||||
post :create, list: attributes_for(:list, supplier: @supplier)
|
||||
post :create, list: valid_attributes
|
||||
}.to change(List, :count).by(1)
|
||||
end
|
||||
|
||||
it "redirects to the new list" do
|
||||
post :create, list: attributes_for(:list, supplier: @supplier)
|
||||
post :create, list: valid_attributes
|
||||
response.should redirect_to [:suppliers, List.last]
|
||||
end
|
||||
|
||||
it "should not be possible to create a list for another supplier" do
|
||||
supplier2 = create :supplier
|
||||
post :create, list: attributes_for(:list, price: '6.66', supplier: supplier2)
|
||||
List.find_by_price(6.66).supplier_id.should == @supplier.id
|
||||
expect{ post :create, list: valid_attributes.merge(price: '6.66', supplier_id: supplier2.id) }.to raise_error
|
||||
List.find_by_price(6.66).should_not be_present
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid attributes" do
|
||||
it "does not save the new list" do
|
||||
expect{
|
||||
post :create, list: {table_id: ''}
|
||||
}.to_not change(List, :count)
|
||||
end
|
||||
|
||||
it "re-renders the new method" do
|
||||
post :create, list: {table_id: ''}
|
||||
response.should render_template :new
|
||||
post :create, list: invalid_params
|
||||
}.to raise_error
|
||||
List.count.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -118,24 +116,25 @@ describe Suppliers::ListsController do
|
||||
|
||||
context "valid attributes" do
|
||||
it "located the requested list" do
|
||||
put :update, id: @list, list: attributes_for(:list, supplier: @supplier)
|
||||
put :update, id: @list, list: valid_attributes
|
||||
@list.reload
|
||||
assigns(:list).should eq(@list)
|
||||
end
|
||||
|
||||
it "changes @list's attributes" do
|
||||
put :update, id: @list, list: attributes_for(:list, price: "7.22", supplier: @supplier)
|
||||
it "changes @list's price attribute" do
|
||||
put :update, id: @list, list: valid_attributes.merge(price: '7.22')
|
||||
@list.reload
|
||||
@list.price.should eq(7.22)
|
||||
end
|
||||
|
||||
it "redirects to the updated list" do
|
||||
put :update, id: @list, list: attributes_for(:list, supplier: @supplier)
|
||||
put :update, id: @list, list: valid_attributes
|
||||
response.should redirect_to [:suppliers, @list]
|
||||
end
|
||||
|
||||
it "should not be possible to update a list to another supplier" do
|
||||
supplier2 = create :supplier
|
||||
put :update, id: @list, list: attributes_for(:list, supplier: supplier2)
|
||||
expect{ put :update, id: @list, list: valid_attributes.merge(supplier_id: supplier2.id) }.to raise_error
|
||||
@list.reload
|
||||
@list.supplier_id.should == @supplier.id
|
||||
end
|
||||
@@ -149,14 +148,8 @@ describe Suppliers::ListsController do
|
||||
end
|
||||
|
||||
context "invalid attributes" do
|
||||
it "locates the requested list" do
|
||||
put :update, id: @list, list: {table_id: ''}
|
||||
assigns(:list).should eq(@list)
|
||||
end
|
||||
|
||||
it "re-renders the edit method" do
|
||||
put :update, id: @list, list: {table_id: ''}
|
||||
response.should render_template :edit
|
||||
it "raises on invalid params" do
|
||||
expect{ put :update, id: @list, list: invalid_params }.to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -168,7 +161,7 @@ describe Suppliers::ListsController do
|
||||
|
||||
it "deletes the list" do
|
||||
expect{
|
||||
delete :destroy, id: @list
|
||||
delete :destroy, id: @list
|
||||
}.to change(List, :count).by(-1)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user