popolo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +41 -0
  3. data/Rakefile +16 -0
  4. data/app/assets/javascripts/popolo/application.js +13 -0
  5. data/app/assets/stylesheets/popolo/application.css +13 -0
  6. data/app/controllers/popolo/areas_controller.rb +48 -0
  7. data/app/controllers/popolo/organizations_controller.rb +48 -0
  8. data/app/controllers/popolo/people_controller.rb +12 -0
  9. data/app/controllers/popolo/posts_controller.rb +12 -0
  10. data/app/controllers/popolo_controller.rb +3 -0
  11. data/app/helpers/popolo_helper.rb +10 -0
  12. data/app/models/popolo/address.rb +27 -0
  13. data/app/models/popolo/area.rb +25 -0
  14. data/app/models/popolo/event.rb +46 -0
  15. data/app/models/popolo/identifier.rb +15 -0
  16. data/app/models/popolo/link.rb +16 -0
  17. data/app/models/popolo/membership.rb +25 -0
  18. data/app/models/popolo/organization.rb +32 -0
  19. data/app/models/popolo/other_name.rb +21 -0
  20. data/app/models/popolo/person.rb +49 -0
  21. data/app/models/popolo/post.rb +25 -0
  22. data/app/models/popolo/source.rb +29 -0
  23. data/app/views/popolo/areas/index.html.erb +1 -0
  24. data/app/views/popolo/areas/show.html.erb +1 -0
  25. data/app/views/popolo/areas_or_organizations/_index.html.erb +31 -0
  26. data/app/views/popolo/areas_or_organizations/_show.html.erb +30 -0
  27. data/app/views/popolo/organizations/index.html.erb +1 -0
  28. data/app/views/popolo/organizations/show.html.erb +1 -0
  29. data/app/views/popolo/people/index.html.erb +0 -0
  30. data/app/views/popolo/people/show.html.erb +0 -0
  31. data/app/views/popolo/posts/index.html.erb +0 -0
  32. data/app/views/popolo/posts/show.html.erb +0 -0
  33. data/config/routes.rb +15 -0
  34. data/lib/generators/popolo_generator.rb +36 -0
  35. data/lib/generators/templates/README +7 -0
  36. data/lib/popolo/engine.rb +7 -0
  37. data/lib/popolo/mixins/eventable.rb +15 -0
  38. data/lib/popolo/mixins/sluggable.rb +64 -0
  39. data/lib/popolo/version.rb +3 -0
  40. data/lib/popolo.rb +18 -0
  41. data/spec/controllers/popolo/areas_controller_spec.rb +59 -0
  42. data/spec/controllers/popolo/organizations_controller_spec.rb +59 -0
  43. data/spec/controllers/popolo/people_controller_spec.rb +30 -0
  44. data/spec/controllers/popolo/posts_controller_spec.rb +30 -0
  45. data/spec/controllers/popolo_controller_spec.rb +4 -0
  46. data/spec/dummy/Rakefile +7 -0
  47. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  48. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  49. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  50. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  51. data/spec/dummy/app/models/cat.rb +6 -0
  52. data/spec/dummy/app/models/dog.rb +10 -0
  53. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  54. data/spec/dummy/config/application.rb +62 -0
  55. data/spec/dummy/config/boot.rb +10 -0
  56. data/spec/dummy/config/environment.rb +5 -0
  57. data/spec/dummy/config/environments/development.rb +37 -0
  58. data/spec/dummy/config/environments/production.rb +67 -0
  59. data/spec/dummy/config/environments/test.rb +37 -0
  60. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  61. data/spec/dummy/config/initializers/session_store.rb +8 -0
  62. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  63. data/spec/dummy/config/locales/en.yml +5 -0
  64. data/spec/dummy/config/mongoid.yml +68 -0
  65. data/spec/dummy/config/routes.rb +3 -0
  66. data/spec/dummy/config.ru +4 -0
  67. data/spec/dummy/log/development.log +6 -0
  68. data/spec/dummy/log/test.log +35513 -0
  69. data/spec/dummy/public/404.html +26 -0
  70. data/spec/dummy/public/422.html +26 -0
  71. data/spec/dummy/public/500.html +25 -0
  72. data/spec/dummy/public/favicon.ico +0 -0
  73. data/spec/dummy/script/rails +6 -0
  74. data/spec/factories.rb +25 -0
  75. data/spec/helpers/popolo_helper_spec.rb +4 -0
  76. data/spec/models/popolo/address_spec.rb +4 -0
  77. data/spec/models/popolo/area_spec.rb +4 -0
  78. data/spec/models/popolo/event_spec.rb +7 -0
  79. data/spec/models/popolo/identifier_spec.rb +5 -0
  80. data/spec/models/popolo/link_spec.rb +5 -0
  81. data/spec/models/popolo/membership_spec.rb +27 -0
  82. data/spec/models/popolo/organization_spec.rb +25 -0
  83. data/spec/models/popolo/other_name_spec.rb +25 -0
  84. data/spec/models/popolo/person_spec.rb +25 -0
  85. data/spec/models/popolo/post_spec.rb +5 -0
  86. data/spec/models/popolo/source_spec.rb +7 -0
  87. data/spec/popolo/mixins/sluggable_spec.rb +153 -0
  88. data/spec/popolo_spec.rb +4 -0
  89. data/spec/routing/popolo/areas_routing_spec.rb +29 -0
  90. data/spec/routing/popolo/organizations_routing_spec.rb +29 -0
  91. data/spec/routing/popolo/people_routing_spec.rb +21 -0
  92. data/spec/routing/popolo/posts_routing_spec.rb +21 -0
  93. data/spec/spec_helper.rb +81 -0
  94. metadata +416 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
