Skip to content
This repository has been archived by the owner on Aug 20, 2019. It is now read-only.

Commit

Permalink
refactored RulingsController to use routes nested under Inquests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesarosen committed Jan 18, 2010
1 parent 876306a commit a7c1260
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions app/controllers/rulings_controller.rb
@@ -1,14 +1,14 @@
class RulingsController < ApplicationController

def create
@ruling ||= Ruling.new(params[:ruling])
@inquest = Inquest.find(params[:inquest_id])
@ruling ||= Ruling.new(params[:ruling].merge(:inquest => @inquest))
if @ruling.save
flash[:notice] = I18n.t('rulings.create.success')
redirect_to random_inquest_path
current_user_has_ruled_on_inquest(@ruling.inquest)
current_user_has_ruled_on_inquest(@inquest)
else
flash[:error] = I18n.t('rulings.create.error')
@inquest = @ruling.inquest
render :action => '/inquests/show'
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/application_helper.rb
Expand Up @@ -17,15 +17,15 @@ def inquests_url(options)
# TODO: remove once
# https://rails.lighthouseapp.com/projects/8994/tickets/3730
# is resolved.
def rulings_path(options = {})
rulings_url(options.merge({:only_path => true}))
def inquest_rulings_path(inquest, options = {})
inquest_rulings_url(inquest, options.merge({:only_path => true}))
end

# TODO: remove once
# https://rails.lighthouseapp.com/projects/8994/tickets/3730
# is resolved.
def rulings_url(options)
url_for({:controller => :rulings, :action => :create}.merge(options))
def inquest_rulings_url(inquest, options)
url_for({:controller => :rulings, :action => :create, :inquest_id => inquest}.merge(options))
end

end
6 changes: 3 additions & 3 deletions app/views/inquests/show.html.erb
Expand Up @@ -2,9 +2,9 @@
<div class='inquest'>
<%= image_tag @inquest.image_url, :class => 'xOrNot' %>
<div class='vote'>
<%= button_to t('inquests.show.is'), rulings_path(:ruling => {:inquest_id => @inquest, :vote => Ruling::YES}) %>
<%= button_to t('inquests.show.is_not'), rulings_path(:ruling => {:inquest_id => @inquest, :vote => Ruling::NO}) %>
<%= button_to t('inquests.show.not_sure'), rulings_path(:ruling => {:inquest_id => @inquest, :vote => Ruling::NOT_SURE}) %>
<%= button_to t('inquests.show.is'), inquest_rulings_path(@inquest, :ruling => {:vote => Ruling::YES}) %>
<%= button_to t('inquests.show.is_not'), inquest_rulings_path(@inquest, :ruling => {:vote => Ruling::NO}) %>
<%= button_to t('inquests.show.not_sure'), inquest_rulings_path(@inquest, :ruling => {:vote => Ruling::NOT_SURE}) %>
</div>
</div>
<%- if @inquest.predecessor.present? -%>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -4,8 +4,8 @@
match '/about(.html)' => 'pages#about', :as => :about
resources :inquests, :only => [ :show, :new, :create ] do
get :random, :on => :collection
resources :rulings, :only => [ :create ]
end
resources :rulings, :only => [ :create ]
match '/(:path(.:format))' => 'pages#not_found'
# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
4 changes: 2 additions & 2 deletions test/functional/rulings_controller_test.rb
Expand Up @@ -15,12 +15,12 @@ class RulingsControllerTest < ActionController::TestCase
end

test "after successfully ruling on an Inquest, the user should be redirected to another random Inquest" do
post :create, :ruling => { :inquest_id => @inquest1.id, :vote => 'yes' }
post :create, :inquest_id => @inquest1.id, :ruling => { :vote => 'yes' }
assert_redirected_to random_inquest_path
end

test "after successfully ruling on an Inquest, should mark the current user as having ruled on it" do
post :create, :ruling => { :inquest_id => @inquest2.id, :vote => 'no' }
post :create, :inquest_id => @inquest2.id, :ruling => { :vote => 'no' }
assert @controller.current_user_has_ruled_on_inquest?(@inquest2)
end

Expand Down

0 comments on commit a7c1260

Please sign in to comment.