Skip to content

Instantly share code, notes, and snippets.

@rahulcn
Created October 28, 2011 04:47
Show Gist options
  • Save rahulcn/1321648 to your computer and use it in GitHub Desktop.
Save rahulcn/1321648 to your computer and use it in GitHub Desktop.
Tests r not passing for create action please help....
Failures:
1) MicropostsController POST 'create' failure should render the home page
Failure/Error: response.should render_template('pages/home')
expecting <"pages/home"> but rendering with <"">
# ./spec/controllers/microposts_controller_spec.rb:38:in `block (4 levels) in <top (required)>'
2) MicropostsController POST 'create' success should create a micropost
Failure/Error: lambda do
count should have been changed by 1, but was changed by 0
# ./spec/controllers/microposts_controller_spec.rb:49:in `block (4 levels) in <top (required)>'
3) MicropostsController POST 'create' success should redirect to the home page
Failure/Error: response.should redirect_to(root_path)
Expected response to be a redirect to <http://test.host/> but was a redirect to <http://test.host/signin>
# ./spec/controllers/microposts_controller_spec.rb:56:in `block (4 levels) in <top (required)>'
4) MicropostsController POST 'create' success should have a flash message
Failure/Error: flash[:success].should =~ /micropost created/i
expected: /micropost created/i
got: nil (using =~)
# ./spec/controllers/microposts_controller_spec.rb:61:in `block (4 levels) in <top (required)>'
Finished in 4.1 seconds
103 examples, 4 failures
Failed examples:
rspec ./spec/controllers/microposts_controller_spec.rb:36 # MicropostsController POST 'create' failure should render the home page
rspec ./spec/controllers/microposts_controller_spec.rb:48 # MicropostsController POST 'create' success should create a micropost
rspec ./spec/controllers/microposts_controller_spec.rb:54 # MicropostsController POST 'create' success should redirect to the home page
rspec ./spec/controllers/microposts_controller_spec.rb:59 # MicropostsController POST 'create' success should have a flash message
<%= form_for(@micropost) do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit "Submit" %>
</div>
<% end %>
class MicropostsController < ApplicationController
before_filter :authenticate
def create
@micropost = current_user.microposts.build(params[:micropost])
if @micropost.save
flash[:success] = "Micropost created!"
redirect_to root_path
else
render 'pages/home'
end
end
def destroy
end
end
require 'spec_helper'
describe MicropostsController do
render_views
describe "access controll" do
it "should deny access to 'create'" do
post :create
response.should redirect_to(signin_path)
end
it "should deny access to 'destroy'" do
delete :destroy, :id => 1
response.should redirect_to(signin_path)
end
end
describe "POST 'create'" do
before(:each) do
@user = test_sign_in(Factory(:user))
end
describe "failure" do
before(:each) do
@attr = { :content => "" }
end
it "should not create a micropost" do
lambda do
post :create, :micropost => @attr
end.should_not change(Micropost, :count)
end
it "should render the home page" do
post :create, :micropost => @attr
response.should render_template('pages/home')
end
end
describe "success" do
before(:each) do
@attr = { :content => "Lorem ipsum" }
end
it "should create a micropost" do
lambda do
post :create, :micropost => @attr
end.should change(Micropost, :count).by(1)
end
it "should redirect to the home page" do
post :create, :micropost => @attr
response.should redirect_to(root_path)
end
it "should have a flash message" do
post :create, :micropost => @attr
flash[:success].should =~ /micropost created/i
end
end
end
end
<% if signed_in? %>
<table class="front" summary="For signed-in users">
<tr>
<td class="main">
<h1 class="micropost">What's up?</h1>
<%= render 'posts' %>
</td>
</tr>
</table>
<% else %>
<h1>Sample App</h1>
<%= link_to "Sign up now!", signup_path, :class => "signup_button round" %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment