attributarchy 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +80 -0
  3. data/Rakefile +28 -0
  4. data/lib/attributarchy.rb +10 -0
  5. data/lib/attributarchy/controller_methods.rb +58 -0
  6. data/lib/attributarchy/helpers.rb +28 -0
  7. data/lib/attributarchy/version.rb +3 -0
  8. data/lib/tasks/attributarchy_tasks.rake +4 -0
  9. data/spec/controller_methods_spec.rb +78 -0
  10. data/spec/dummy/README.rdoc +261 -0
  11. data/spec/dummy/Rakefile +7 -0
  12. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  13. data/spec/dummy/app/assets/stylesheets/application.css +22 -0
  14. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  15. data/spec/dummy/app/controllers/examples_controller.rb +15 -0
  16. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  17. data/spec/dummy/app/views/examples/_continent.html.erb +1 -0
  18. data/spec/dummy/app/views/examples/_country.html.erb +1 -0
  19. data/spec/dummy/app/views/examples/index.html.erb +1 -0
  20. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  21. data/spec/dummy/config.ru +4 -0
  22. data/spec/dummy/config/application.rb +65 -0
  23. data/spec/dummy/config/boot.rb +10 -0
  24. data/spec/dummy/config/environment.rb +5 -0
  25. data/spec/dummy/config/environments/development.rb +31 -0
  26. data/spec/dummy/config/environments/production.rb +64 -0
  27. data/spec/dummy/config/environments/test.rb +35 -0
  28. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/spec/dummy/config/initializers/inflections.rb +15 -0
  30. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  31. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  32. data/spec/dummy/config/initializers/session_store.rb +8 -0
  33. data/spec/dummy/config/initializers/wrap_parameters.rb +10 -0
  34. data/spec/dummy/config/locales/en.yml +5 -0
  35. data/spec/dummy/config/routes.rb +4 -0
  36. data/spec/dummy/log/development.log +28885 -0
  37. data/spec/dummy/log/test.log +23070 -0
  38. data/spec/dummy/public/404.html +26 -0
  39. data/spec/dummy/public/422.html +26 -0
  40. data/spec/dummy/public/500.html +25 -0
  41. data/spec/dummy/public/favicon.ico +0 -0
  42. data/spec/dummy/script/rails +6 -0
  43. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  44. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  45. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  46. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  47. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  48. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  49. data/spec/fixtures/expectations/one_attributarchy.html +22 -0
  50. data/spec/fixtures/expectations/two_attributarchies.html +70 -0
  51. data/spec/fixtures/expectations/two_attributarchies_without_rendering_country.html +52 -0
  52. data/spec/fixtures/partials/_country.html.erb +15 -0
  53. data/spec/fixtures/partials/_state.html.erb +15 -0
  54. data/spec/helpers_spec.rb +219 -0
  55. data/spec/spec_helper.rb +51 -0
  56. data/spec/support/helpers.rb +27 -0
  57. data/spec/support/shared_examples_group_spec.rb +9 -0
  58. metadata +156 -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'