data/spec/factories.rb ADDED
@@ -0,0 +1,25 @@
1
+ # https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md
2
+ FactoryGirl.define do
3
+ factory :area, class: Popolo::Area do
4
+ name 'Foo'
5
+ end
6
+
7
+ factory :membership, class: Popolo::Membership do
8
+ person
9
+ organization
10
+ end
11
+
12
+ factory :organization, class: Popolo::Organization do
13
+ name 'ABC, Inc.'
14
+ end
15
+
16
+ factory :person, class: Popolo::Person do
17
+ name 'John Q. Public'
18
+ end
19
+
20
+ factory :post, class: Popolo::Post do
21
+ role 'Director'
22
+ person
23
+ organization
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe PopoloHelper do
4
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Address do
4
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Area do
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Event do
4
+ [:source, :url, :body, :issued_at].each do |attribute|
5
+ it {should validate_presence_of attribute}
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Identifier do
4
+ it {should validate_presence_of :identifier}
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Link do
4
+ it {should validate_presence_of :url}
5
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Membership do
4
+ [:organization_id, :person_id].each do |attribute|
5
+ it {should validate_presence_of attribute}
6
+ end
7
+
8
+ [:start_date, :end_date].each do |attribute|
9
+ it {
10
+ should validate_format_of(attribute).
11
+ # 4.1.2.2 Basic format
12
+ not_to_allow('20041231').
13
+ # 4.1.2.2 Extended format
14
+ to_allow('2004-12-31').
15
+ # 4.1.2.3 a) A specific month
16
+ to_allow('2004-01').
17
+ # 4.1.2.3 b) A specific year
18
+ to_allow('2004').
19
+ # 4.1.2.3 c) A specific century
20
+ not_to_allow('20').
21
+ # Avoid confusion with YYMMDD
22
+ not_to_allow('200401').
23
+ # Date and time of day.
24
+ not_to_allow('2004-12-31T00:00:00Z')
25
+ }
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Organization do
4
+ it {should validate_presence_of :name}
5
+
6
+ [:founding_date, :dissolution_date].each do |attribute|
7
+ it {
8
+ should validate_format_of(attribute).
9
+ # 4.1.2.2 Basic format
10
+ not_to_allow('20041231').
11
+ # 4.1.2.2 Extended format
12
+ to_allow('2004-12-31').
13
+ # 4.1.2.3 a) A specific month
14
+ to_allow('2004-01').
15
+ # 4.1.2.3 b) A specific year
16
+ to_allow('2004').
17
+ # 4.1.2.3 c) A specific century
18
+ not_to_allow('20').
19
+ # Avoid confusion with YYMMDD
20
+ not_to_allow('200401').
21
+ # Date and time of day.
22
+ not_to_allow('2004-12-31T00:00:00Z')
23
+ }
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::OtherName do
4
+ it {should validate_presence_of :name}
5
+
6
+ [:start_date, :end_date].each do |attribute|
7
+ it {
8
+ should validate_format_of(attribute).
9
+ # 4.1.2.2 Basic format
10
+ not_to_allow('20041231').
11
+ # 4.1.2.2 Extended format
12
+ to_allow('2004-12-31').
13
+ # 4.1.2.3 a) A specific month
14
+ to_allow('2004-01').
15
+ # 4.1.2.3 b) A specific year
16
+ to_allow('2004').
17
+ # 4.1.2.3 c) A specific century
18
+ not_to_allow('20').
19
+ # Avoid confusion with YYMMDD
20
+ not_to_allow('200401').
21
+ # Date and time of day.
22
+ not_to_allow('2004-12-31T00:00:00Z')
23
+ }
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Person do
4
+ it {should validate_presence_of :name}
5
+
6
+ [:birth_date, :death_date].each do |attribute|
7
+ it {
8
+ should validate_format_of(attribute).
9
+ # 4.1.2.2 Basic format
10
+ not_to_allow('20041231').
11
+ # 4.1.2.2 Extended format
12
+ to_allow('2004-12-31').
13
+ # 4.1.2.3 a) A specific month
14
+ to_allow('2004-01').
15
+ # 4.1.2.3 b) A specific year
16
+ to_allow('2004').
17
+ # 4.1.2.3 c) A specific century
18
+ not_to_allow('20').
19
+ # Avoid confusion with YYMMDD
20
+ not_to_allow('200401').
21
+ # Date and time of day.
22
+ not_to_allow('2004-12-31T00:00:00Z')
23
+ }
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Post do
4
+ it {should validate_presence_of :organization_id}
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Source do
4
+ [:name, :last_modified].each do |attribute|
5
+ it {should validate_presence_of attribute}
6
+ end
7
+ end
@@ -0,0 +1,153 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::Sluggable do
4
+ describe '.included' do
5
+ describe '#new' do
6
+ subject {Cat.new}
7
+
8
+ [:name, :slug, :sort_name].each do |attribute|
9
+ it {should validate_presence_of attribute}
10
+ end
11
+
12
+ context 'with a custom slug source' do
13
+ subject {Dog.new}
14
+
15
+ [:moniker, :slug, :sort_name].each do |attribute|
16
+ it {should validate_presence_of attribute}
17
+ end
18
+
19
+ it {should_not validate_presence_of :name}
20
+ end
21
+ end
22
+
23
+ describe '#slug_source' do
24
+ it 'should default to :name' do
25
+ Cat.slug_source.should == :name
26
+ end
27
+
28
+ context 'with a custom slug source' do
29
+ it 'should use the custom slug source' do
30
+ Dog.slug_source.should == :moniker
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '#create' do
36
+ it 'should set the slug' do
37
+ Cat.create(name: 'Foo').slug.should == 'foo'
38
+ end
39
+
40
+ it 'should not set the slug if it is already set' do
41
+ Cat.create(name: 'Foo', slug: 'bar').slug.should == 'bar'
42
+ end
43
+
44
+ it 'should not attempt to set the slug if the slug source is empty' do
45
+ expect {Cat.create!}.to raise_error(Mongoid::Errors::Validations)
46
+ end
47
+
48
+ it 'should prevent duplicate slugs' do
49
+ Cat.create name: 'Foo', slug: 'foo'
50
+ expect {Cat.with(safe: true).create(name: 'Bar', slug: 'foo')}.to raise_error(Moped::Errors::OperationFailure)
51
+ end
52
+
53
+ it 'should set the sort name' do
54
+ Cat.create(name: 'Foo').sort_name.should == 'Foo'
55
+ end
56
+
57
+ it 'should not set the sort name if it is already set' do
58
+ Cat.create(name: 'Foo', sort_name: 'Bar').sort_name.should == 'Bar'
59
+ end
60
+
61
+ context 'with a custom slug source' do
62
+ it 'should set the slug' do
63
+ Dog.create(moniker: 'Foo').slug.should == 'foo'
64
+ end
65
+
66
+ it 'should not set the slug if it is already set' do
67
+ Dog.create(moniker: 'Foo', slug: 'bar').slug.should == 'bar'
68
+ end
69
+
70
+ it 'should not attempt to set the slug if the slug source is empty' do
71
+ expect {Dog.create!}.to raise_error(Mongoid::Errors::Validations)
72
+ end
73
+
74
+ it 'should prevent duplicate slugs' do
75
+ Dog.create moniker: 'Foo', slug: 'foo'
76
+ expect {Dog.with(safe: true).create(moniker: 'Bar', slug: 'foo')}.to raise_error(Moped::Errors::OperationFailure)
77
+ end
78
+
79
+ it 'should set the sort name' do
80
+ Dog.create(moniker: 'Foo').sort_name.should == 'Foo'
81
+ end
82
+
83
+ it 'should not set the sort name if it is already set' do
84
+ Dog.create(moniker: 'Foo', sort_name: 'Bar').sort_name.should == 'Bar'
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#find_by_slug' do
90
+ let :resource do
91
+ Cat.create(name: 'Foo')
92
+ end
93
+
94
+ it 'should find a resource by its slug' do
95
+ Cat.find_by_slug(resource.slug).should == resource
96
+ end
97
+
98
+ it 'should find a resource by its slug source' do
99
+ Cat.find_by_slug(resource.name).should == resource
100
+ end
101
+
102
+ context 'with a custom slug source' do
103
+ let :resource do
104
+ Dog.create(moniker: 'Foo')
105
+ end
106
+
107
+ it 'should find a resource by its slug' do
108
+ Dog.find_by_slug(resource.slug).should == resource
109
+ end
110
+
111
+ it 'should find a resource by its slug source' do
112
+ Dog.find_by_slug(resource.moniker).should == resource
113
+ end
114
+ end
115
+ end
116
+
117
+ describe '#find_by_slug_or_id' do
118
+ let :resource do
119
+ Cat.create(name: 'Foo')
120
+ end
121
+
122
+ it 'should find a resource by its slug' do
123
+ Cat.find_by_slug_or_id(resource.slug).should == resource
124
+ end
125
+
126
+ it 'should find a resource by its slug source' do
127
+ Cat.find_by_slug(resource.name).should == resource
128
+ end
129
+
130
+ it 'should find a resource by its ID' do
131
+ Cat.find_by_slug_or_id(resource.id).should == resource
132
+ end
133
+
134
+ context 'with a custom slug source' do
135
+ let :resource do
136
+ Dog.create(moniker: 'Foo')
137
+ end
138
+
139
+ it 'should find a resource by its slug' do
140
+ Dog.find_by_slug_or_id(resource.slug).should == resource
141
+ end
142
+
143
+ it 'should find a resource by its slug' do
144
+ Dog.find_by_slug_or_id(resource.moniker).should == resource
145
+ end
146
+
147
+ it 'should find a resource by its ID' do
148
+ Dog.find_by_slug_or_id(resource.id).should == resource
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo do
4
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::AreasController do
4
+ describe 'routing' do
5
+ before :each do
6
+ @routes = Popolo::Engine.routes
7
+ end
8
+
9
+ it 'routes to #index' do
10
+ get('/areas').should route_to('popolo/areas#index')
11
+ end
12
+
13
+ it 'routes to #show' do
14
+ get('/areas/1').should route_to('popolo/areas#show', id: '1')
15
+ end
16
+
17
+ it 'routes to #show' do
18
+ get('/areas/foo').should route_to('popolo/areas#show', id: 'foo')
19
+ end
20
+
21
+ it 'routes to #nested_index' do
22
+ get('/areas/foo/areas').should route_to('popolo/areas#nested_index', path: 'foo')
23
+ end
24
+
25
+ it 'routes to #nested_show' do
26
+ get('/areas/foo/bar').should route_to('popolo/areas#nested_show', path: 'foo/bar')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::OrganizationsController do
4
+ describe 'routing' do
5
+ before :each do
6
+ @routes = Popolo::Engine.routes
7
+ end
8
+
9
+ it 'routes to #index' do
10
+ get('/organizations').should route_to('popolo/organizations#index')
11
+ end
12
+
13
+ it 'routes to #show' do
14
+ get('/organizations/1').should route_to('popolo/organizations#show', id: '1')
15
+ end
16
+
17
+ it 'routes to #show' do
18
+ get('/organizations/foo').should route_to('popolo/organizations#show', id: 'foo')
19
+ end
20
+
21
+ it 'routes to #nested_index' do
22
+ get('/organizations/foo/organizations').should route_to('popolo/organizations#nested_index', path: 'foo')
23
+ end
24
+
25
+ it 'routes to #nested_show' do
26
+ get('/organizations/foo/bar').should route_to('popolo/organizations#nested_show', path: 'foo/bar')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::PeopleController do
4
+ describe 'routing' do
5
+ before :each do
6
+ @routes = Popolo::Engine.routes
7
+ end
8
+
9
+ it 'routes to #index' do
10
+ get('/people').should route_to('popolo/people#index')
11
+ end
12
+
13
+ it 'routes to #show' do
14
+ get('/people/1').should route_to('popolo/people#show', id: '1')
15
+ end
16
+
17
+ it 'routes to #show' do
18
+ get('/people/foo').should route_to('popolo/people#show', id: 'foo')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popolo::PostsController do
4
+ describe 'routing' do
5
+ before :each do
6
+ @routes = Popolo::Engine.routes
7
+ end
8
+
9
+ it 'routes to #index' do
10
+ get('/posts').should route_to('popolo/posts#index')
11
+ end
12
+
13
+ it 'routes to #show' do
14
+ get('/posts/1').should route_to('popolo/posts#show', id: '1')
15
+ end
16
+
17
+ it 'routes to #show' do
18
+ get('/posts/foo').should route_to('popolo/posts#show', id: 'foo')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,81 @@
1
+ require 'spork'
2
+
3
+ Spork.prefork do
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+
6
+ require 'rails/application'
7
+ # Prevent Spork from caching the routes.
8
+ Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
9
+ # Prevent Spork from caching Popolo classes (see below).
10
+ Spork.trap_method(Rails::Application, :eager_load!)
11
+
12
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
13
+ require 'rspec/rails'
14
+
15
+ # Requires supporting ruby files with custom matchers and macros, etc,
16
+ # in spec/support/ and its subdirectories.
17
+ Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}
18
+
19
+ # Prevent Spork from caching Popolo classes (see above).
20
+ Rails.application.railties.all do |railtie|
21
+ unless railtie.respond_to?(:engine_name) && railtie.engine_name == 'popolo'
22
+ railtie.eager_load!
23
+ end
24
+ end
25
+
26
+ # Create non-Popolo indexes.
27
+ Rails.application.railties.engines.each do |engine|
28
+ unless engine.engine_name == 'popolo'
29
+ engine.paths["app/models"].expanded.each do |path|
30
+ Rails::Mongoid.create_indexes("#{path}/**/*.rb")
31
+ end
32
+ end
33
+ end
34
+
35
+ require 'database_cleaner'
36
+ require 'factory_girl_rails'
37
+ require 'mongoid-rspec'
38
+
39
+ RSpec.configure do |config|
40
+ config.include Mongoid::Matchers
41
+
42
+ config.mock_with :rspec
43
+
44
+ config.after(:each) do
45
+ DatabaseCleaner.clean
46
+ end
47
+
48
+ # http://railscasts.com/episodes/285-spork
49
+ config.treat_symbols_as_metadata_keys_with_true_values = true
50
+ config.run_all_when_everything_filtered = true
51
+ config.filter_run focus: true
52
+ end
53
+ end
54
+
55
+ Spork.each_run do
56
+ # DatabaseCleaner will not truncate system.indexes between tests, but it
57
+ # should be truncated before running the full test suite.
58
+ Mongoid::Sessions.default.drop
59
+
60
+ # It's now okay to load Popolo.
61
+ Rails.application.railties.engines.each do |engine|
62
+ if engine.engine_name == 'popolo'
63
+ engine.eager_load!
64
+ end
65
+ end
66
+
67
+ # Create Popolo indexes.
68
+ Rails.application.railties.engines.each do |engine|
69
+ if engine.engine_name == 'popolo'
70
+ engine.paths["app/models"].expanded.each do |path|
71
+ Rails::Mongoid.create_indexes("#{path}/**/*.rb")
72
+ end
73
+ end
74
+ end
75
+
76
+ # Create dummy indexes.
77
+ Rails::Mongoid.create_indexes(File.expand_path("../dummy/app/models/**/*.rb", __FILE__))
78
+
79
+ # @todo I18n.backend.reload!
80
+ FactoryGirl.reload
81
+ end