Permalink
Browse files

add integration tests for a child category

  • Loading branch information...
1 parent aae2e52 commit 59a0c4666126b4d2b13a14aa62c7358692b6d0b4 @tkawa tkawa committed Apr 4, 2012
Showing with 43 additions and 0 deletions.
  1. +6 −0 spec/factories.rb
  2. +16 −0 spec/integration/admin/categories_spec.rb
  3. +21 −0 spec/integration/app_spec.rb
View
@@ -123,6 +123,12 @@
updated_at update_time
end
+ factory :category_child, :parent => :category do
+ title 'Test Child Category'
+ created_at create_time
+ updated_at update_time
+ end
+
factory :tag do
sequence(:name){|n| "sample-tag-#{n}" }
end
@@ -55,6 +55,22 @@
end
end
+ context 'when a child category exists' do
+ context 'POST /admin/categories' do
+ it 'should create a new child category' do
+ sample = { :title => 'Child Category',
+ :description => 'This is created in spec',
+ :slug => 'child-category',
+ :parent_id => @category.id }
+ post '/admin/categories', { :category => sample }
+ last_response.should be_redirect
+ child = Category('child-category')
+ child.should_not be_nil
+ child.parent.should == @category
+ end
+ end
+ end
+
context 'when the category does not exist' do
before { Category.destroy }
@@ -68,6 +68,27 @@
end
end
+ context '/category/:id/' do
+ before do
+ @category = Factory(:category)
+ @category_child = Factory(:category_child, :parent => @category)
+ end
+
+ after do
+ Category.destroy
+ end
+
+ it "should show category index" do
+ get "/category/#{@category.id}/"
+ last_response.body.should match('Test Site')
+ end
+
+ it "should show child category index" do
+ get "/category/#{@category.id}/#{@category_child.id}/"
+ last_response.body.should match('Test Site')
+ end
+ end
+
describe 'a draft post' do
before do
Factory(:draft_post_with_tag_and_category)

0 comments on commit 59a0c46

Please sign in to comment.