Commit 7e3b8e11
Changed files (8)
spec
controllers
models
requests
routing
spec/controllers/likes_controller_spec.rb
@@ -30,34 +30,11 @@ describe LikesController do
describe "GET index" do
it "assigns all likes as @likes" do
like = Like.create! valid_attributes
- get :index
+ get :index, :creation_id => "1"
assigns(:likes).should eq([like])
end
end
- describe "GET show" do
- it "assigns the requested like as @like" do
- like = Like.create! valid_attributes
- get :show, :id => like.id
- assigns(:like).should eq(like)
- end
- end
-
- describe "GET new" do
- it "assigns a new like as @like" do
- get :new
- assigns(:like).should be_a_new(Like)
- end
- end
-
- describe "GET edit" do
- it "assigns the requested like as @like" do
- like = Like.create! valid_attributes
- get :edit, :id => like.id
- assigns(:like).should eq(like)
- end
- end
-
describe "POST create" do
describe "with valid params" do
it "creates a new Like" do
@@ -77,81 +54,5 @@ describe LikesController do
response.should redirect_to(Like.last)
end
end
-
- describe "with invalid params" do
- it "assigns a newly created but unsaved like as @like" do
- # Trigger the behavior that occurs when invalid params are submitted
- Like.any_instance.stub(:save).and_return(false)
- post :create, :like => {}
- assigns(:like).should be_a_new(Like)
- end
-
- it "re-renders the 'new' template" do
- # Trigger the behavior that occurs when invalid params are submitted
- Like.any_instance.stub(:save).and_return(false)
- post :create, :like => {}
- response.should render_template("new")
- end
- end
- end
-
- describe "PUT update" do
- describe "with valid params" do
- it "updates the requested like" do
- like = Like.create! valid_attributes
- # Assuming there are no other likes in the database, this
- # specifies that the Like created on the previous line
- # receives the :update_attributes message with whatever params are
- # submitted in the request.
- Like.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
- put :update, :id => like.id, :like => {'these' => 'params'}
- end
-
- it "assigns the requested like as @like" do
- like = Like.create! valid_attributes
- put :update, :id => like.id, :like => valid_attributes
- assigns(:like).should eq(like)
- end
-
- it "redirects to the like" do
- like = Like.create! valid_attributes
- put :update, :id => like.id, :like => valid_attributes
- response.should redirect_to(like)
- end
- end
-
- describe "with invalid params" do
- it "assigns the like as @like" do
- like = Like.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- Like.any_instance.stub(:save).and_return(false)
- put :update, :id => like.id, :like => {}
- assigns(:like).should eq(like)
- end
-
- it "re-renders the 'edit' template" do
- like = Like.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- Like.any_instance.stub(:save).and_return(false)
- put :update, :id => like.id, :like => {}
- response.should render_template("edit")
- end
- end
end
-
- describe "DELETE destroy" do
- it "destroys the requested like" do
- like = Like.create! valid_attributes
- expect {
- delete :destroy, :id => like.id
- }.to change(Like, :count).by(-1)
- end
-
- it "redirects to the likes list" do
- like = Like.create! valid_attributes
- delete :destroy, :id => like.id
- response.should redirect_to(likes_url)
- end
- end
-
end
spec/models/user_spec.rb
@@ -5,14 +5,9 @@ describe User do
it "should not let the user like it again" do
# creation = Creation.new
creation = FactoryGirl.build(:creation)
- # user = User.create!
user = FactoryGirl.create(:user)
user.like(creation)
user.like(creation)
-
- # creation.likes.each do |like|
- # puts like.user.id
- # end
creation.likes.length.should eq(1)
end
end
spec/requests/likes_spec.rb
@@ -4,7 +4,7 @@ describe "Likes" do
describe "GET /likes" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
- get likes_path
+ get creation_likes_path
response.status.should be(200)
end
end
spec/routing/likes_routing_spec.rb
@@ -4,32 +4,11 @@ describe LikesController do
describe "routing" do
it "routes to #index" do
- get("/likes").should route_to("likes#index")
- end
-
- it "routes to #new" do
- get("/likes/new").should route_to("likes#new")
- end
-
- it "routes to #show" do
- get("/likes/1").should route_to("likes#show", :id => "1")
- end
-
- it "routes to #edit" do
- get("/likes/1/edit").should route_to("likes#edit", :id => "1")
+ get("/creations/1/likes").should route_to("likes#index")
end
it "routes to #create" do
- post("/likes").should route_to("likes#create")
+ post("/creations/1/likes").should route_to("likes#create")
end
-
- it "routes to #update" do
- put("/likes/1").should route_to("likes#update", :id => "1")
- end
-
- it "routes to #destroy" do
- delete("/likes/1").should route_to("likes#destroy", :id => "1")
- end
-
end
end
spec/views/likes/edit.html.erb_spec.rb
@@ -1,20 +0,0 @@
-require 'spec_helper'
-
-describe "likes/edit.html.erb" do
- before(:each) do
- @like = assign(:like, stub_model(Like,
- :user_id => 1,
- :creation_id => 1
- ))
- end
-
- it "renders the edit like form" do
- render
-
- # Run the generator again with the --webrat flag if you want to use webrat matchers
- assert_select "form", :action => likes_path(@like), :method => "post" do
- assert_select "input#like_user_id", :name => "like[user_id]"
- assert_select "input#like_creation_id", :name => "like[creation_id]"
- end
- end
-end
spec/views/likes/index.html.erb_spec.rb
@@ -1,24 +0,0 @@
-require 'spec_helper'
-
-describe "likes/index.html.erb" do
- before(:each) do
- assign(:likes, [
- stub_model(Like,
- :user_id => 1,
- :creation_id => 1
- ),
- stub_model(Like,
- :user_id => 1,
- :creation_id => 1
- )
- ])
- end
-
- it "renders a list of likes" do
- render
- # Run the generator again with the --webrat flag if you want to use webrat matchers
- assert_select "tr>td", :text => 1.to_s, :count => 2
- # Run the generator again with the --webrat flag if you want to use webrat matchers
- assert_select "tr>td", :text => 1.to_s, :count => 2
- end
-end
spec/views/likes/new.html.erb_spec.rb
@@ -1,20 +0,0 @@
-require 'spec_helper'
-
-describe "likes/new.html.erb" do
- before(:each) do
- assign(:like, stub_model(Like,
- :user_id => 1,
- :creation_id => 1
- ).as_new_record)
- end
-
- it "renders new like form" do
- render
-
- # Run the generator again with the --webrat flag if you want to use webrat matchers
- assert_select "form", :action => likes_path, :method => "post" do
- assert_select "input#like_user_id", :name => "like[user_id]"
- assert_select "input#like_creation_id", :name => "like[creation_id]"
- end
- end
-end
spec/views/likes/show.html.erb_spec.rb
@@ -1,18 +0,0 @@
-require 'spec_helper'
-
-describe "likes/show.html.erb" do
- before(:each) do
- @like = assign(:like, stub_model(Like,
- :user_id => 1,
- :creation_id => 1
- ))
- end
-
- it "renders attributes in <p>" do
- render
- # Run the generator again with the --webrat flag if you want to use webrat matchers
- rendered.should match(/1/)
- # Run the generator again with the --webrat flag if you want to use webrat matchers
- rendered.should match(/1/)
- end
-end