Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pagina para listar inscritos em uma corrida

  • Loading branch information...
commit 4a0d65fa8ce9b9896f31ffab8d1b8e9e672f11a7 1 parent d1e1f41
fabioperrella authored
6 app/controllers/subscriptions_controller.rb
View
@@ -10,7 +10,7 @@ def create
@subscription.user = current_user
if @subscription.save
flash[:notice] = I18n.t(:subscription_saved_successfull, :race_name => @subscription.id)
- redirect_to races_path
+ redirect_to race_subscriptions_path(race)
else
flash[:alert] = @subscription.errors.full_messages
render :action => :new
@@ -22,4 +22,8 @@ def destroy
subscription.destroy
redirect_to races_path, :notice => I18n.t(:subscription_destroyed_successfull, :race_name => subscription.race.name)
end
+
+ def show
+ @subscriptions = Subscription.where(:race_id => params[:race_id]).order(:created_at)
+ end
end
5 app/views/races/index.html.erb
View
@@ -1,4 +1,4 @@
-<h1>Calendario de corridas</h1>
+<h1>Calendário de corridas</h1>
<table class="table1">
<% @races.each do |race| %>
<tr>
@@ -19,6 +19,9 @@
<%= link_to t(:unsubscribe).downcase, race_subscriptions_path(race), :method => :delete %>
<% end %>
</td>
+ <td>
+ <%= link_to :subscriptions, race_subscriptions_path(race) %>
+ </td>
<% end %>
</tr>
<% end %>
6 app/views/subscriptions/show.html.erb
View
@@ -0,0 +1,6 @@
+<h2><%= t(:subscribed_users) %></h2>
+<% @subscriptions.each do |subscription| %>
+<p>
+ <%= subscription.user.name %> (<%= subscription.shirt_size %>)
+</p
+<% end %>
2  config/locales/pt-BR.yml
View
@@ -7,6 +7,8 @@
sign_in: "Logar"
sign_out: "Deslogar"
subscription: "Inscrição"
+ subscriptions: "Inscrições"
+ subscribed_users: "Usuários inscritos"
do_subscription: "Fazer inscrição"
subscription_saved_successfull: "Inscrição na corrida %{race_name} realizada com sucesso"
subscription_destroyed_successfull: "Cancelada inscrição na corrida %{race_name}"
19 spec/controllers/subscriptions_controller_spec.rb
View
@@ -32,10 +32,10 @@
flash[:notice].should_not be_nil
end
end
-
- describe "DELETE destroy" do
+
+ describe "DELETE destroy" do
it "deletes a subscription" do
- subscription = FactoryGirl.create :subscription, :user => @user, :race => @race
+ subscription = FactoryGirl.create :subscription, :user => @user, :race => @race
delete :destroy, { :race_id => @race.id }
Subscription.find_by_race_id_and_user_id(@race,@user).should be_nil
end
@@ -58,7 +58,7 @@
it "redirects to races index" do
post :create, { :race_id => @race, :subscription => { :shirt_size => "P" } }
- response.should redirect_to(races_path)
+ response.should redirect_to(race_subscriptions_path(@race))
end
end
@@ -74,5 +74,16 @@
end
end
end
+
+ describe "GET show" do
+ it "assigns subscriptions ordered by date" do
+ subscription1 = FactoryGirl.create :subscription, :race => @race
+ FactoryGirl.create :subscription, :race => FactoryGirl.create(:race)
+ subscription2 = FactoryGirl.create :subscription, :race => @race, :created_at => Date.yesterday
+
+ get :show, :race_id => @race.id
+ assigns(:subscriptions).should == [subscription2, subscription1]
+ end
+ end
end
end
2  spec/spec_helper.rb
View
@@ -3,7 +3,7 @@
Spork.each_run do
#FactoryGirl.reload
- I18n.backend.reload!
+ #I18n.backend.reload!
end
Spork.prefork do
Please sign in to comment.
Something went wrong with that request. Please try again.