Add spring and fix controller specs
This commit is contained in:
@@ -72,35 +72,37 @@ gem 'mini_magick'
|
|||||||
|
|
||||||
# To use Jbuilder templates for JSON
|
# To use Jbuilder templates for JSON
|
||||||
# gem 'jbuilder'
|
# gem 'jbuilder'
|
||||||
|
#
|
||||||
|
group :development, :test do
|
||||||
|
gem 'rspec-rails'
|
||||||
|
gem 'pry-rails'
|
||||||
|
end
|
||||||
group :development do
|
group :development do
|
||||||
#gem 'pry-remote'
|
#gem 'pry-remote'
|
||||||
gem 'rspec-rails'
|
|
||||||
gem 'quiet_assets'
|
gem 'quiet_assets'
|
||||||
gem 'letter_opener'
|
gem 'letter_opener'
|
||||||
gem 'thin'
|
gem 'thin'
|
||||||
gem 'faye'
|
gem 'faye'
|
||||||
gem 'pry-rails'
|
|
||||||
gem 'capistrano', '~> 3.0', require: false
|
gem 'capistrano', '~> 3.0', require: false
|
||||||
gem 'capistrano-rvm', '~> 0.1', require: false
|
gem 'capistrano-rvm', '~> 0.1', require: false
|
||||||
gem 'capistrano-rails', '~> 1.1', require: false
|
gem 'capistrano-rails', '~> 1.1', require: false
|
||||||
#gem 'spring'
|
gem 'spring'
|
||||||
#gem 'spring-commands-rspec'
|
gem 'spring-commands-rspec'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
#gem 'steak'
|
#gem 'steak'
|
||||||
gem 'rspec-rails'
|
|
||||||
gem 'database_cleaner'
|
gem 'database_cleaner'
|
||||||
gem 'capybara' #, '2.0.3'
|
gem 'capybara' #, '2.0.3'
|
||||||
#gem 'selenium-webdriver'
|
#gem 'selenium-webdriver'
|
||||||
gem 'capybara-webkit' #, '~>0.14.2' # version 1.1.0 does not yet compile in mavericks
|
gem 'capybara-webkit' #, '~>0.14.2' # version 1.1.0 does not yet compile in mavericks
|
||||||
gem 'turnip'
|
gem 'turnip'
|
||||||
|
gem 'rspec-its'
|
||||||
gem 'launchy'
|
gem 'launchy'
|
||||||
gem 'fuubar'
|
gem 'fuubar'
|
||||||
#gem 'rb-fsevent', :require => false #if RUBY_PLATFORM =~ /darwin/i
|
#gem 'rb-fsevent', :require => false #if RUBY_PLATFORM =~ /darwin/i
|
||||||
gem 'simplecov', require: false
|
gem 'simplecov', require: false
|
||||||
gem 'factory_girl_rails'
|
gem 'factory_girl_rails'
|
||||||
gem 'pry-rails'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Use unicorn as the app server
|
# Use unicorn as the app server
|
||||||
|
|||||||
+11
-2
@@ -37,7 +37,7 @@ GIT
|
|||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/bterkuile/simply_stored.git
|
remote: git://github.com/bterkuile/simply_stored.git
|
||||||
revision: a4b672f68cbcf275aa10fc5014a3763238691956
|
revision: e0e72e8e73c59666191d578408572ed8f5de9e42
|
||||||
specs:
|
specs:
|
||||||
simply_stored (1.0.0)
|
simply_stored (1.0.0)
|
||||||
activesupport
|
activesupport
|
||||||
@@ -322,6 +322,9 @@ GEM
|
|||||||
rspec-expectations (3.0.2)
|
rspec-expectations (3.0.2)
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
diff-lcs (>= 1.2.0, < 2.0)
|
||||||
rspec-support (~> 3.0.0)
|
rspec-support (~> 3.0.0)
|
||||||
|
rspec-its (1.0.1)
|
||||||
|
rspec-core (>= 2.99.0.beta1)
|
||||||
|
rspec-expectations (>= 2.99.0.beta1)
|
||||||
rspec-mocks (3.0.2)
|
rspec-mocks (3.0.2)
|
||||||
rspec-support (~> 3.0.0)
|
rspec-support (~> 3.0.0)
|
||||||
rspec-rails (3.0.1)
|
rspec-rails (3.0.1)
|
||||||
@@ -357,6 +360,9 @@ GEM
|
|||||||
railties (>= 3.0, < 4.2)
|
railties (>= 3.0, < 4.2)
|
||||||
slim (~> 2.0)
|
slim (~> 2.0)
|
||||||
slop (3.5.0)
|
slop (3.5.0)
|
||||||
|
spring (1.1.3)
|
||||||
|
spring-commands-rspec (1.0.2)
|
||||||
|
spring (>= 0.9.1)
|
||||||
sprockets (2.11.0)
|
sprockets (2.11.0)
|
||||||
hike (~> 1.2)
|
hike (~> 1.2)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
@@ -384,7 +390,7 @@ GEM
|
|||||||
treetop (1.4.15)
|
treetop (1.4.15)
|
||||||
polyglot
|
polyglot
|
||||||
polyglot (>= 0.3.1)
|
polyglot (>= 0.3.1)
|
||||||
turnip (1.2.1)
|
turnip (1.2.2)
|
||||||
gherkin (>= 2.5)
|
gherkin (>= 2.5)
|
||||||
rspec (>= 2.0, < 4.0)
|
rspec (>= 2.0, < 4.0)
|
||||||
tzinfo (1.2.1)
|
tzinfo (1.2.1)
|
||||||
@@ -443,12 +449,15 @@ DEPENDENCIES
|
|||||||
rack-cors
|
rack-cors
|
||||||
rails (= 4.1.4)
|
rails (= 4.1.4)
|
||||||
rqrcode
|
rqrcode
|
||||||
|
rspec-its
|
||||||
rspec-rails
|
rspec-rails
|
||||||
sass-rails (~> 4.0.2)
|
sass-rails (~> 4.0.2)
|
||||||
simple_form
|
simple_form
|
||||||
simplecov
|
simplecov
|
||||||
simply_stored!
|
simply_stored!
|
||||||
slim-rails
|
slim-rails
|
||||||
|
spring
|
||||||
|
spring-commands-rspec
|
||||||
thin
|
thin
|
||||||
turnip
|
turnip
|
||||||
uglifier (>= 1.0.3)
|
uglifier (>= 1.0.3)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
class Supplier
|
class Supplier
|
||||||
include SimplyStored::Couch
|
include SimplyStored::Couch
|
||||||
include ActiveModel::SerializerSupport
|
include ActiveModel::SerializerSupport
|
||||||
|
|
||||||
|
view :by_confirmation_token, key: :confirmation_token # devise confirmable
|
||||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
|
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
|
||||||
property :unconfirmed_email
|
property :unconfirmed_email
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ begin
|
|||||||
load File.expand_path("../spring", __FILE__)
|
load File.expand_path("../spring", __FILE__)
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
||||||
|
|
||||||
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
require_relative '../config/boot'
|
||||||
require 'rails/commands'
|
require 'rails/commands'
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
begin
|
||||||
|
load File.expand_path("../spring", __FILE__)
|
||||||
|
rescue LoadError
|
||||||
|
end
|
||||||
|
require 'bundler/setup'
|
||||||
|
load Gem.bin_path('rspec-core', 'rspec')
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe SupplierController do
|
describe SupplierController, type: :controller do
|
||||||
before :each do
|
before :each do
|
||||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || Supplier.create(name: 'Supplier', email: 'supplier@qwaiter.com', password: 'secret')
|
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || Supplier.create(name: 'Supplier', email: 'supplier@qwaiter.com', password: 'secret')
|
||||||
sign_in @supplier
|
sign_in @supplier
|
||||||
|
|||||||
@@ -1,25 +1,27 @@
|
|||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Suppliers::ListsController do
|
describe Suppliers::ListsController, type: :controller do
|
||||||
before :each do
|
before :each do
|
||||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
|
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
|
||||||
ActionController::Parameters.permit_all_parameters = false
|
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
|
sign_in @supplier
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def valid_attributes
|
||||||
|
{state: 'active'}
|
||||||
|
end
|
||||||
|
|
||||||
|
def invalid_params
|
||||||
|
{foo: 'bar'}
|
||||||
|
end
|
||||||
|
|
||||||
#after :each do
|
#after :each do
|
||||||
#ActionController::Parameters.permit_all_parameters = true
|
#ActionController::Parameters.permit_all_parameters = true
|
||||||
#end
|
#end
|
||||||
|
|
||||||
describe "GET #index" do
|
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
|
it "has pagination options if show_all is given" do
|
||||||
list = create :list, supplier: @supplier
|
list = create :list, supplier: @supplier
|
||||||
get :index, show_all: 'yes'
|
get :index, show_all: 'yes'
|
||||||
@@ -81,32 +83,28 @@ describe Suppliers::ListsController do
|
|||||||
context "with valid attributes" do
|
context "with valid attributes" do
|
||||||
it "creates a new list" do
|
it "creates a new list" do
|
||||||
expect{
|
expect{
|
||||||
post :create, list: attributes_for(:list, supplier: @supplier)
|
post :create, list: valid_attributes
|
||||||
}.to change(List, :count).by(1)
|
}.to change(List, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the new list" do
|
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]
|
response.should redirect_to [:suppliers, List.last]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to create a list for another supplier" do
|
it "should not be possible to create a list for another supplier" do
|
||||||
supplier2 = create :supplier
|
supplier2 = create :supplier
|
||||||
post :create, list: attributes_for(:list, price: '6.66', supplier: supplier2)
|
expect{ post :create, list: valid_attributes.merge(price: '6.66', supplier_id: supplier2.id) }.to raise_error
|
||||||
List.find_by_price(6.66).supplier_id.should == @supplier.id
|
List.find_by_price(6.66).should_not be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with invalid attributes" do
|
context "with invalid attributes" do
|
||||||
it "does not save the new list" do
|
it "does not save the new list" do
|
||||||
expect{
|
expect{
|
||||||
post :create, list: {table_id: ''}
|
post :create, list: invalid_params
|
||||||
}.to_not change(List, :count)
|
}.to raise_error
|
||||||
end
|
List.count.should be_zero
|
||||||
|
|
||||||
it "re-renders the new method" do
|
|
||||||
post :create, list: {table_id: ''}
|
|
||||||
response.should render_template :new
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -118,24 +116,25 @@ describe Suppliers::ListsController do
|
|||||||
|
|
||||||
context "valid attributes" do
|
context "valid attributes" do
|
||||||
it "located the requested list" 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
|
@list.reload
|
||||||
assigns(:list).should eq(@list)
|
assigns(:list).should eq(@list)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "changes @list's attributes" do
|
it "changes @list's price attribute" do
|
||||||
put :update, id: @list, list: attributes_for(:list, price: "7.22", supplier: @supplier)
|
put :update, id: @list, list: valid_attributes.merge(price: '7.22')
|
||||||
@list.reload
|
@list.reload
|
||||||
@list.price.should eq(7.22)
|
@list.price.should eq(7.22)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the updated list" do
|
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]
|
response.should redirect_to [:suppliers, @list]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to update a list to another supplier" do
|
it "should not be possible to update a list to another supplier" do
|
||||||
supplier2 = create :supplier
|
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.reload
|
||||||
@list.supplier_id.should == @supplier.id
|
@list.supplier_id.should == @supplier.id
|
||||||
end
|
end
|
||||||
@@ -149,14 +148,8 @@ describe Suppliers::ListsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "invalid attributes" do
|
context "invalid attributes" do
|
||||||
it "locates the requested list" do
|
it "raises on invalid params" do
|
||||||
put :update, id: @list, list: {table_id: ''}
|
expect{ put :update, id: @list, list: invalid_params }.to raise_error
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -168,7 +161,7 @@ describe Suppliers::ListsController do
|
|||||||
|
|
||||||
it "deletes the list" do
|
it "deletes the list" do
|
||||||
expect{
|
expect{
|
||||||
delete :destroy, id: @list
|
delete :destroy, id: @list
|
||||||
}.to change(List, :count).by(-1)
|
}.to change(List, :count).by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Suppliers::ProductCategoriesController do
|
describe Suppliers::ProductCategoriesController, type: :controller do
|
||||||
before :each do
|
before :each do
|
||||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
|
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
|
||||||
controller.stub(:product_category_params){ controller.params.require(:product_category).permit! } # allow all parameters since cross parameter injection is tested
|
|
||||||
sign_in @supplier
|
sign_in @supplier
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET #index" do
|
def valid_attributes
|
||||||
it "populates an array of product_categories" do
|
{name: 'Lunch'}
|
||||||
product_category = create :product_category, supplier: @supplier
|
end
|
||||||
get :index
|
|
||||||
assigns(:product_categories).should eq([product_category])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
def invalid_attributes
|
||||||
|
{name: ''}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET #index" do
|
||||||
it "does not include product_categories from another supplier" do
|
it "does not include product_categories from another supplier" do
|
||||||
product_category1 = create :product_category, supplier: @supplier
|
product_category1 = create :product_category, supplier: @supplier
|
||||||
product_category2 = create :product_category
|
product_category2 = create :product_category
|
||||||
@@ -26,11 +27,6 @@ describe Suppliers::ProductCategoriesController do
|
|||||||
get :index
|
get :index
|
||||||
expect{ render_template :index }.not_to raise_error
|
expect{ render_template :index }.not_to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders the :index view" do
|
|
||||||
get :index
|
|
||||||
response.should render_template :index
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET #show" do
|
describe "GET #show" do
|
||||||
@@ -45,12 +41,6 @@ describe Suppliers::ProductCategoriesController do
|
|||||||
get :show, id: product_category
|
get :show, id: product_category
|
||||||
response.status.should == 404
|
response.status.should == 404
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders the #show view" do
|
|
||||||
product_category = create :product_category, supplier: @supplier
|
|
||||||
get :show, id: product_category
|
|
||||||
response.should render_template :show
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET #new" do
|
describe "GET #new" do
|
||||||
@@ -58,43 +48,33 @@ describe Suppliers::ProductCategoriesController do
|
|||||||
get :new
|
get :new
|
||||||
assigns(:product_category).should be_a ProductCategory
|
assigns(:product_category).should be_a ProductCategory
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders the #show view" do
|
|
||||||
get :new
|
|
||||||
response.should render_template :new
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "POST #create" do
|
describe "POST #create" do
|
||||||
context "with valid attributes" do
|
context "with valid attributes" do
|
||||||
it "creates a new product_category" do
|
it "creates a new product_category" do
|
||||||
expect{
|
expect{
|
||||||
post :create, product_category: attributes_for(:product_category, supplier: @supplier)
|
post :create, product_category: valid_attributes
|
||||||
}.to change(ProductCategory, :count).by(1)
|
}.to change(ProductCategory, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the new product_category" do
|
it "redirects to the new product_category" do
|
||||||
post :create, product_category: attributes_for(:product_category, supplier: @supplier)
|
post :create, product_category: valid_attributes
|
||||||
response.should redirect_to [:suppliers, :product_categories]
|
response.should redirect_to [:suppliers, :product_categories]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to create a product category for another supplier" do
|
it "should not be possible to create a product category for another supplier" do
|
||||||
supplier2 = create :supplier
|
supplier2 = create :supplier
|
||||||
post :create, product_category: attributes_for(:product_category, name: 'Trying to hack', supplier: supplier2)
|
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').supplier_id.should == @supplier.id
|
ProductCategory.find_by_name('Trying to hack').should_not be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with invalid attributes" do
|
context "with invalid attributes" do
|
||||||
it "does not save the new product_category" do
|
it "does not save the new product_category" do
|
||||||
expect{
|
expect{
|
||||||
post :create, product_category: {name: ''}
|
post :create, product_category: invalid_attributes
|
||||||
}.to_not change(ProductCategory, :count)
|
}.not_to change{ ProductCategory.count }
|
||||||
end
|
|
||||||
|
|
||||||
it "re-renders the new method" do
|
|
||||||
post :create, product_category: {name: ''}
|
|
||||||
response.should render_template :new
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -106,46 +86,33 @@ describe Suppliers::ProductCategoriesController do
|
|||||||
|
|
||||||
context "valid attributes" do
|
context "valid attributes" do
|
||||||
it "located the requested product_category" do
|
it "located the requested product_category" do
|
||||||
put :update, id: @product_category, product_category: attributes_for(:product_category, supplier: @supplier)
|
put :update, id: @product_category, product_category: valid_attributes
|
||||||
@product_category.reload
|
@product_category.reload
|
||||||
assigns(:product_category).should eq(@product_category)
|
assigns(:product_category).should eq(@product_category)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "changes @product_category's attributes" do
|
it "changes @product_category's attributes" do
|
||||||
put :update, id: @product_category, product_category: attributes_for(:product_category, name: "ChangedByTest", supplier: @supplier)
|
put :update, id: @product_category, product_category: valid_attributes.merge(name: "ChangedByTest")
|
||||||
@product_category.reload
|
@product_category.reload
|
||||||
@product_category.name.should eq("ChangedByTest")
|
@product_category.name.should eq("ChangedByTest")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the updated product_category" do
|
|
||||||
put :update, id: @product_category, product_category: attributes_for(:product_category, supplier: @supplier)
|
|
||||||
response.should redirect_to [:suppliers, :product_categories]
|
|
||||||
end
|
|
||||||
it "should not be possible to update a product category to another supplier" do
|
it "should not be possible to update a product category to another supplier" do
|
||||||
supplier2 = create :supplier
|
supplier2 = create :supplier
|
||||||
put :update, id: @product_category, product_category: attributes_for(:product_category, name: "Trying to hack", supplier: supplier2)
|
expect{
|
||||||
ProductCategory.find_by_name('Trying to hack').supplier_id.should == @supplier.id
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to update a product_category of another supplier" do
|
it "should not be possible to update a product_category of another supplier" do
|
||||||
product_category = create :product_category, name: 'Other supplier product_category'
|
product_category = create :product_category, name: 'Other supplier product_category'
|
||||||
put :update, id: product_category, product_category: {name: "Trying to hack"}
|
put :update, id: product_category, product_category: {name: "Trying to hack"}
|
||||||
|
expect(response.status).to eq 404
|
||||||
product_category.reload
|
product_category.reload
|
||||||
product_category.name.should == 'Other supplier product_category'
|
product_category.name.should == 'Other supplier product_category'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "invalid attributes" do
|
|
||||||
it "locates the requested product_category" do
|
|
||||||
put :update, id: @product_category, product_category: {name: ''}
|
|
||||||
assigns(:product_category).should eq(@product_category)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "re-renders the edit method" do
|
|
||||||
put :update, id: @product_category, product_category: {name: ''}
|
|
||||||
response.should render_template :edit
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE destroy' do
|
describe 'DELETE destroy' do
|
||||||
@@ -155,20 +122,15 @@ describe Suppliers::ProductCategoriesController do
|
|||||||
|
|
||||||
it "deletes the product_category" do
|
it "deletes the product_category" do
|
||||||
expect{
|
expect{
|
||||||
delete :destroy, id: @product_category
|
delete :destroy, id: @product_category
|
||||||
}.to change(ProductCategory, :count).by(-1)
|
}.to change(ProductCategory, :count).by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to product_categories#index" do
|
|
||||||
delete :destroy, id: @product_category
|
|
||||||
response.should redirect_to [:suppliers, :product_categories]
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should not be possible to delete a product category of another supplier" do
|
it "should not be possible to delete a product category of another supplier" do
|
||||||
product_category = create :product_category
|
product_category = create :product_category
|
||||||
expect{
|
expect{
|
||||||
delete :destroy, id: product_category
|
delete :destroy, id: product_category
|
||||||
}.to_not change(ProductCategory, :count)
|
}.to_not change{ProductCategory.count }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Suppliers::ProductsController do
|
describe Suppliers::ProductsController, type: :controller do
|
||||||
|
def valid_attributes
|
||||||
|
{name: 'Lemon cake', price: '4.2'}
|
||||||
|
end
|
||||||
|
|
||||||
|
def invalid_attributes
|
||||||
|
{name: ''}
|
||||||
|
end
|
||||||
|
|
||||||
before :each do
|
before :each do
|
||||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
|
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
|
||||||
controller.stub(:product_params){ controller.params.require(:product).permit! } # allow all parameters since cross parameter injection is tested
|
|
||||||
sign_in @supplier
|
sign_in @supplier
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET #index" do
|
describe "GET #index" do
|
||||||
it "populates an array of products" do
|
|
||||||
product = create :product, supplier: @supplier
|
|
||||||
get :index
|
|
||||||
assigns(:products).should eq([product])
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not include products from another supplier" do
|
it "does not include products from another supplier" do
|
||||||
product1 = create :product, supplier: @supplier
|
product1 = create :product, supplier: @supplier
|
||||||
product2 = create :product
|
product2 = create :product
|
||||||
@@ -26,11 +27,6 @@ describe Suppliers::ProductsController do
|
|||||||
get :index
|
get :index
|
||||||
expect{ render_template :index }.not_to raise_error
|
expect{ render_template :index }.not_to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders the :index view" do
|
|
||||||
get :index
|
|
||||||
response.should render_template :index
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET #show" do
|
describe "GET #show" do
|
||||||
@@ -43,22 +39,11 @@ describe Suppliers::ProductsController do
|
|||||||
it "should not display a product of another supplier" do
|
it "should not display a product of another supplier" do
|
||||||
product = create :product
|
product = create :product
|
||||||
get :show, id: product
|
get :show, id: product
|
||||||
response.status.should == 404
|
expect(response.status).to eq 404
|
||||||
end
|
|
||||||
|
|
||||||
it "renders the #show view" do
|
|
||||||
product = create :product, supplier: @supplier
|
|
||||||
get :show, id: product
|
|
||||||
response.should render_template :show
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET #new" do
|
describe "GET #new" do
|
||||||
it "assigns a new product to @product" do
|
|
||||||
get :new
|
|
||||||
assigns(:product).should be_a Product
|
|
||||||
end
|
|
||||||
|
|
||||||
it "renders the #show view" do
|
it "renders the #show view" do
|
||||||
get :new
|
get :new
|
||||||
response.should render_template :new
|
response.should render_template :new
|
||||||
@@ -69,31 +54,31 @@ describe Suppliers::ProductsController do
|
|||||||
context "with valid attributes" do
|
context "with valid attributes" do
|
||||||
it "creates a new product" do
|
it "creates a new product" do
|
||||||
expect{
|
expect{
|
||||||
post :create, product: attributes_for(:product, supplier: @supplier)
|
post :create, product: valid_attributes
|
||||||
}.to change(Product, :count).by(1)
|
}.to change(Product, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the new product" do
|
it "redirects to the new product" do
|
||||||
post :create, product: attributes_for(:product, supplier: @supplier)
|
post :create, product: valid_attributes
|
||||||
response.should redirect_to [:suppliers, :products]
|
response.should redirect_to [:suppliers, :products]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to create a product for another supplier" do
|
it "should not be possible to create a product for another supplier" do
|
||||||
supplier2 = create :supplier
|
supplier2 = create :supplier
|
||||||
post :create, product: attributes_for(:product, name: 'Trying to hack', supplier: supplier2)
|
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').supplier_id.should == @supplier.id
|
Product.find_by_name('Trying to hack').should_not be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with invalid attributes" do
|
context "with invalid attributes" do
|
||||||
it "does not save the new product" do
|
it "does not save the new product" do
|
||||||
expect{
|
expect{
|
||||||
post :create, product: {name: ''}
|
post :create, product: invalid_attributes
|
||||||
}.to_not change(Product, :count)
|
}.to_not change(Product, :count)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "re-renders the new method" do
|
it "re-renders the new method" do
|
||||||
post :create, product: {name: ''}
|
post :create, product: invalid_attributes
|
||||||
response.should render_template :new
|
response.should render_template :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -106,25 +91,21 @@ describe Suppliers::ProductsController do
|
|||||||
|
|
||||||
context "valid attributes" do
|
context "valid attributes" do
|
||||||
it "located the requested product" do
|
it "located the requested product" do
|
||||||
put :update, id: @product, product: attributes_for(:product, supplier: @supplier)
|
put :update, id: @product, product: valid_attributes
|
||||||
@product.reload
|
@product.reload
|
||||||
assigns(:product).should eq(@product)
|
assigns(:product).should eq(@product)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "changes @product's attributes" do
|
it "changes @product's attributes" do
|
||||||
put :update, id: @product, product: attributes_for(:product, name: "ChangedByTest", supplier: @supplier)
|
put :update, id: @product, product: valid_attributes.merge(name: "ChangedByTest")
|
||||||
@product.reload
|
@product.reload
|
||||||
@product.name.should eq("ChangedByTest")
|
@product.name.should eq("ChangedByTest")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the updated product" do
|
|
||||||
put :update, id: @product, product: attributes_for(:product, supplier: @supplier)
|
|
||||||
response.should redirect_to [:suppliers, :products]
|
|
||||||
end
|
|
||||||
it "should not be possible to update a product to another supplier" do
|
it "should not be possible to update a product to another supplier" do
|
||||||
supplier2 = create :supplier
|
supplier2 = create :supplier
|
||||||
put :update, id: @product, product: attributes_for(:product, name: "Trying to hack", supplier: supplier2)
|
expect{ put :update, id: @product, product: valid_attributes.merge(name: "Trying to hack", supplier_id: supplier2.id) }.to raise_error
|
||||||
Product.find_by_name('Trying to hack').supplier_id.should == @supplier.id
|
expect( Product.find_by_name 'Trying to hack' ).not_to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to update a product of another supplier" do
|
it "should not be possible to update a product of another supplier" do
|
||||||
@@ -137,12 +118,12 @@ describe Suppliers::ProductsController do
|
|||||||
|
|
||||||
context "invalid attributes" do
|
context "invalid attributes" do
|
||||||
it "locates the requested product" do
|
it "locates the requested product" do
|
||||||
put :update, id: @product, product: {name: ''}
|
put :update, id: @product, product: invalid_attributes
|
||||||
assigns(:product).should eq(@product)
|
assigns(:product).should eq(@product)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "re-renders the edit method" do
|
it "re-renders the edit method" do
|
||||||
put :update, id: @product, product: {name: ''}
|
put :update, id: @product, product: invalid_attributes
|
||||||
response.should render_template :edit
|
response.should render_template :edit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Suppliers::SectionsController do
|
describe Suppliers::SectionsController, type: :controller do
|
||||||
before :each do
|
before :each do
|
||||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
|
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
|
||||||
controller.stub(:section_params){ controller.params.require(:section).permit! } # allow all parameters since cross parameter injection is tested
|
|
||||||
sign_in @supplier
|
sign_in @supplier
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET #index" do
|
def valid_attributes
|
||||||
it "populates an array of sections" do
|
{title: 'Terrace'}
|
||||||
base_section = @supplier.sections.first
|
end
|
||||||
section = create :section, supplier: @supplier
|
|
||||||
get :index
|
|
||||||
assigns(:sections).should =~[base_section, section].compact
|
|
||||||
end
|
|
||||||
|
|
||||||
|
def invalid_attributes
|
||||||
|
{title: ''}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET #index" do
|
||||||
it "does not include sections from another supplier" do
|
it "does not include sections from another supplier" do
|
||||||
base_section = @supplier.sections.first
|
base_section = @supplier.sections.first
|
||||||
section1 = create :section, supplier: @supplier
|
section1 = create :section, supplier: @supplier
|
||||||
section2 = create :section
|
section2 = create :section
|
||||||
get :index
|
get :index
|
||||||
assigns(:sections).should =~[base_section, section1].compact
|
assigns(:sections).map(&:id).sort.should == [base_section.id, section1.id].sort
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should render without errors when no objects are present" do
|
it "should render without errors when no objects are present" do
|
||||||
@@ -71,31 +71,31 @@ describe Suppliers::SectionsController do
|
|||||||
context "with valid attributes" do
|
context "with valid attributes" do
|
||||||
it "creates a new section" do
|
it "creates a new section" do
|
||||||
expect{
|
expect{
|
||||||
post :create, section: attributes_for(:section, supplier: @supplier)
|
post :create, section: valid_attributes
|
||||||
}.to change(Section, :count).by(2)
|
}.to change(Section, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the new section" do
|
it "redirects to the new section" do
|
||||||
post :create, section: attributes_for(:section, title: 'Created section 45', supplier: @supplier)
|
post :create, section: valid_attributes.merge(title: 'Created section 45')
|
||||||
response.should redirect_to [:suppliers, Section.find_by_title('Created section 45')]
|
response.should redirect_to [:suppliers, Section.find_by_title('Created section 45')]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to create a section for another supplier" do
|
it "should not be possible to create a section for another supplier" do
|
||||||
supplier2 = create :supplier
|
supplier2 = create :supplier
|
||||||
post :create, section: attributes_for(:section, title: 'Trying to hack', supplier: supplier2)
|
expect{ post :create, section: valid_attributes.merge(title: 'Trying to hack', supplier_id: supplier2.id) }.to raise_error
|
||||||
Section.find_by_title('Trying to hack').supplier_id.should == @supplier.id
|
expect( Section.find_by_title 'Trying to hack' ).not_to be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with invalid attributes" do
|
context "with invalid attributes" do
|
||||||
it "does not save the new section" do
|
it "does not save the new section" do
|
||||||
expect{
|
expect{
|
||||||
post :create, section: {title: ''}
|
post :create, section: invalid_attributes
|
||||||
}.to_not change(Section, :count)
|
}.to_not change(Section, :count)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "re-renders the new method" do
|
it "re-renders the new method" do
|
||||||
post :create, section: {title: ''}
|
post :create, section: invalid_attributes
|
||||||
response.should render_template :new
|
response.should render_template :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -108,25 +108,27 @@ describe Suppliers::SectionsController do
|
|||||||
|
|
||||||
context "valid attributes" do
|
context "valid attributes" do
|
||||||
it "located the requested section" do
|
it "located the requested section" do
|
||||||
put :update, id: @section, section: attributes_for(:section, supplier: @supplier)
|
put :update, id: @section, section: valid_attributes
|
||||||
@section.reload
|
@section.reload
|
||||||
assigns(:section).should eq(@section)
|
assigns(:section).should eq(@section)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "changes @section's attributes" do
|
it "changes @section's attributes" do
|
||||||
put :update, id: @section, section: attributes_for(:section, title: "ChangedByTest", supplier: @supplier)
|
put :update, id: @section, section: valid_attributes.merge(title: "ChangedByTest")
|
||||||
@section.reload
|
@section.reload
|
||||||
@section.title.should eq("ChangedByTest")
|
expect( @section.title ).to eq "ChangedByTest"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the updated section" do
|
it "redirects to the updated section" do
|
||||||
put :update, id: @section, section: attributes_for(:section, supplier: @supplier)
|
put :update, id: @section, section: valid_attributes
|
||||||
response.should redirect_to [:suppliers, @section]
|
response.should redirect_to [:suppliers, @section]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to update a section to another supplier" do
|
it "should not be possible to update a section to another supplier" do
|
||||||
supplier2 = create :supplier
|
supplier2 = create :supplier
|
||||||
put :update, id: @section, section: attributes_for(:section, title: "Trying to hack", supplier: supplier2)
|
expect{ put :update, id: @section, section: valid_attributes.merge(title: "Trying to hack", supplier_id: supplier2.id) }.to raise_error
|
||||||
Section.find_by_title('Trying to hack').supplier_id.should == @supplier.id
|
@section.reload
|
||||||
|
@section.supplier_id.should == @supplier.id
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to update a section of another supplier" do
|
it "should not be possible to update a section of another supplier" do
|
||||||
@@ -139,12 +141,12 @@ describe Suppliers::SectionsController do
|
|||||||
|
|
||||||
context "invalid attributes" do
|
context "invalid attributes" do
|
||||||
it "locates the requested section" do
|
it "locates the requested section" do
|
||||||
put :update, id: @section, section: {title: ''}
|
put :update, id: @section, section: invalid_attributes
|
||||||
assigns(:section).should eq(@section)
|
assigns(:section).should eq(@section)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "re-renders the edit method" do
|
it "re-renders the edit method" do
|
||||||
put :update, id: @section, section: {title: ''}
|
put :update, id: @section, section: invalid_attributes
|
||||||
response.should render_template :edit
|
response.should render_template :edit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Suppliers::TablesController do
|
describe Suppliers::TablesController, type: :controller do
|
||||||
before :each do
|
before :each do
|
||||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || create(:supplier, :confirmed)
|
@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
|
sign_in @supplier
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -69,19 +69,19 @@ describe Suppliers::TablesController do
|
|||||||
context "with valid attributes" do
|
context "with valid attributes" do
|
||||||
it "creates a new table" do
|
it "creates a new table" do
|
||||||
expect{
|
expect{
|
||||||
post :create, table: attributes_for(:table, supplier: @supplier)
|
post :create, table: {number: 22}
|
||||||
}.to change(Table, :count).by(1)
|
}.to change(Table, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the new table" do
|
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]
|
response.should redirect_to [:suppliers, Table.last]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to create a table for another supplier" do
|
it "should not be possible to create a table for another supplier" do
|
||||||
supplier2 = create :supplier
|
supplier2 = create :supplier
|
||||||
post :create, table: attributes_for(:table, number: 6, supplier: supplier2)
|
expect { post :create, table: {number: 6, supplier_id: supplier2.id} }.to raise_error
|
||||||
Table.find_by_number(6).supplier_id.should == @supplier.id
|
Table.find_by_number(6).should_not be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -106,25 +106,29 @@ describe Suppliers::TablesController do
|
|||||||
|
|
||||||
context "valid attributes" do
|
context "valid attributes" do
|
||||||
it "located the requested table" 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
|
@table.reload
|
||||||
assigns(:table).should eq(@table)
|
assigns(:table).should eq(@table)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "changes @table's attributes" do
|
it "changes @table's number attribute" do
|
||||||
put :update, id: @table, table: attributes_for(:table, number: "14", supplier: @supplier)
|
put :update, id: @table, table: {number: "14"}
|
||||||
@table.reload
|
@table.reload
|
||||||
@table.number.should eq(14)
|
@table.number.should eq(14)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the updated table" do
|
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]
|
response.should redirect_to [:suppliers, @table]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to update a table to another supplier" do
|
it "should not be possible to update a table to another supplier" do
|
||||||
supplier2 = create :supplier
|
supplier2 = create :supplier
|
||||||
put :update, id: @table, table: attributes_for(:table, number: 6, supplier: supplier2)
|
expect{
|
||||||
Table.find_by_number(6).supplier_id.should == @supplier.id
|
put :update, id: @table.id, table: {number: 6, supplier_id: supplier2.id}
|
||||||
|
}.to raise_error
|
||||||
|
@table.reload
|
||||||
|
@table.supplier_id.should == @supplier.id
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be possible to update a table of another supplier" do
|
it "should not be possible to update a table of another supplier" do
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ module Matchers
|
|||||||
def failure_message
|
def failure_message
|
||||||
"supplier #{@supplier_id} did not receive broadcast #{@message} with #{@target_object.inspect} #{@failure_debug_content}"
|
"supplier #{@supplier_id} did not receive broadcast #{@message} with #{@target_object.inspect} #{@failure_debug_content}"
|
||||||
end
|
end
|
||||||
|
def supports_block_expectations?; true; end
|
||||||
end
|
end
|
||||||
|
|
||||||
def broadcast_to_supplier(*args, &block)
|
def broadcast_to_supplier(*args, &block)
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ module Matchers
|
|||||||
def failure_message
|
def failure_message
|
||||||
"user #{@user_id} did not receive broadcast #{@message} with #{@target_object.inspect} #{@failure_debug_content}"
|
"user #{@user_id} did not receive broadcast #{@message} with #{@target_object.inspect} #{@failure_debug_content}"
|
||||||
end
|
end
|
||||||
|
def supports_block_expectations?; true; end
|
||||||
end
|
end
|
||||||
|
|
||||||
def broadcast_to_user(*args, &block)
|
def broadcast_to_user(*args, &block)
|
||||||
|
|||||||
Reference in New Issue
Block a user