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
@@ -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