Skip to content

Instantly share code, notes, and snippets.

@dangalipo
Created April 20, 2011 08:40
Show Gist options
  • Save dangalipo/930751 to your computer and use it in GitHub Desktop.
Save dangalipo/930751 to your computer and use it in GitHub Desktop.
Testing
before :each do
login_as_admin!
end
before :all do
@search_tree_a = SearchTree.make!
@search_tree_b = SearchTree.make!
@search_tree_c = SearchTree.make!
@product_type = ProductType.make!
@search_tree_a.children << @search_tree_b
@search_tree_a.save
@search_tree_b.product_type = @product_type
@search_tree_b.save
end
after :all do
[@search_tree_a, @search_tree_b, @product_type].each do |obj|
obj.destroy
end
end
context 'as json' do
context 'with product type id' do
before :each do
get :index, :product_type_id => @product_type.id, :format => :json
end
it 'should respond with an array of search trees' do
assigns(:search_trees).include?(@search_tree_a).should be_false
assigns(:search_trees).include?(@search_tree_b).should be_true
assigns(:search_trees).include?(@search_tree_c).should be_false
end
it 'should return success' do
response.should be_success
end
end
context 'without product type id' do
before :each do
get :index, :format => :json
end
it 'should respond with an array of search trees' do
assigns(:search_trees).include?(@search_tree_a).should be_false
assigns(:search_trees).include?(@search_tree_b).should be_true
assigns(:search_trees).include?(@search_tree_c).should be_true
end
it 'should return success' do
response.should be_success
end
end
end
context 'as html' do
end
before :each do
get :index
end
it 'should respond with an array of search trees' do
assigns(:search_trees).include?(@search_tree_a).should be_true
assigns(:search_trees).include?(@search_tree_b).should be_false
assigns(:search_trees).include?(@search_tree_c).should be_true
end
it 'should return success' do
response.should be_success
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment