Skip to content

Commit

Permalink
Implement controller spec
Browse files Browse the repository at this point in the history
  • Loading branch information
kwgch committed Aug 27, 2014
1 parent 115b75c commit 7d0dfd2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Gemfile
Expand Up @@ -53,4 +53,9 @@ group :development, :test do
gem 'spring-commands-rspec'
end

gem "better_errors", group: :development
gem "better_errors", group: :development

group :test do
gem 'factory_girl_rails'
gem 'faker'
end
9 changes: 9 additions & 0 deletions Gemfile.lock
Expand Up @@ -47,6 +47,13 @@ GEM
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.2.1)
factory_girl (4.4.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.4.1)
factory_girl (~> 4.4.0)
railties (>= 3.0.0)
faker (1.4.2)
i18n (~> 0.5)
hike (1.2.3)
i18n (0.6.11)
jbuilder (2.1.3)
Expand Down Expand Up @@ -149,6 +156,8 @@ DEPENDENCIES
bootstrap
bootstrap-sass
coffee-rails
factory_girl_rails
faker
jbuilder
jquery-rails
rails
Expand Down
28 changes: 28 additions & 0 deletions spec/controllers/blog_controller_spec.rb
@@ -0,0 +1,28 @@
require 'rails_helper'

RSpec.describe BlogsController, :type => :controller do

describe 'GET #index' do

let!(:blog1) { FactoryGirl.create(:blog) }
let!(:blog2) { FactoryGirl.create(:blog) }
let!(:blog3) { FactoryGirl.create(:blog) }

it "@blogsに全てのBlogが入っていること" do
get :index
expect(assigns(:blogs)).to eq [blog1, blog2, blog3]
end
end

describe 'POST #create' do
it "新規作成後に@blogのshowに遷移すること" do
@blog = FactoryGirl.attributes_for(:blog)
post :create, blog: @blog
response.should redirect_to blog_path(assigns(:blog))
end
end
end

# post :create, { name: 'name' }
# response.should redirect_to blog_path(@blog)
# expect(assigns(:blogs)).to eq @blogs
10 changes: 10 additions & 0 deletions spec/factories/blogs.rb
@@ -0,0 +1,10 @@
require 'faker'

FactoryGirl.define do
factory :blog do
title { Faker::Name.title }
end
factory :invalid_blog do
title nil
end
end

0 comments on commit 7d0dfd2

Please sign in to comment.