popolo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,17 +18,19 @@ First, create your Rails application:
18
18
 
19
19
  rails new myapp --skip-active-record
20
20
 
21
- Add the `popolo` gem to your `Gemfile`:
21
+ Add the `popolo` gem to your `Gemfile` and bundle your dependencies:
22
22
 
23
23
  gem 'popolo'
24
+ bundle
24
25
 
25
26
  If you didn't run `rails new` with the `--skip-active-record` option, follow Mongoid's [installation instructions](http://mongoid.org/en/mongoid/docs/installation.html). Otherwise:
26
27
 
27
28
  rails generate mongoid:config
28
29
 
29
- Finally, run the `popolo` generator:
30
+ Finally, run the `popolo` generator and create the MongoDB indexes:
30
31
 
31
32
  rails generate popolo
33
+ bundle exec rake db:mongoid:create_indexes
32
34
 
33
35
  ## Bugs? Questions?
34
36
 
@@ -16,11 +16,6 @@ module Popolo
16
16
  index!
17
17
  end
18
18
 
19
- def show
20
- @area = Area.find_by_slug_or_id(params[:id])
21
- show!
22
- end
23
-
24
19
  def nested_index
25
20
  @areas = @area.children
26
21
 
@@ -7,20 +7,15 @@ module Popolo
7
7
 
8
8
  respond_to :html, :json
9
9
  actions :index, :show
10
- custom_actions collection: :nested_index, resource: :nested_show
10
+ custom_actions collection: :nested_index, resource: [:nested_show, :posts, :post]
11
11
 
12
- before_filter :validate_path, only: [:nested_index, :nested_show]
12
+ before_filter :validate_path, only: [:nested_index, :nested_show, :posts, :post]
13
13
 
14
14
  def index
15
15
  @organizations = Organization.roots
16
16
  index!
17
17
  end
18
18
 
19
- def show
20
- @organization = Organization.find_by_slug_or_id(params[:id])
21
- show!
22
- end
23
-
24
19
  def nested_index
25
20
  @organizations = @organization.children
26
21
 
@@ -35,6 +30,14 @@ module Popolo
35
30
  end
36
31
  end
37
32
 
33
+ def posts
34
+ @posts = @organization.posts
35
+ end
36
+
37
+ def post
38
+ @post = Post.find_by(organization_id: @organization, slug: params[:id])
39
+ end
40
+
38
41
  protected
39
42
 
40
43
  # @raises [Mongoid::Errors::DocumentNotFound] if a resource is improperly nested
@@ -3,10 +3,5 @@ module Popolo
3
3
  inherit_resources
4
4
  respond_to :html, :json
5
5
  actions :index, :show
6
-
7
- def show
8
- @post = Post.find_by_slug_or_id(params[:id])
9
- show!
10
- end
11
6
  end
12
7
  end
@@ -10,18 +10,18 @@ module Popolo
10
10
  # The postal address.
11
11
  field :address, type: String
12
12
  # A voice telephone number.
13
- field :voice, type: Integer
13
+ field :voice, type: String
14
14
  # A facsimile telephone number.
15
- field :fax, type: Integer
15
+ field :fax, type: String
16
16
  # A mobile telephone number.
17
- field :cell, type: Integer
17
+ field :cell, type: String
18
18
  # A toll-free telephone number.
19
- field :tollfree, type: Integer
19
+ field :tollfree, type: String
20
20
  # A video conferencing telephone number.
21
- field :video, type: Integer
21
+ field :video, type: String
22
22
  # A paging device telephone number.
23
- field :pager, type: Integer
23
+ field :pager, type: String
24
24
  # A telecommunication device for people with hearing or speech difficulties.
25
- field :textphone, type: Integer
25
+ field :textphone, type: String
26
26
  end
27
27
  end
@@ -4,12 +4,8 @@ module Popolo
4
4
  class Post
5
5
  include Mongoid::Document
6
6
 
7
- def self.slug_source
8
- :role
9
- end
10
-
11
7
  include Popolo::Sluggable
12
- index({slug: 1}, unique: true)
8
+ index({slug: 1, organization_id: 1}, unique: true)
13
9
 
14
10
  # An area related to the post, e.g. an electoral riding.
15
11
  belongs_to :area, index: true, class_name: 'Popolo::Area'
@@ -20,6 +16,10 @@ module Popolo
20
16
  # The address at which the post is based.
21
17
  embeds_many :addresses, as: :addressable, class_name: 'Popolo::Address'
22
18
 
23
- validates_presence_of :organization_id
19
+ # The role that the holder of the post fulfills. Roles should preferably
20
+ # belong to a controlled vocabulary.
21
+ field :role, type: String
22
+
23
+ validates_presence_of :role, :organization_id
24
24
  end
25
25
  end
@@ -0,0 +1,16 @@
1
+ <section>
2
+ <% if address.type? %>
3
+ <header>
4
+ <%=t address.type, default: address.type %>
5
+ </header>
6
+ <% end %>
7
+ <% if address.voice? %>
8
+ <p>Phone: <%= address.voice %></p>
9
+ <% end %>
10
+ <% if address.fax? %>
11
+ <p>Fax: <%= address.fax %></p>
12
+ <% end %>
13
+ <% if address.address? %>
14
+ <%= simple_format address.address %>
15
+ <% end %>
16
+ </section>
@@ -0,0 +1,13 @@
1
+ <nav>
2
+ <ul class="breadcrumb">
3
+ <li><%= link_to resource_collection_name.capitalize, collection_path %> <span class="divider">/</span></li>
4
+ <% ancestors = object.ancestors %>
5
+ <% ancestors.each_with_index do |ancestor,index| %>
6
+ <li>
7
+ <%= link_to ancestor.name, nested_resource_path(ancestors[0..index]) %>
8
+ <span class="divider">/</span>
9
+ </li>
10
+ <% end %>
11
+ <li class="active"><%= object.name %></li>
12
+ </ul>
13
+ </nav>
@@ -21,11 +21,11 @@
21
21
  <header>
22
22
  <h1><%= t(classification, scope: [:popolo, resource_collection_name, :classifications]) %></h1>
23
23
  </header>
24
- <ul>
24
+ <ol>
25
25
  <% documents.each do |document| %>
26
26
  <li><%= link_to document.name, nested_resources_path([object, document].compact) %></li>
27
27
  <% end %>
28
- </ul>
28
+ </ol>
29
29
  </section>
30
30
  <% end %>
31
31
  <% end %>
@@ -1,16 +1,4 @@
1
- <nav>
2
- <ul class="breadcrumb">
3
- <li><%= link_to resource_collection_name.capitalize, collection_path %> <span class="divider">/</span></li>
4
- <% ancestors = object.ancestors %>
5
- <% ancestors.each_with_index do |ancestor,index| %>
6
- <li>
7
- <%= link_to ancestor.name, nested_resource_path(ancestors[0..index]) %>
8
- <span class="divider">/</span>
9
- </li>
10
- <% end %>
11
- <li class="active"><%= object.name %></li>
12
- </ul>
13
- </nav>
1
+ <%= render partial: 'popolo/areas_or_organizations/breadcrumb', locals: {object: object} %>
14
2
 
15
3
  <% collection = object.children %>
16
4
  <% unless collection.empty? %>
@@ -20,11 +8,11 @@
20
8
  <header>
21
9
  <h1><%= t(classification, scope: [:popolo, resource_collection_name, :classifications]) %></h1>
22
10
  </header>
23
- <ul>
11
+ <ol>
24
12
  <% documents.each do |document| %>
25
13
  <li><%= link_to document.name, nested_resource_path([object, document]) %></li>
26
14
  <% end %>
27
- </ul>
15
+ </ol>
28
16
  </section>
29
17
  <% end %>
30
18
  <% end %>
@@ -0,0 +1,27 @@
1
+ <%= render partial: 'popolo/areas_or_organizations/breadcrumb', locals: {object: @organization} %>
2
+
3
+ <section>
4
+ <div class="media">
5
+ <% if @post.person && @post.person.image? %>
6
+ <span class="pull-left">
7
+ <%= image_tag(@post.person.image, class: 'media-object') %>
8
+ </span>
9
+ <% end %>
10
+ <div class="media-body">
11
+ <h4 class="media-heading"><%= @post.name %></h4>
12
+ <% if @post.person %>
13
+ <%= @post.person.name %>
14
+ <% end %>
15
+ </div>
16
+ </div>
17
+ <% if @post.person && @post.person.summary? %>
18
+ <p><%= @post.person.summary %></p>
19
+ <% end %>
20
+
21
+ <aside>
22
+ <% if @post.person && @post.person.email? %>
23
+ <p>Email: <%= mail_to @post.person.email %></p>
24
+ <% end %>
25
+ <%= render @post.addresses %>
26
+ </aside>
27
+ </section>
@@ -0,0 +1,23 @@
1
+ <%= render partial: 'popolo/areas_or_organizations/breadcrumb', locals: {object: @organization} %>
2
+
3
+ <section>
4
+ <h1><%= @organization.name %></h1>
5
+
6
+ <ol class="media-list">
7
+ <% @posts.asc(:sort_name).each do |post| %>
8
+ <li class="media">
9
+ <% if post.person && post.person.image? %>
10
+ <span class="pull-left">
11
+ <%= image_tag(post.person.image, class: 'image-object') %>
12
+ </span>
13
+ <% end %>
14
+ <div class="media-body">
15
+ <h4 class="media-heading"><%= link_to post.name, nested_organization_post_path(@organization.ancestors_and_self, post) %></h4>
16
+ <% if post.person %>
17
+ <%= post.person.name %>
18
+ <% end %>
19
+ </div>
20
+ </li>
21
+ <% end %>
22
+ </ol>
23
+ </section>
data/config/routes.rb CHANGED
@@ -6,7 +6,10 @@ Popolo::Engine.routes.draw do
6
6
 
7
7
  match 'areas/*path/areas' => 'areas#nested_index', as: 'nested_areas'
8
8
  match 'areas/*path' => 'areas#nested_show', as: 'nested_area'
9
+
9
10
  match 'organizations/*path/organizations' => 'organizations#nested_index', as: 'nested_organizations'
11
+ match 'organizations/*path/posts/:id' => 'organizations#post', as: 'nested_organization_post'
12
+ match 'organizations/*path/posts' => 'organizations#posts', as: 'nested_organization_posts'
10
13
  match 'organizations/*path' => 'organizations#nested_show', as: 'nested_organization'
11
14
 
12
15
  # A host application will sometimes complain about a missing `root_path`, even
@@ -10,6 +10,8 @@ module Popolo
10
10
  # The field used to sort the document.
11
11
  field :sort_name, type: String
12
12
 
13
+ index sort_name: 1
14
+
13
15
  validates_presence_of slug_source, :slug, :sort_name
14
16
 
15
17
  before_validation :set_slug_and_sort_name
@@ -1,3 +1,3 @@
1
1
  module Popolo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -25,12 +25,6 @@ describe Popolo::AreasController do
25
25
  assigns(:area).should == @area
26
26
  response.should be_success
27
27
  end
28
-
29
- it 'gets the requested area by slug' do
30
- get :show, id: @area.slug
31
- assigns(:area).should == @area
32
- response.should be_success
33
- end
34
28
  end
35
29
 
36
30
  describe 'GET nested_index' do
@@ -9,6 +9,7 @@ describe Popolo::OrganizationsController do
9
9
  @xyz = @organization.children.create name: 'XYZ, Inc.'
10
10
  @department = @xyz.children.create name: "Marketing Department"
11
11
  @branch = @department.children.create name: "Youth Branch"
12
+ @post = FactoryGirl.create :post, organization: @xyz
12
13
  end
13
14
 
14
15
  describe 'GET index' do
@@ -25,12 +26,6 @@ describe Popolo::OrganizationsController do
25
26
  assigns(:organization).should == @organization
26
27
  response.should be_success
27
28
  end
28
-
29
- it 'gets the requested organization by slug' do
30
- get :show, id: @organization.slug
31
- assigns(:organization).should == @organization
32
- response.should be_success
33
- end
34
29
  end
35
30
 
36
31
  describe 'GET nested_index' do
@@ -56,4 +51,20 @@ describe Popolo::OrganizationsController do
56
51
  expect {get :nested_show, path: 'acme-corporation/abc-inc/marketing-department'}.to raise_error(Mongoid::Errors::DocumentNotFound)
57
52
  end
58
53
  end
54
+
55
+ describe 'GET posts' do
56
+ it 'assigns the requested posts as @posts' do
57
+ get :posts, path: 'acme-corporation/xyz-inc'
58
+ assigns(:posts).to_a.should == [@post]
59
+ response.should be_success
60
+ end
61
+ end
62
+
63
+ describe 'GET post' do
64
+ it 'assigns the requested post as @post' do
65
+ get :post, path: 'acme-corporation/xyz-inc', id: 'marketing-director'
66
+ assigns(:post).should == @post
67
+ response.should be_success
68
+ end
69
+ end
59
70
  end
@@ -20,11 +20,5 @@ describe Popolo::PostsController do
20
20
  assigns(:post).should == @post
21
21
  response.should be_success
22
22
  end
23
-
24
- it 'gets the requested post by slug' do
25
- get :show, id: @post.slug
26
- assigns(:post).should == @post
27
- response.should be_success
28
- end
29
23
  end
30
24
  end