Permalink
Browse files

Updated specs, to_param and better even tests

  • Loading branch information...
1 parent 9cf1b52 commit c73a3612ac6c4bd90d1028aa33651847515a93be LupineDev committed Feb 19, 2012
@@ -48,7 +48,7 @@ def valid_attributes
it "assigns the requested event as @event" do
event = Event.create! valid_attributes
- get :show, :id => event.id.to_s
+ get :show, :id => event.to_param
assigns(:event).should eq(event)
end
end
@@ -69,7 +69,7 @@ def valid_attributes
it_should_behave_like "a single admin event view", :edit
it "assigns the requested event as @event" do
- get :edit, :id => @event.id.to_s
+ get :edit, :id => @event.to_param
assigns(:event).should eq(@event)
end
end
@@ -141,15 +141,15 @@ def valid_attributes
event = Event.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Event.any_instance.stub(:save).and_return(false)
- put :update, :id => event.id.to_s, :event => {}
+ put :update, :id => event.to_param, :event => {}
assigns(:event).should eq(event)
end
it "re-renders the 'edit' template" do
event = Event.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Event.any_instance.stub(:save).and_return(false)
- put :update, :id => event.id.to_s, :event => {}
+ put :update, :id => event.to_param, :event => {}
response.should render_template("edit")
end
end
@@ -159,13 +159,13 @@ def valid_attributes
it "destroys the requested event" do
event = Event.create! valid_attributes
expect {
- delete :destroy, :id => event.id.to_s
+ delete :destroy, :id => event.to_param
}.to change(Event, :count).by(-1)
end
it "redirects to the events list" do
event = Event.create! valid_attributes
- delete :destroy, :id => event.id.to_s
+ delete :destroy, :id => event.to_param
response.should redirect_to(admin_events_url)
end
end
@@ -14,36 +14,36 @@
login_admin
def valid_attributes
- {:name => "top_snippet", :event_id => @event.id}
+ {:name => "top_snippet", :event_id => @event.to_param}
end
describe "GET index" do
it "assigns all snippets as @snippets" do
snippet = Snippet.create! valid_attributes
- get :index, :event_id => @event.id
+ get :index, :event_id => @event.to_param
assigns(:snippets).should eq([snippet])
end
end
describe "GET show" do
it "assigns the requested snippet as @snippet" do
snippet = Snippet.create! valid_attributes
- get :show, :id => snippet.id.to_s, :event_id => @event.id
+ get :show, :id => snippet.id.to_s, :event_id => @event.to_param
assigns(:snippet).should eq(snippet)
end
end
describe "GET new" do
it "assigns a new snippet as @snippet" do
- get :new, :event_id => @event.id
+ get :new, :event_id => @event.to_param
assigns(:snippet).should be_a_new(Snippet)
end
end
describe "GET edit" do
it "assigns the requested snippet as @snippet" do
snippet = Snippet.create! valid_attributes
- get :edit, :id => snippet.id.to_s, :event_id => @event.id
+ get :edit, :id => snippet.id.to_s, :event_id => @event.to_param
assigns(:snippet).should eq(snippet)
end
end
@@ -52,18 +52,18 @@ def valid_attributes
describe "with valid params" do
it "creates a new Snippet" do
expect {
- post :create, :event_id => @event.id, :snippet => valid_attributes
+ post :create, :event_id => @event.to_param, :snippet => valid_attributes
}.to change(Snippet, :count).by(1)
end
it "assigns a newly created snippet as @snippet" do
- post :create, :event_id => @event.id, :snippet => valid_attributes
+ post :create, :event_id => @event.to_param, :snippet => valid_attributes
assigns(:snippet).should be_a(Snippet)
assigns(:snippet).should be_persisted
end
it "redirects to the created snippet" do
- post :create, :event_id => @event.id, :snippet => valid_attributes
+ post :create, :event_id => @event.to_param, :snippet => valid_attributes
response.should redirect_to(admin_event_snippet_path(@event,Snippet.last))
end
end
@@ -72,14 +72,14 @@ def valid_attributes
it "assigns a newly created but unsaved snippet as @snippet" do
# Trigger the behavior that occurs when invalid params are submitted
Snippet.any_instance.stub(:save).and_return(false)
- post :create, :event_id => @event.id, :snippet => {}
+ post :create, :event_id => @event.to_param, :snippet => {}
assigns(:snippet).should be_a_new(Snippet)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Snippet.any_instance.stub(:save).and_return(false)
- post :create, :event_id => @event.id, :snippet => {}
+ post :create, :event_id => @event.to_param, :snippet => {}
response.should render_template("new")
end
end
@@ -94,18 +94,18 @@ def valid_attributes
# receives the :update_attributes message with whatever params are
# submitted in the request.
Snippet.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
- put :update, :event_id => @event.id, :id => snippet.id, :snippet => {'these' => 'params'}
+ put :update, :event_id => @event.to_param, :id => snippet.id, :snippet => {'these' => 'params'}
end
it "assigns the requested snippet as @snippet" do
snippet = Snippet.create! valid_attributes
- put :update, :event_id => @event.id, :id => snippet.id, :snippet => valid_attributes
+ put :update, :event_id => @event.to_param, :id => snippet.id, :snippet => valid_attributes
assigns(:snippet).should eq(snippet)
end
it "redirects to the snippet" do
snippet = Snippet.create! valid_attributes
- put :update, :event_id => @event.id, :id => snippet.id, :snippet => valid_attributes
+ put :update, :event_id => @event.to_param, :id => snippet.id, :snippet => valid_attributes
response.should redirect_to(admin_event_snippet_path(@event, snippet))
end
end
@@ -115,15 +115,15 @@ def valid_attributes
snippet = Snippet.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Snippet.any_instance.stub(:save).and_return(false)
- put :update, :event_id => @event.id, :id => snippet.id.to_s, :snippet => {}
+ put :update, :event_id => @event.to_param, :id => snippet.id.to_s, :snippet => {}
assigns(:snippet).should eq(snippet)
end
it "re-renders the 'edit' template" do
snippet = Snippet.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Snippet.any_instance.stub(:save).and_return(false)
- put :update, :event_id => @event.id, :id => snippet.id.to_s, :snippet => {}
+ put :update, :event_id => @event.to_param, :id => snippet.id.to_s, :snippet => {}
response.should render_template("edit")
end
end
@@ -133,13 +133,13 @@ def valid_attributes
it "destroys the requested snippet" do
snippet = Snippet.create! valid_attributes
expect {
- delete :destroy, :event_id => @event.id, :id => snippet.id.to_s
+ delete :destroy, :event_id => @event.to_param, :id => snippet.id.to_s
}.to change(Snippet, :count).by(-1)
end
it "redirects to the snippets list" do
snippet = Snippet.create! valid_attributes
- delete :destroy, :event_id => @event.id, :id => snippet.id.to_s
+ delete :destroy, :event_id => @event.to_param, :id => snippet.id.to_s
response.should redirect_to(admin_event_snippets_url)
end
end
@@ -16,7 +16,7 @@
# Sponsor. As you add validations to Sponsor, be sure to
# update the return value of this method accordingly.
def valid_attributes
- {:name => "sponsor", :event_id => @event.id}
+ {:name => "sponsor", :event_id => @event.to_param}
end
shared_examples_for "an admin event sponsors view" do |action, single_action|
@@ -37,7 +37,7 @@ def valid_attributes
describe "GET index" do
it "assigns all sponsors as @sponsors" do
sponsor = Sponsor.create! valid_attributes
- get :index, :event_id => @event.id
+ get :index, :event_id => @event.to_param
assigns(:sponsors).should eq([sponsor])
end
it_should_behave_like "an admin event sponsors view", :index
@@ -46,15 +46,15 @@ def valid_attributes
describe "GET show" do
it "assigns the requested sponsor as @sponsor" do
sponsor = Sponsor.create! valid_attributes
- get :show, :id => sponsor.id.to_s, :event_id => @event.id
+ get :show, :id => sponsor.id.to_s, :event_id => @event.to_param
assigns(:sponsor).should eq(sponsor)
end
it_should_behave_like "an admin event sponsors view", :show, true
end
describe "GET new" do
it "assigns a new sponsor as @sponsor" do
- get :new, :event_id => @event.id
+ get :new, :event_id => @event.to_param
assigns(:sponsor).should be_a_new(Sponsor)
end
it_should_behave_like "an admin event sponsors view", :new
@@ -63,7 +63,7 @@ def valid_attributes
describe "GET edit" do
it "assigns the requested sponsor as @sponsor" do
sponsor = Sponsor.create! valid_attributes
- get :edit, :id => sponsor.id.to_s, :event_id => @event.id
+ get :edit, :id => sponsor.id.to_s, :event_id => @event.to_param
assigns(:sponsor).should eq(sponsor)
end
it_should_behave_like "an admin event sponsors view", :edit, true
@@ -73,18 +73,18 @@ def valid_attributes
describe "with valid params" do
it "creates a new Sponsor" do
expect {
- post :create, :event_id => @event.id, :sponsor => valid_attributes
+ post :create, :event_id => @event.to_param, :sponsor => valid_attributes
}.to change(Sponsor, :count).by(1)
end
it "assigns a newly created sponsor as @sponsor" do
- post :create, :event_id => @event.id, :sponsor => valid_attributes
+ post :create, :event_id => @event.to_param, :sponsor => valid_attributes
assigns(:sponsor).should be_a(Sponsor)
assigns(:sponsor).should be_persisted
end
it "redirects to the created sponsor" do
- post :create, :event_id => @event.id, :sponsor => valid_attributes
+ post :create, :event_id => @event.to_param, :sponsor => valid_attributes
response.should redirect_to([:admin, @event, Sponsor.last])
end
end
@@ -93,14 +93,14 @@ def valid_attributes
it "assigns a newly created but unsaved sponsor as @sponsor" do
# Trigger the behavior that occurs when invalid params are submitted
Sponsor.any_instance.stub(:save).and_return(false)
- post :create, :event_id => @event.id, :sponsor => {}
+ post :create, :event_id => @event.to_param, :sponsor => {}
assigns(:sponsor).should be_a_new(Sponsor)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Sponsor.any_instance.stub(:save).and_return(false)
- post :create, :event_id => @event.id, :sponsor => {}
+ post :create, :event_id => @event.to_param, :sponsor => {}
response.should render_template("new")
end
end
@@ -115,18 +115,18 @@ def valid_attributes
# receives the :update_attributes message with whatever params are
# submitted in the request.
Sponsor.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
- put :update, :event_id => @event.id, :id => sponsor.id, :sponsor => {'these' => 'params'}
+ put :update, :event_id => @event.to_param, :id => sponsor.id, :sponsor => {'these' => 'params'}
end
it "assigns the requested sponsor as @sponsor" do
sponsor = Sponsor.create! valid_attributes
- put :update, :event_id => @event.id, :id => sponsor.id, :sponsor => valid_attributes
+ put :update, :event_id => @event.to_param, :id => sponsor.id, :sponsor => valid_attributes
assigns(:sponsor).should eq(sponsor)
end
it "redirects to the sponsor" do
sponsor = Sponsor.create! valid_attributes
- put :update, :event_id => @event.id, :id => sponsor.id, :sponsor => valid_attributes
+ put :update, :event_id => @event.to_param, :id => sponsor.id, :sponsor => valid_attributes
response.should redirect_to([:admin, @event, sponsor])
end
end
@@ -136,15 +136,15 @@ def valid_attributes
sponsor = Sponsor.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Sponsor.any_instance.stub(:save).and_return(false)
- put :update, :event_id => @event.id, :id => sponsor.id.to_s, :sponsor => {}
+ put :update, :event_id => @event.to_param, :id => sponsor.id.to_s, :sponsor => {}
assigns(:sponsor).should eq(sponsor)
end
it "re-renders the 'edit' template" do
sponsor = Sponsor.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Sponsor.any_instance.stub(:save).and_return(false)
- put :update, :event_id => @event.id, :id => sponsor.id.to_s, :sponsor => {}
+ put :update, :event_id => @event.to_param, :id => sponsor.id.to_s, :sponsor => {}
response.should render_template("edit")
end
end
@@ -154,14 +154,14 @@ def valid_attributes
it "destroys the requested sponsor" do
sponsor = Sponsor.create! valid_attributes
expect {
- delete :destroy, :event_id => @event.id, :id => sponsor.id.to_s
+ delete :destroy, :event_id => @event.to_param, :id => sponsor.id.to_s
}.to change(Sponsor, :count).by(-1)
end
it "redirects to the sponsors list" do
sponsor = Sponsor.create! valid_attributes
- delete :destroy, :event_id => @event.id, :id => sponsor.id.to_s
- response.should redirect_to(admin_event_sponsors_url(@event.id))
+ delete :destroy, :event_id => @event.to_param, :id => sponsor.id.to_s
+ response.should redirect_to(admin_event_sponsors_url(@event.to_param))
end
end
@@ -2,7 +2,6 @@
require 'faker'
Factory.define :event do |f|
-
f.name Faker::Company.name
-
-end
+ f.year (1000..3000).to_a.sample.to_s
+end
View
@@ -1,7 +1,16 @@
require 'spec_helper'
describe Event do
-
- it { should validate_presence_of :name }
-
+ before :all do
+ @event = Factory(:event)
+ end
+ describe "validations" do
+ it { should validate_presence_of :name }
+ end
+
+ describe "associations" do
+ it { should have_many :snippets }
+ it { should have_many :sponsors }
+ it { should have_many :sponsorship_levels }
+ end
end

0 comments on commit c73a361

Please sign in to comment.