Skip to content

Commit

Permalink
add integration tests for a child category
Browse files Browse the repository at this point in the history
  • Loading branch information
tkawa committed Apr 4, 2012
1 parent aae2e52 commit 59a0c46
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/factories.rb
Expand Up @@ -123,6 +123,12 @@
updated_at update_time updated_at update_time
end end


factory :category_child, :parent => :category do
title 'Test Child Category'
created_at create_time
updated_at update_time
end

factory :tag do factory :tag do
sequence(:name){|n| "sample-tag-#{n}" } sequence(:name){|n| "sample-tag-#{n}" }
end end
Expand Down
16 changes: 16 additions & 0 deletions spec/integration/admin/categories_spec.rb
Expand Up @@ -55,6 +55,22 @@
end end
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 context 'when the category does not exist' do
before { Category.destroy } before { Category.destroy }


Expand Down
21 changes: 21 additions & 0 deletions spec/integration/app_spec.rb
Expand Up @@ -68,6 +68,27 @@
end end
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 describe 'a draft post' do
before do before do
Factory(:draft_post_with_tag_and_category) Factory(:draft_post_with_tag_and_category)
Expand Down

0 comments on commit 59a0c46

Please sign in to comment.