Skip to content

Commit

Permalink
change tests to reflect reality now that decisionapp/controllers/fact…
Browse files Browse the repository at this point in the history
…ors_controller.rbshow has been made the edit, and alternatives and factors are updated and deleted as part of the decision form
  • Loading branch information
Dave Aronson committed Jan 18, 2012
1 parent 132de94 commit 2931c6a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 133 deletions.
5 changes: 0 additions & 5 deletions app/controllers/decisions_controller.rb
Expand Up @@ -27,7 +27,6 @@ def new
@title = 'New Decision'
@decision = Decision.new
@show_all = @user.is_admin?
puts "NEW decision User = #{@decision.user.inspect}"
respond_to do |format|
format.html # new.html.erb
format.json { render json: @decision }
Expand All @@ -36,7 +35,6 @@ def new

# GET /decisions/1/edit
def edit
puts "EDITING decision User = #{@decision.user.inspect}"
respond_to do |format|
format.html # show.html.erb
format.json { render json: @decision }
Expand All @@ -50,15 +48,12 @@ def create
@decision = Decision.new(params[:decision])
@decision.user_id = current_user.id
@show_all = @user.is_admin?
puts "CREATING decision User = #{@decision.user.inspect}"
respond_to do |format|
if @decision.save
puts "\n\n\nSAVED #{@decision.inspect}\n\n\n"
format.html { redirect_to edit_decision_path(@decision),
notice: 'Decision was successfully created.' }
format.json { render json: @decision, status: :created, location: @decision }
else
puts "\n\n\nERRORED #{@decision.inspect}\n\n\n"
format.html { render action: "new" }
format.json { render json: @decision.errors,
status: :unprocessable_entity }
Expand Down
74 changes: 15 additions & 59 deletions spec/controllers/alternatives_controller_spec.rb
Expand Up @@ -41,6 +41,11 @@
sign_in @user
end

# since alts are now part of form, there is no
# edit in controller, only new/create!
# describe "GET edit" do
# end

describe "POST create" do
describe "with valid params" do
it "creates a new Alternative" do
Expand All @@ -63,15 +68,15 @@

describe "with invalid params" do
it "doesn't create a new alternative" do
pending "need to catch the exception here"
pending "need to rearrange this; currently can't find a decision w/o an id"
# Trigger the behavior that occurs when invalid params are submitted
Alternative.any_instance.stub(:save).and_return(false)
post :create, :alternative => {}
assigns(:alternative).should be_nil
end

it "re-renders the 'new' template" do
pending "need to catch the exception here, and/or in the actual code"
pending "need to rearrange this; currently can't find a decision w/o an id"
# Trigger the behavior that occurs when invalid params are submitted
Alternative.any_instance.stub(:save).and_return(false)
post :create, :alternative => {}
Expand All @@ -80,63 +85,14 @@
end
end

describe "PUT update" do
describe "with valid params" do
it "updates the requested alternative" do
alternative = Alternative.create! valid_attributes
# Assuming there are no other alternatives in the database, this
# specifies that the Alternative created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
Alternative.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => alternative.id, :alternative => {'these' => 'params'}
end

it "assigns the requested alternative as @alternative" do
alternative = Alternative.create! valid_attributes
put :update, :id => alternative.id, :alternative => valid_attributes
assigns(:alternative).should eq(alternative)
end

it "redirects to the decision" do
alternative = Alternative.create! valid_attributes
put :update, :id => alternative.id, :alternative => valid_attributes
response.should redirect_to(alternative.decision)
end
end
# since alts are now part of form, there is no
# update in controller, only new/create!
# describe "PUT update" do
# end

describe "with invalid params" do
it "assigns the alternative as @alternative" do
alternative = Alternative.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Alternative.any_instance.stub(:save).and_return(false)
put :update, :id => alternative.id.to_s, :alternative => {}
assigns(:alternative).should eq(alternative)
end

it "re-renders the 'edit' template" do
alternative = Alternative.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Alternative.any_instance.stub(:save).and_return(false)
put :update, :id => alternative.id.to_s, :alternative => {}
response.should render_template("edit")
end
end
end

describe "DELETE destroy" do
it "destroys the requested alternative" do
alternative = Alternative.create! valid_attributes
expect {
delete :destroy, :id => alternative.id.to_s
}.to change(Alternative, :count).by(-1)
end

