Created
April 23, 2012 18:11
-
-
Save wnstn/2472809 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Admin::AnswersController < Admin::AdminController | |
helper :answers | |
def index | |
@answers = @site.answers | |
end | |
def show | |
@answer = Answer.find(params[:id]) | |
end | |
def new | |
@answer = Answer.new | |
end | |
def edit | |
@answer = Answer.find(params[:id]) | |
end | |
def create | |
@answer = Answer.new(params[:answer]) | |
@page = @site.pages.find(params[:answer][:page_id]) | |
if @page.answers << @answer | |
redirect_to(admin_site_answers_path(@site), :notice => 'answer was successfully created.') | |
else | |
render :action => "new" | |
end | |
end | |
def update | |
@answer = Answer.find(params[:id]) | |
if @answer.update_attributes(params[:answer]) | |
redirect_to(admin_site_answers_path(@answer, :site_id => params[:site_id]), :notice => 'answer was successfully updated.') | |
else | |
render :action => "edit" | |
end | |
end | |
def destroy | |
@answer = Answer.find(params[:id]) | |
@answer.destroy | |
redirect_to(admin_site_answers_url(:site_id => @site.id)) | |
end | |
private | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "POST create" do | |
context "while signed-in as a site specific admin" do | |
before(:each) do | |
@user = Factory(:user) | |
@site.add_site_specific_admin!(@user) | |
UserSession.create(@user) | |
end | |
describe "with valid params" do | |
it "creates a new Answer" do | |
expect { | |
post :create, :answer => Factory.build(:answer, :page_id => @page.id).attributes, :site_id => @site.id | |
}.to change(Answer, :count).by(1) | |
end | |
it "assigns a newly created answer as @answer" do | |
post :create, :answer => Factory.build(:answer, :page_id => @page.id).attributes, :site_id => @site.id | |
assigns(:answer).should be_a(Answer) | |
assigns(:answer).should be_persisted | |
end | |
it "redirects to the answer list" do | |
post :create, :answer => Factory.build(:answer, :page_id => @page.id).attributes, :site_id => @site.id | |
response.should redirect_to(admin_site_answers_path(:site_id => @site.id)) | |
end | |
end | |
describe "with invalid params" do | |
it "assigns a newly created but unsaved answer as @answer" do | |
# Trigger the behavior that occurs when invalid params are submitted | |
Answer.any_instance.stubs(:save).returns(false) | |
post :create, :answer => {}, :site_id => @site.id | |
assigns(:answer).should be_a_new(Answer) | |
end | |
it "re-renders the 'new' template" do | |
# Trigger the behavior that occurs when invalid params are submitted | |
Answer.any_instance.stubs(:save).returns(false) | |
post :create, :answer => {}, :site_id => @site.id | |
response.should render_template("new") | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) Admin::AnswersController POST create while signed-in as a site specific admin with invalid params assigns a newly created but unsaved answer as @answer | |
Failure/Error: post :create, :answer => {}, :site_id => @site.id | |
ActionView::MissingTemplate: | |
Missing layout layouts/test with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :rep], :formats=>[:html], :locale=>[:en, :en]} in view paths "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007f90655924a8>" | |
# ./app/controllers/application_controller.rb:90:in `rescue in catch_exceptions' | |
# ./app/controllers/application_controller.rb:87:in `catch_exceptions' | |
# ./spec/controllers/admin/answers_controller_spec.rb:191:in `block (5 levels) in <top (required)>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment