Skip to content

Commit

Permalink
organization decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjabba committed Sep 21, 2013
1 parent 0707a26 commit 0263eea
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
5 changes: 2 additions & 3 deletions app/controllers/organizations_controller.rb
Expand Up @@ -8,9 +8,8 @@ def index
end

def show
@organization = Organization.find(params[:id])
@title = "View Organization | " + @organization.name
@leagues = @organization.leagues
@organization = OrganizationDecorator.new(Organization.find(params[:id]))
@title = @organization.title
end

def new
Expand Down
11 changes: 11 additions & 0 deletions app/decorators/organization_decorator.rb
@@ -0,0 +1,11 @@
class OrganizationDecorator < Draper::Decorator
delegate_all

def leagues
@leagues ||= model.leagues
end

def title
"View Organization | " + model.name
end
end
2 changes: 1 addition & 1 deletion app/views/leagues/_simple.html.erb
Expand Up @@ -4,7 +4,7 @@
<th title="Year">Season</th>
<th title="Actions">Actions</th>
</tr>
<% for league in @leagues%>
<% for league in leagues %>
<tr>
<td><%= link_to league.name , league %></td>
<td><%= league.from_year %>-<%= league.to_year %></td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/organizations/show.html.erb
Expand Up @@ -12,8 +12,8 @@
</div>

<div>
<% unless @leagues.empty? %>
<%= render :partial => "leagues/simple", :locals => {:leagues => @leagues} %>
<% unless @organization.leagues.empty? %>
<%= render :partial => "leagues/simple", :locals => {:leagues => @organization.leagues} %>
<% end %>
</div>
<div class="row">
Expand Down
23 changes: 23 additions & 0 deletions spec/decorators/organization_decorator_spec.rb
@@ -0,0 +1,23 @@
require 'spec_helper'

describe OrganizationDecorator do
let(:organization) {Organization.new}
subject do
organization.leagues.build(:name => 'foo')
OrganizationDecorator.new(organization)
end

describe 'leagues' do
it 'shows the leagues' do
subject.leagues.size.should == 1
end
end

describe 'title' do
let(:title) { "title"}
before { subject.name = title}
it 'shows the title' do
subject.title.should == "View Organization | #{title}"
end
end
end

0 comments on commit 0263eea

Please sign in to comment.