it "redirects to the decision" do
alternative = Alternative.create! valid_attributes
delete :destroy, :id => alternative.id.to_s
response.should redirect_to(alternative.decision)
end
end
# since alts are now part of form, there is no
# delete in controller, only new/create!
# describe "DELETE destroy" do
# end

end
4 changes: 2 additions & 2 deletions spec/controllers/decisions_controller_spec.rb
Expand Up @@ -80,7 +80,7 @@ def valid_attributes

it "redirects to the created decision" do
post :create, :decision => valid_attributes
response.should redirect_to(Decision.last)
response.should redirect_to( edit_decision_path( Decision.last ))
end
end

Expand Down Expand Up @@ -122,7 +122,7 @@ def valid_attributes
it "redirects to the decision" do
decision = Decision.create! valid_attributes
put :update, :id => decision.id, :decision => valid_attributes
response.should redirect_to(decision)
response.should redirect_to( edit_decision_path( decision ))
end
end

Expand Down
78 changes: 13 additions & 65 deletions spec/controllers/factors_controller_spec.rb
Expand Up @@ -60,13 +60,10 @@
sign_in @user
end

describe "GET edit" do
it "assigns the requested factor as @factor" do
factor = Factor.create! valid_attributes
get :edit, :id => factor.id.to_s
assigns(:factor).should eq(factor)
end
end
# since factors are now part of form, there is no
# edit in controller, only new/create!
# describe "GET edit" do
# end

describe "POST create" do
describe "with valid params" do
Expand All @@ -84,7 +81,7 @@

it "redirects to the decision" do
post :create, :factor => valid_attributes
response.should redirect_to(Factor.last.decision)
response.should redirect_to( edit_decision_path( Factor.last.decision ))
end
end

Expand All @@ -107,63 +104,14 @@
end
end

describe "PUT update" do
describe "with valid params" do
it "updates the requested factor" do
factor = Factor.create! valid_attributes
# Assuming there are no other factors in the database, this
# specifies that the Factor created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
Factor.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => factor.id, :factor => {'these' => 'params'}
end
# since factors are now part of form, there is no
# update in controller, only new/create!
# describe "PUT update" do
# end

it "assigns the requested factor as @factor" do
factor = Factor.create! valid_attributes
put :update, :id => factor.id, :factor => valid_attributes
assigns(:factor).should eq(factor)
end

it "redirects to the decision" do
factor = Factor.create! valid_attributes
put :update, :id => factor.id, :factor => valid_attributes
response.should redirect_to(factor.decision)
end
end

describe "with invalid params" do
it "assigns the factor as @factor" do
factor = Factor.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Factor.any_instance.stub(:save).and_return(false)
put :update, :id => factor.id.to_s, :factor => {}
assigns(:factor).should eq(factor)
end

it "re-renders the 'edit' template" do
factor = Factor.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Factor.any_instance.stub(:save).and_return(false)
put :update, :id => factor.id.to_s, :factor => {}
response.should render_template("edit")
end
end
end

describe "DELETE destroy" do
it "destroys the requested factor" do
factor = Factor.create! valid_attributes
expect {
delete :destroy, :id => factor.id.to_s
}.to change(Factor, :count).by(-1)
end

it "redirects to the decision" do
factor = Factor.create! valid_attributes
delete :destroy, :id => factor.id.to_s
response.should redirect_to(factor.decision)
end
end
# since factors are now part of form, there is no
# delete in controller, only new/create!
# describe "DELETE destroy" do
# end

end
3 changes: 2 additions & 1 deletion spec/views/decisions/edit.html.erb_spec.rb
Expand Up @@ -12,7 +12,8 @@
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => decisions_path(@decision), :method => "post" do
assert_select "input#decision_name", :name => "decision[name]"
assert_select "input#decision_user_id", :name => "decision[user_id]"
# no, this only happens if user is admin!
# assert_select "input#decision_user_id", :name => "decision[user_id]"
end
end
end
3 changes: 2 additions & 1 deletion spec/views/decisions/new.html.erb_spec.rb
Expand Up @@ -12,7 +12,8 @@
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => decisions_path, :method => "post" do
assert_select "input#decision_name", :name => "decision[name]"
assert_select "input#decision_user_id", :name => "decision[user_id]"
# no, this only happens if user is admin!
# assert_select "input#decision_user_id", :name => "decision[user_id]"
end
end
end
File renamed without changes.

0 comments on commit 2931c6a

Please sign in to comment.