big refactor for test and admin namespace

This commit is contained in:
2012-12-04 18:45:18 +01:00
parent 7d64ab2022
commit d8eef4a047
85 changed files with 1403 additions and 1272 deletions
@@ -1,21 +0,0 @@
require 'acceptance/acceptance_helper'
feature 'Supplier main board spec.rb', %q{
In order to manage active orders
As a supplier
I want to have control
} do
background do
create_supplier 'supplier@qwaiter.com'
create_user 'user@qwaiter.com'
end
def create_active_list(options = {})
end
scenario 'loaded orders should have a list_id present for handling actions' do
create_active_list
login_supplier_as 'supplier@qwaiter.com'
end
end
@@ -0,0 +1,46 @@
require 'acceptance/acceptance_helper'
@javascript
feature 'Supplier main board spec.rb', %q{
In order to manage active orders
As a supplier
I want to have control
} do
background do
CouchPotato.couchrest_database.recreate!
create_supplier 'supplier@qwaiter.com'
create_user 'user@qwaiter.com'
end
def create_active_list(options = {})
@table = create :table, supplier: @supplier
@list = create :list, supplier: @supplier, table: @table, user_ids: [@user.id]
end
context "using javascript", js: true do
scenario 'the active list should be present and contained in row having its id' do
create_active_list
login_supplier_as 'supplier@qwaiter.com'
visit '/supplier'
page.should have_selector "#list-row-#{@list.id}"
end
scenario 'order is added to the list before visiting the page' do
create_active_list
login_supplier_as 'supplier@qwaiter.com'
product = create :product, supplier: @supplier
sleep 0.1
@list.place_order @user, {product.id => 369}
visit '/supplier'
page.should have_selector ".of-list-#{@list.id}"
end
scenario 'order is added to the list after visiting the page' do
create_active_list
login_supplier_as 'supplier@qwaiter.com'
product = create :product, supplier: @supplier
visit '/supplier'
@list.place_order @user, {product.id => 369}
page.should have_selector ".of-list-#{@list.id}"
end
end
end
@@ -0,0 +1,108 @@
# encoding: UTF-8
require 'spec_helper'
describe Admin::ProductsController do
before :each do
@administrator = Administrator.find_by_email('administrator@qwaiter.com') || Administrator.create(email: 'administrator@qwaiter.com', password: 'secret')
sign_in @administrator
end
describe "GET #index" do
it "populates an array of products" do
product = create :product
get :index
assigns(:products).should eq([product])
end
it "should render without errors when no objects are present" do
get :index
expect{ render_template :index }.not_to raise_error
end
it "renders the :index view" do
get :index
response.should render_template :index
end
end
describe "GET #show" do
it "assigns the requested product to @product" do
product = create :product
get :show, id: product
assigns(:product).should eq(product)
end
it "renders the #show view" do
product = create :product
get :show, id: product
response.should render_template :show
end
end
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
get :new
response.should render_template :new
end
end
describe "POST #create" do
context "with valid attributes" do
it "creates a new product" do
expect{
post :create, product: attributes_for(:product)
}.to change(Product, :count).by(1)
end
it "redirects to the new product" do
post :create, product: attributes_for(:product)
response.should redirect_to [:admin, Product.last]
end
end
context "with invalid attributes" do
it "does not save the new product" do
expect{
post :create, product: {}
}.to_not change(Product, :count)
end
it "re-renders the new method" do
post :create, product: {}
response.should render_template :new
end
end
end
describe 'PUT update' do
before :each do
@product = create :product
end
context "valid attributes" do
it "located the requested product" do
put :update, id: @product, product: attributes_for(:product)
assigns(:product).should eq(@product)
end
it "changes @product's attributes" do
attributes = attributes_for(:product)
attribute_to_change = attributes.keys.find{|k| k !~ /_id$/}
attributes[attribute_to_change] = "ChangedByTest"
put :update, id: @product, product: attributes
@product.reload
@product.send(attribute_to_change).should eq("ChangedByTest")
end
it "redirects to the updated product" do
put :update, id: @product, product: attributes_for(:product)
response.should redirect_to [:admin, @product]
end
end
end
end
-164
View File
@@ -1,164 +0,0 @@
require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe UsersController do
# This should return the minimal set of attributes required to create a valid
# User. As you add validations to User, be sure to
# update the return value of this method accordingly.
def valid_attributes
{}
end
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# UsersController. Be sure to keep this updated too.
def valid_session
{}
end
describe "GET index" do
it "assigns all users as @users" do
user = User.create! valid_attributes
get :index, {}, valid_session
assigns(:users).should eq([user])
end
end
describe "GET show" do
it "assigns the requested user as @user" do
user = User.create! valid_attributes
get :show, {:id => user.to_param}, valid_session
assigns(:user).should eq(user)
end
end
describe "GET new" do
it "assigns a new user as @user" do
get :new, {}, valid_session
assigns(:user).should be_a_new(User)
end
end
describe "GET edit" do
it "assigns the requested user as @user" do
user = User.create! valid_attributes
get :edit, {:id => user.to_param}, valid_session
assigns(:user).should eq(user)
end
end
describe "POST create" do
describe "with valid params" do
it "creates a new User" do
expect {
post :create, {:user => valid_attributes}, valid_session
}.to change(User, :count).by(1)
end
it "assigns a newly created user as @user" do
post :create, {:user => valid_attributes}, valid_session
assigns(:user).should be_a(User)
assigns(:user).should be_persisted
end
it "redirects to the created user" do
post :create, {:user => valid_attributes}, valid_session
response.should redirect_to(User.last)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved user as @user" do
# Trigger the behavior that occurs when invalid params are submitted
User.any_instance.stub(:save).and_return(false)
post :create, {:user => {}}, valid_session
assigns(:user).should be_a_new(User)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
User.any_instance.stub(:save).and_return(false)
post :create, {:user => {}}, valid_session
response.should render_template("new")
end
end
end
describe "PUT update" do
describe "with valid params" do
it "updates the requested user" do
user = User.create! valid_attributes
# Assuming there are no other users in the database, this
# specifies that the User created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
User.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
put :update, {:id => user.to_param, :user => {'these' => 'params'}}, valid_session
end
it "assigns the requested user as @user" do
user = User.create! valid_attributes
put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
assigns(:user).should eq(user)
end
it "redirects to the user" do
user = User.create! valid_attributes
put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
response.should redirect_to(user)
end
end
describe "with invalid params" do
it "assigns the user as @user" do
user = User.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
User.any_instance.stub(:save).and_return(false)
put :update, {:id => user.to_param, :user => {}}, valid_session
assigns(:user).should eq(user)
end
it "re-renders the 'edit' template" do
user = User.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
User.any_instance.stub(:save).and_return(false)
put :update, {:id => user.to_param, :user => {}}, valid_session
response.should render_template("edit")
end
end
end
describe "DELETE destroy" do
it "destroys the requested user" do
user = User.create! valid_attributes
expect {
delete :destroy, {:id => user.to_param}, valid_session
}.to change(User, :count).by(-1)
end
it "redirects to the users list" do
user = User.create! valid_attributes
delete :destroy, {:id => user.to_param}, valid_session
response.should redirect_to(users_url)
end
end
end
+6
View File
@@ -0,0 +1,6 @@
FactoryGirl.define do
factory :product do
price 34.95
association :supplier
end
end
-11
View File
@@ -1,11 +0,0 @@
require 'spec_helper'
describe "Users" do
describe "GET /users" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get users_path
response.status.should be(200)
end
end
end
+43
View File
@@ -0,0 +1,43 @@
require "spec_helper"
describe SupplierController do
describe "routing" do
it "routes root to #home" do
get("/supplier").should route_to("supplier#home")
end
it "routes to #active_orders" do
get("/supplier/active_orders").should route_to("supplier#active_orders")
end
it "routes to #active_lists" do
get("/supplier/active_lists").should route_to("supplier#active_lists")
end
it "routes to #close_list" do
post("/supplier/close_list").should route_to("supplier#close_list")
end
it "routes to #mark_list_as_helped" do
post("/supplier/mark_list_as_helped").should route_to("supplier#mark_list_as_helped")
end
it "routes to #mark_order_in_process" do
post("/supplier/mark_order_in_process").should route_to("supplier#mark_order_in_process")
end
it "routes to #order_is_delivered" do
post("/supplier/order_is_delivered").should route_to("supplier#order_is_delivered")
end
it "routes to #mark_as_open" do
post("/supplier/mark_as_open").should route_to("supplier#mark_as_open")
end
it "routes to #mark_as_closed" do
post("/supplier/mark_as_closed").should route_to("supplier#mark_as_closed")
end
it "routes to #settings" do
get("/supplier/settings").should route_to("supplier#edit")
end
it "routes to #update via put" do
put("/supplier/settings").should route_to("supplier#update")
end
it "routes to #update via post" do
post("/supplier/settings").should route_to("supplier#update")
end
end
end
+72
View File
@@ -0,0 +1,72 @@
require "spec_helper"
describe UserController do
describe "routing" do
it "routes root to #home" do
get("/user").should route_to("user#home")
end
it "routes to #home" do
get("/user/home").should route_to("user#home")
end
it "routes to #active_list" do
get("/user/active_list").should route_to("user#active_list")
end
it "routes to #list_info" do
get("/user/list_info").should route_to("user#list_info")
end
it "routes to #needs_help" do
post("/user/needs_help").should route_to("user#needs_help")
end
it "routes to #list_needs_payment" do
post("/user/list_needs_payment").should route_to("user#list_needs_payment")
end
it "routes to #create_list" do
post("/user/create_list").should route_to("user#create_list")
end
it "routes to #list_products" do
get("/user/list_products").should route_to("user#list_products")
end
it "routes to #list_products_for_table" do
get("/user/list_products_for_table").should route_to("user#list_products_for_table")
end
it "routes to #list_history" do
get("/user/list_history").should route_to("user#list_history")
end
it "routes to #history_list" do
get("/user/history_list").should route_to("user#history_list")
end
it "routes to #home" do
get("/user/home").should route_to("user#home")
end
it "routes to #order_selected_products" do
post("/user/order_selected_products").should route_to("user#order_selected_products")
end
it "routes to #move_table" do
post("/user/move_table").should route_to("user#move_table")
end
it "routes to #table_info" do
get("/user/table_info").should route_to("user#table_info")
end
it "routes to #join_occupied_table" do
get("/user/join_occupied_table").should route_to("user#join_occupied_table")
end
it "routes to #join_occupied_table" do
post("/user/join_occupied_table").should route_to("user#request_to_join_occupied_table")
end
it "routes to #reject_join_request" do
post("/user/reject_join_request").should route_to("user#reject_join_request")
end
it "routes to #approve_join_request" do
post("/user/approve_join_request").should route_to("user#approve_join_request")
end
it "routes to #check_table_join_status" do
post("/user/check_table_join_status").should route_to("user#check_table_join_status")
end
it "routes to #obtain_token" do
get("/user/obtain_token").should route_to("user#obtain_token")
end
end
end
-35
View File
@@ -1,35 +0,0 @@
require "spec_helper"
describe UsersController do
describe "routing" do
it "routes to #index" do
get("/users").should route_to("users#index")
end
it "routes to #new" do
get("/users/new").should route_to("users#new")
end
it "routes to #show" do
get("/users/1").should route_to("users#show", :id => "1")
end
it "routes to #edit" do
get("/users/1/edit").should route_to("users#edit", :id => "1")
end
it "routes to #create" do
post("/users").should route_to("users#create")
end
it "routes to #update" do
put("/users/1").should route_to("users#update", :id => "1")
end
it "routes to #destroy" do
delete("/users/1").should route_to("users#destroy", :id => "1")
end
end
end
+10 -1
View File
@@ -11,7 +11,14 @@ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
I18n.locale = :en
Devise.stretches = 1
Capybara.default_driver = :selenium
Capybara.javascript_driver = :selenium
#Capybara.default_driver = :selenium
module FactoryAttributesFor
def attributes_for(obj, options={})
super(obj, options).merge(build(obj).attributes.select{|k,v| k =~ /_id$/}).symbolize_keys
end
end
RSpec.configure do |config|
# == Mock Framework
#
@@ -22,6 +29,7 @@ RSpec.configure do |config|
# config.mock_with :rr
config.mock_with :rspec
config.include FactoryGirl::Syntax::Methods
config.include FactoryAttributesFor
config.include Devise::TestHelpers, :type => :controller
config.include EndWithMatcher
#config.use_transactional_fixtures = true
@@ -30,6 +38,7 @@ RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
config.fail_fast = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
-15
View File
@@ -1,15 +0,0 @@
require 'spec_helper'
describe "users/edit" do
before(:each) do
@user = assign(:user, stub_model(User))
end
it "renders the edit user form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => users_path(@user), :method => "post" do
end
end
end
-15
View File
@@ -1,15 +0,0 @@
require 'spec_helper'
describe "users/index" do
before(:each) do
assign(:users, [
stub_model(User),
stub_model(User)
])
end
it "renders a list of users" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
end
end
-15
View File
@@ -1,15 +0,0 @@
require 'spec_helper'
describe "users/new" do
before(:each) do
assign(:user, stub_model(User).as_new_record)
end
it "renders new user form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => users_path, :method => "post" do
end
end
end
-12
View File
@@ -1,12 +0,0 @@
require 'spec_helper'
describe "users/show" do
before(:each) do
@user = assign(:user, stub_model(User))
end
it "renders attributes in <p>" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
end
end