@@ -0,0 +1,22 @@
1
+ <div class="attributarchy">
2
+ <div class="country-attributarchy">
3
+ <section class="country">
4
+ <header>
5
+ <h1>United States</h1>
6
+ </header>
7
+ <div class="data">
8
+ <ul>
9
+ <li>United States, Colorado, Denver</li>
10
+ <li>United States, Colorado, Lakewood</li>
11
+ <li>United States, Illinois, Chicago</li>
12
+ <li>United States, Illinois, Westmont</li>
13
+ <li>United States, North Carolina, Charlotte</li>
14
+ <li>United States, North Carolina, Asheville</li>
15
+ </ul>
16
+ </div>
17
+ <div class="level">
18
+ 0
19
+ </div>
20
+ </section>
21
+ </div>
22
+ </div>
@@ -0,0 +1,70 @@
1
+ <div class="attributarchy">
2
+ <div class="country-attributarchy">
3
+ <section class="country">
4
+ <header>
5
+ <h1>United States</h1>
6
+ </header>
7
+ <div class="data">
8
+ <ul>
9
+ <li>United States, Colorado, Denver</li>
10
+ <li>United States, Colorado, Lakewood</li>
11
+ <li>United States, Illinois, Chicago</li>
12
+ <li>United States, Illinois, Westmont</li>
13
+ <li>United States, North Carolina, Charlotte</li>
14
+ <li>United States, North Carolina, Asheville</li>
15
+ </ul>
16
+ </div>
17
+ <div class="level">
18
+ 0
19
+ </div>
20
+ </section>
21
+ <div class="state-attributarchy">
22
+ <section class="state">
23
+ <header>
24
+ <h1>Colorado</h1>
25
+ </header>
26
+ <div class="data">
27
+ <ul>
28
+ <li>United States, Colorado, Denver</li>
29
+ <li>United States, Colorado, Lakewood</li>
30
+ </ul>
31
+ </div>
32
+ <div class="level">
33
+ 1
34
+ </div>
35
+ </section>
36
+ </div>
37
+ <div class="state-attributarchy">
38
+ <section class="state">
39
+ <header>
40
+ <h1>Illinois</h1>
41
+ </header>
42
+ <div class="data">
43
+ <ul>
44
+ <li>United States, Illinois, Chicago</li>
45
+ <li>United States, Illinois, Westmont</li>
46
+ </ul>
47
+ </div>
48
+ <div class="level">
49
+ 1
50
+ </div>
51
+ </section>
52
+ </div>
53
+ <div class="state-attributarchy">
54
+ <section class="state">
55
+ <header>
56
+ <h1>North Carolina</h1>
57
+ </header>
58
+ <div class="data">
59
+ <ul>
60
+ <li>United States, North Carolina, Charlotte</li>
61
+ <li>United States, North Carolina, Asheville</li>
62
+ </ul>
63
+ </div>
64
+ <div class="level">
65
+ 1
66
+ </div>
67
+ </section>
68
+ </div>
69
+ </div>
70
+ </div>
@@ -0,0 +1,52 @@
1
+ <div class="attributarchy">
2
+ <div class="country-attributarchy">
3
+ <div class="state-attributarchy">
4
+ <section class="state">
5
+ <header>
6
+ <h1>Colorado</h1>
7
+ </header>
8
+ <div class="data">
9
+ <ul>
10
+ <li>United States, Colorado, Denver</li>
11
+ <li>United States, Colorado, Lakewood</li>
12
+ </ul>
13
+ </div>
14
+ <div class="level">
15
+ 1
16
+ </div>
17
+ </section>
18
+ </div>
19
+ <div class="state-attributarchy">
20
+ <section class="state">
21
+ <header>
22
+ <h1>Illinois</h1>
23
+ </header>
24
+ <div class="data">
25
+ <ul>
26
+ <li>United States, Illinois, Chicago</li>
27
+ <li>United States, Illinois, Westmont</li>
28
+ </ul>
29
+ </div>
30
+ <div class="level">
31
+ 1
32
+ </div>
33
+ </section>
34
+ </div>
35
+ <div class="state-attributarchy">
36
+ <section class="state">
37
+ <header>
38
+ <h1>North Carolina</h1>
39
+ </header>
40
+ <div class="data">
41
+ <ul>
42
+ <li>United States, North Carolina, Charlotte</li>
43
+ <li>United States, North Carolina, Asheville</li>
44
+ </ul>
45
+ </div>
46
+ <div class="level">
47
+ 1
48
+ </div>
49
+ </section>
50
+ </div>
51
+ </div>
52
+ </div>
@@ -0,0 +1,15 @@
1
+ <section class="country">
2
+ <header>
3
+ <h1><%= group_value %></h1>
4
+ </header>
5
+ <div class="data">
6
+ <ul>
7
+ <%- group_data.each do |gd| -%>
8
+ <li><%= gd.values.join(', ') -%></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <div class="level">
13
+ <%= group_level %>
14
+ </div>
15
+ </section>
@@ -0,0 +1,15 @@
1
+ <section class="state">
2
+ <header>
3
+ <h1><%= group_value %></h1>
4
+ </header>
5
+ <div class="data">
6
+ <ul>
7
+ <%- group_data.each do |gd| -%>
8
+ <li><%= gd.values.join(', ') -%></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <div class="level">
13
+ <%= group_level %>
14
+ </div>
15
+ </section>
@@ -0,0 +1,219 @@
1
+ require 'spec_helper'
2
+
3
+ CountryStateCityStruct = Struct.new(:country, :state, :city)
4
+
5
+ module Attributarchy
6
+ describe Helpers do
7
+
8
+ subject { ControllerWithAttributarchy.new }
9
+ let(:data) { [
10
+ CountryStateCityStruct.new('United States', 'Colorado', 'Denver'),
11
+ CountryStateCityStruct.new('United States', 'Colorado', 'Lakewood'),
12
+ CountryStateCityStruct.new('United States', 'Illinois', 'Chicago'),
13
+ CountryStateCityStruct.new('United States', 'Illinois', 'Westmont'),
14
+ CountryStateCityStruct.new('United States', 'North Carolina', 'Charlotte'),
15
+ CountryStateCityStruct.new('United States', 'North Carolina', 'Asheville')
16
+ ] }
17
+ let(:attributarchy_view_path) { File.join(rails_view_path, subject.controller_name) }
18
+
19
+ describe '#build_attributarchy' do
20
+
21
+ context 'when a partial is missing' do
22
+ it 'should throw an ActionView::MissingTemplate exception' do
23
+ subject.stub(:attributarchy_configuration).and_return({
24
+ country: [:country],
25
+ without_rendering: {}
26
+ })
27
+ expect{ subject.build_attributarchy(:country, data) }.to raise_error ActionView::MissingTemplate
28
+ end
29
+ end
30
+
31
+ context 'with the default lookup path' do
32
+
33
+ before :each do
34
+ load_fixtures_into(attributarchy_view_path)
35
+ end
36
+
37
+ context 'with one attributarchy (country)' do
38
+
39
+ let(:output) { subject.build_attributarchy(:country, data) }
40
+ let(:tidied_output) { html_tidy(output) }
41
+ let(:tidied_expected_output) { html_tidy(fixture_content_of(attributarchy_view_path, 'one_attributarchy.html')) }
42
+
43
+ before :each do
44
+ subject.stub(:attributarchy_configuration).and_return({
45
+ country: [:country],
46
+ without_rendering: {}
47
+ })
48
+ end
49
+
50
+ it_behaves_like 'an attributarchy'
51
+
52
+ it 'should have one country attributarchy' do
53
+ expect(output).to have_tag('div.country-attributarchy', count: 1)
54
+ end
55
+
56
+ it 'should have no state attributarchies' do
57
+ expect(output).to_not have_tag('div.state-attributarchy')
58
+ end
59
+
60
+ it 'renders one attributarchy' do
61
+ expect(tidied_output).to eq(tidied_expected_output)
62
+ end
63
+
64
+ end
65
+
66
+ context 'with two attributarchies (country, state)' do
67
+
68
+ context 'when all attributarchies are rendered' do
69
+
70
+ let(:output) { subject.build_attributarchy(:country_and_state, data) }
71
+ let(:tidied_output) { html_tidy(output) }
72
+ let(:tidied_expected_output) { html_tidy(fixture_content_of(attributarchy_view_path, 'two_attributarchies.html')) }
73
+
74
+ before :each do
75
+ subject.stub(:attributarchy_configuration).and_return({
76
+ country_and_state: [:country, :state],
77
+ without_rendering: {}
78
+ })
79
+ end
80
+
81
+ it_behaves_like 'an attributarchy'
82
+
83
+ it 'should have one country attributarchy' do
84
+ expect(output).to have_tag('div.country-attributarchy', count: 1)
85
+ end
86
+
87
+ it 'should have three state attributarchies within the country' do
88
+ expect(output).to have_tag('div.country-attributarchy') do
89
+ with_tag('div.state-attributarchy', count: 3)
90
+ end
91
+ end
92
+
93
+ it 'renders two attributarchies' do
94
+ expect(tidied_output).to eq(tidied_expected_output)
95
+ end
96
+
97
+ end
98
+
99
+ context 'when an attributarchy has a non-rendering attribute' do
100
+
101
+ let(:output) { subject.build_attributarchy(:country_and_state, data) }
102
+ let(:tidied_output) { html_tidy(output) }
103
+ let(:tidied_expected_output) { html_tidy(fixture_content_of(attributarchy_view_path, 'two_attributarchies_without_rendering_country.html')) }
104
+
105
+ before :each do
106
+ subject.stub(:attributarchy_configuration).and_return({
107
+ country_and_state: [:country, :state],
108
+ without_rendering: { country: nil }
109
+ })
110
+ end
111
+
112
+ it_behaves_like 'an attributarchy'
113
+
114
+ it 'should have one country attributarchy but no country content' do
115
+ expect(output).to have_tag('div.country-attributarchy', count: 1)
116
+ expect(output).to_not have_tag('section.country')
117
+ end
118
+
119
+ it 'should have three state attributarchies within the country' do
120
+ expect(output).to have_tag('div.country-attributarchy') do
121
+ with_tag('div.state-attributarchy', count: 3)
122
+ end
123
+ end
124
+
125
+ it 'groups on both attributarchies but only renders the states' do
126
+ expect(tidied_output).to eq(tidied_expected_output)
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+
133
+ context 'with two attributarchies back-to-back (country; country, state)' do
134
+
135
+ let(:output) {
136
+ subject.build_attributarchy(:country, data) +
137
+ subject.build_attributarchy(:country_and_state, data)
138
+ }
139
+ let(:tidied_output) { html_tidy(output) }
140
+ let(:tidied_expected_output) {
141
+ html_tidy(
142
+ fixture_content_of(attributarchy_view_path, 'one_attributarchy.html') +
143
+ fixture_content_of(attributarchy_view_path, 'two_attributarchies.html')
144
+ )
145
+ }
146
+
147
+ before :each do
148
+ subject.stub(:attributarchy_configuration).and_return({
149
+ country: [:country],
150
+ country_and_state: [:country, :state],
151
+ without_rendering: {}
152
+ })
153
+ end
154
+
155
+ it_behaves_like 'an attributarchy'
156
+
157
+ it 'should have two attributarchies' do
158
+ expect(output).to have_tag('div.attributarchy', count: 2)
159
+ end
160
+
161
+ it 'should have one country in the first attributarchy' do
162
+ expect(output).to have_tag('div.attributarchy:nth-child(1) div.country-attributarchy', count: 1)
163
+ end
164
+
165
+ it 'should have no states in the first attributarchy' do
166
+ expect(output).to_not have_tag('div.attributarchy:nth-child(1) div.state-attributarchy')
167
+ end
168
+
169
+ it 'should have one country in the second attributarchy' do
170
+ expect(output).to have_tag('div.attributarchy:nth-child(2) div.country-attributarchy', count: 1)
171
+ end
172
+
173
+ it 'should have three states in the second attributarchy' do
174
+ expect(output).to have_tag('div.attributarchy:nth-child(2) div.country-attributarchy') do
175
+ with_tag('div.state-attributarchy', count: 3)
176
+ end
177
+ end
178
+
179
+ it 'renders two attributarchies back-to-back' do
180
+ expect(tidied_output).to eq(tidied_expected_output)
181
+ end
182
+
183
+ end
184
+ end
185
+
186
+ context 'with a specified lookup path' do
187
+
188
+ before :each do
189
+ lookup_path = File.join(attributarchy_view_path, 'lookup')
190
+ load_fixtures_into(lookup_path)
191
+ end
192
+
193
+ context 'with one attributarchy (country)' do
194
+
195
+ let(:output) { subject.build_attributarchy(:country, data) }
196
+ let(:expected_output) { html_tidy(fixture_content_of(lookup_path, 'one_attributarchy.html')) }
197
+
198
+ before :each do
199
+ subject.stub(:attributarchy_configuration).and_return({
200
+ country: [:country],
201
+ without_rendering: {}
202
+ })
203
+ end
204
+
205
+ it_behaves_like 'an attributarchy'
206
+
207
+ it 'should have one country attributarchy' do
208
+ expect(output).to have_tag('div.country-attributarchy', count: 1)
209
+ end
210
+
211
+ it 'should have no state attributarchies' do
212
+ expect(output).to_not have_tag('div.state-attributarchy')
213
+ end
214
+ end
215
+ end
216
+
217
+ end # /build_attributarchy
218
+ end # /Helpers
219
+ end # /Attributarchy