Permalink
Browse files

I kind of separated the handling for the quick answers and the edit i…

…n the form and thereby introduced two levels of partials, dunno how to do it better atm. Suggestions are always welcome. Also got a sip of the magic of inherited_resources - wow. Contains a little nice cucumber feature. Fixes #126
  • Loading branch information...
1 parent 1786f7c commit 1c0759b31b238c60acc3f6bb4a681cc1807f033a @PragTob PragTob committed Mar 12, 2012
@@ -13,5 +13,13 @@ def create
create!(:notice => "Answer Posted!"){ question_url(params[:question_id]) }
end
+ def update
+ # inherited resorces (gem) magic
+ super do |format|
+ format.html { redirect_to question_url(resource.question) }
+ end
+ end
+
end
+
@@ -1,9 +1,3 @@
-= simple_form_for(@answer, :url => question_answers_path(@question)) do |f|
- = f.error_notification
+= simple_form_for(resource, :url => @form_url) do |f|
+ = render 'form_content', :f => f
- .inputs
- = f.input :description, :as => :text, :label => "Answer",
- :hint => "You can format your input with <a href=\"http://daringfireball.net/projects/markdown/\">Markdown</a>".html_safe
-
- .actions
- = f.button :submit, :value => "Post Answer", :class => "primary btn"
@@ -0,0 +1,9 @@
+= f.error_notification
+
+.inputs
+ = f.input :description, :as => :text, :label => "Answer",
+ :hint => "You can format your input with <a href=\"http://daringfireball.net/projects/markdown/\">Markdown</a>".html_safe
+
+.actions
+ = f.button :submit, :value => "Post Answer", :class => "primary btn"
+
@@ -0,0 +1,3 @@
+= simple_form_for(@answer, :url => question_answers_path(@question)) do |f|
+ = render 'answers/form_content', :f => f
+
@@ -34,4 +34,5 @@
= render :partial => "answers/list", :collection => resource.answers
- if can? :create, Answer
- = render :partial => "answers/form"
+ = render :partial => "answers/short_answer"
+
@@ -10,3 +10,9 @@ Feature: CRUD actions for answers
And I should be able to see my answer
And my answer should show on my profile page
+ Scenario: Edit an answer
+ Given a question exists
+ And I answer that question
+ When I edit that answer
+ Then I should see the updated answer
+
@@ -28,3 +28,15 @@
ActionMailer::Base.deliveries.should_not be_empty
end
+When /^I edit that answer$/ do
+ visit question_path(@question)
+ page.find('.answer > .links').click_link('Edit')
+ fill_in 'Answer', with: 'Edit: Did you try magic?'
+ click_button 'Post Answer'
+end
+
+Then /^I should see the updated answer$/ do
+ page.should have_content("#{@user.username} says")
+ page.should have_content('Edit: Did you try magic?')
+end
+

0 comments on commit 1c0759b

Please sign in to comment.