From 59a0c4666126b4d2b13a14aa62c7358692b6d0b4 Mon Sep 17 00:00:00 2001 From: tkawa Date: Wed, 4 Apr 2012 20:26:34 +0900 Subject: [PATCH] add integration tests for a child category --- spec/factories.rb | 6 ++++++ spec/integration/admin/categories_spec.rb | 16 ++++++++++++++++ spec/integration/app_spec.rb | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/spec/factories.rb b/spec/factories.rb index 89587410..80be1560 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/integration/admin/categories_spec.rb b/spec/integration/admin/categories_spec.rb index 4dd95582..5e452376 100644 --- a/spec/integration/admin/categories_spec.rb +++ b/spec/integration/admin/categories_spec.rb @@ -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 } diff --git a/spec/integration/app_spec.rb b/spec/integration/app_spec.rb index 725434f8..6ba6330d 100644 --- a/spec/integration/app_spec.rb +++ b/spec/integration/app_spec.rb @@ -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)