cullender 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/cullender/application.js +13 -0
  6. data/app/assets/javascripts/cullender/rules.js +46 -0
  7. data/app/assets/stylesheets/cullender/application.css +13 -0
  8. data/app/assets/stylesheets/cullender/rules.css.scss +15 -0
  9. data/app/controllers/cullender/rules_controller.rb +68 -0
  10. data/app/controllers/cullender_controller.rb +105 -0
  11. data/app/helpers/cullender/rules_helper.rb +136 -0
  12. data/app/models/cullender/rule.rb +204 -0
  13. data/app/views/cullender/rules/_form.html.erb +20 -0
  14. data/app/views/cullender/rules/_trigger_fields.html.erb +19 -0
  15. data/app/views/cullender/rules/create.js.erb +3 -0
  16. data/app/views/cullender/rules/index.html.erb +25 -0
  17. data/app/views/cullender/rules/new.html.erb +1 -0
  18. data/app/views/cullender/rules/show.html.erb +3 -0
  19. data/config/locales/en.yml +12 -0
  20. data/config/routes.rb +4 -0
  21. data/lib/cullender.rb +96 -0
  22. data/lib/cullender/controllers/filter_logic.rb +89 -0
  23. data/lib/cullender/controllers/scoped_views.rb +17 -0
  24. data/lib/cullender/core_ext/hash.rb +1 -0
  25. data/lib/cullender/core_ext/hash/deep_delete.rb +13 -0
  26. data/lib/cullender/engine.rb +15 -0
  27. data/lib/cullender/engine/routes.rb +306 -0
  28. data/lib/cullender/mapping.rb +139 -0
  29. data/lib/cullender/version.rb +3 -0
  30. data/lib/generators/cullender/cullender_generator.rb +66 -0
  31. data/lib/generators/cullender/install_generator.rb +18 -0
  32. data/lib/generators/cullender/orm_helpers.rb +32 -0
  33. data/lib/generators/cullender/templates/cullender.rb +3 -0
  34. data/lib/generators/cullender/templates/cullender_migration.rb +13 -0
  35. data/lib/tasks/cullender_tasks.rake +4 -0
  36. data/spec/controllers/cullender/rules_controller_spec.rb +180 -0
  37. data/spec/cullender/controllers/filter_logic_spec.rb +233 -0
  38. data/spec/dummy/README.rdoc +28 -0
  39. data/spec/dummy/Rakefile +6 -0
  40. data/spec/dummy/app/assets/javascripts/application.js +17 -0
  41. data/spec/dummy/app/assets/stylesheets/application.css +14 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  43. data/spec/dummy/app/controllers/events_controller.rb +60 -0
  44. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  45. data/spec/dummy/app/models/event.rb +16 -0
  46. data/spec/dummy/app/views/cullender/rules/_form.html.erb +33 -0
  47. data/spec/dummy/app/views/cullender/rules/index.html.erb +24 -0
  48. data/spec/dummy/app/views/cullender/rules/new.html.erb +1 -0
  49. data/spec/dummy/app/views/cullender/rules/show.html.erb +3 -0
  50. data/spec/dummy/app/views/events/_form.html.erb +21 -0
  51. data/spec/dummy/app/views/events/edit.html.erb +6 -0
  52. data/spec/dummy/app/views/events/index.html.erb +27 -0
  53. data/spec/dummy/app/views/events/new.html.erb +5 -0
  54. data/spec/dummy/app/views/events/show.html.erb +10 -0
  55. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  56. data/spec/dummy/bin/bundle +3 -0
  57. data/spec/dummy/bin/rails +4 -0
  58. data/spec/dummy/bin/rake +4 -0
  59. data/spec/dummy/config.ru +4 -0
  60. data/spec/dummy/config/application.rb +23 -0
  61. data/spec/dummy/config/boot.rb +9 -0
  62. data/spec/dummy/config/database.yml +25 -0
  63. data/spec/dummy/config/environment.rb +5 -0
  64. data/spec/dummy/config/environments/development.rb +27 -0
  65. data/spec/dummy/config/environments/production.rb +80 -0
  66. data/spec/dummy/config/environments/test.rb +36 -0
  67. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/spec/dummy/config/initializers/cullender.rb +3 -0
  69. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  70. data/spec/dummy/config/initializers/inflections.rb +16 -0
  71. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  72. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  73. data/spec/dummy/config/initializers/session_store.rb +3 -0
  74. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  75. data/spec/dummy/config/locales/cullender.en.yml +12 -0
  76. data/spec/dummy/config/locales/en.yml +23 -0
  77. data/spec/dummy/config/routes.rb +5 -0
  78. data/spec/dummy/db/development.sqlite3 +0 -0
  79. data/spec/dummy/db/migrate/123344556676_create_cullender_tables.rb +12 -0
  80. data/spec/dummy/db/schema.rb +24 -0
  81. data/spec/dummy/db/test.sqlite3 +0 -0
  82. data/spec/dummy/log/development.log +9987 -0
  83. data/spec/dummy/log/test.log +19786 -0
  84. data/spec/dummy/public/404.html +27 -0
  85. data/spec/dummy/public/422.html +26 -0
  86. data/spec/dummy/public/500.html +26 -0
  87. data/spec/dummy/public/favicon.ico +0 -0
  88. data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  89. data/spec/dummy/tmp/cache/assets/development/sprockets/268a828ee4997cf5c19106e5f00fcfb8 +0 -0
  90. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  91. data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  92. data/spec/dummy/tmp/cache/assets/development/sprockets/56b2eb9b46b9aca7e86b5132ddf0d9de +0 -0
  93. data/spec/dummy/tmp/cache/assets/development/sprockets/750887406b3e8dacb2b03f986330932d +0 -0
  94. data/spec/dummy/tmp/cache/assets/development/sprockets/750b42e431d194c41f5b1cde4a257e47 +0 -0
  95. data/spec/dummy/tmp/cache/assets/development/sprockets/921642fe740290e9e5e88a706e5a562c +0 -0
  96. data/spec/dummy/tmp/cache/assets/development/sprockets/a967ed3fc5f8406f3ff72180775f1b40 +0 -0
  97. data/spec/dummy/tmp/cache/assets/development/sprockets/ae74bf4fc3fd20e7f7b98860b8ef0f74 +0 -0
  98. data/spec/dummy/tmp/cache/assets/development/sprockets/c7dbd1f5acc2d5bc078363f4f3c70c54 +0 -0
  99. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  100. data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  101. data/spec/dummy/tmp/cache/assets/development/sprockets/d995daf8d6f36c27b6e9d1b4672eaf1e +0 -0
  102. data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  103. data/spec/helpers/cullender/rules_helper_spec.rb +360 -0
  104. data/spec/models/cullender/rule_spec.rb +425 -0
  105. data/spec/requests/rules_spec.rb +19 -0
  106. data/spec/spec_helper.rb +60 -0
  107. metadata +319 -0
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
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
+ <p>If you are the application owner check the logs for more information.</p>
26
+ </body>
27
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
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,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
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
+ <p>If you are the application owner check the logs for more information.</p>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,360 @@
1
+ require 'spec_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the EventsHelper. For example:
5
+ #
6
+ # describe EventsHelper do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # helper.concat_strings("this","that").should == "this that"
10
+ # end
11
+ # end
12
+ # end
13
+ describe Cullender::RulesHelper do
14
+
15
+
16
+ describe "#cullender_collection_or_select" do
17
+ before(:each) do
18
+ helper.stub(:nested_property_prefix).with([]).and_return("prefix")
19
+ end
20
+ context "is base" do
21
+ it "renders the attribute select menu and OR submit btn" do
22
+ html = helper.cullender_collection_or_select(["attr1", "attr2"], [], {:base => true})
23
+ html.should have_selector("select#or_raise_fieldprefix", :text => "attr1\nattr2")
24
+ html.should have_selector("input[type='submit'][name='or[raise]prefix']")
25
+ end
26
+ end
27
+ context "is not a base" do
28
+ it "renders the attribute select menu and OR submit btn" do
29
+ html = helper.cullender_collection_or_select(["attr1", "attr2"])
30
+ html.should have_selector("select#or_fieldprefix", :text => "attr1\nattr2")
31
+ html.should have_selector("input[type='submit'][name='or[commit]prefix']")
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#cullender_collection_and_select" do
37
+ before(:each) do
38
+ helper.stub(:nested_property_prefix).with([]).and_return("prefix")
39
+ helper.stub(:option_for_select).and_return("options_for_select")
40
+ end
41
+ it "renders the attribute select menu and AND submit btn" do
42
+ html = helper.cullender_collection_and_select(["attr1", "attr2"])
43
+ html.should have_selector("select#and_fieldprefix", :text => "attr1\nattr2")
44
+ html.should have_selector("input[type='submit'][name='and[commit]prefix']")
45
+ end
46
+ end
47
+
48
+
49
+ describe "#link_to_filter" do
50
+ before(:each) do
51
+ controller.params.merge!(:controller => "cullender/rules", :action => "index", :use_route => :cullender)
52
+ @options = {}
53
+ end
54
+ it "doesn't modify the params hash" do
55
+ params = controller.params
56
+ helper.link_to_filter(:attribute, "Name")
57
+ controller.params == params
58
+ end
59
+ context "with attribute in the filter" do
60
+ before(:each) do
61
+ controller.params.merge!(:filter => {:attribute => {"v" => "value"}})
62
+ end
63
+ it "returns the text of the attribute" do
64
+ html = helper.link_to_filter(:attribute, "Name")
65
+ html.should include "Name"
66
+ end
67
+
68
+ end
69
+ context "without the attribute in the filter" do
70
+ it "returns a link to filter by the attribute" do
71
+ html = helper.link_to_filter(:attribute, "Name")
72
+ html.should have_selector("a", :text => "Name")
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#remove_filter_link" do
78
+ before(:each) do
79
+ controller.params.merge!(:controller => "cullender/rules", :action => "index", :use_route => :cullender)
80
+ @options = {}
81
+ end
82
+ it "doesn't modify the params hash" do
83
+ params = controller.params
84
+ helper.remove_filter_link(:attribute, "value", 2)
85
+ controller.params == params
86
+ end
87
+ context "with attribute in the filter" do
88
+ before(:each) do
89
+ controller.params.deep_merge!({:filter => {"attribute" => {"o" => 1, "v" => "value"}}})
90
+ end
91
+ it "returns a link to remove the filter" do
92
+ html = helper.remove_filter_link(:attribute, "value", 2)
93
+ html.should have_selector("a", :text => "remove")
94
+ end
95
+ end
96
+ context "without attribute in the filter" do
97
+ it "returns the count" do
98
+ html = helper.remove_filter_link(:attribute, "value", 2)
99
+ html.should have_selector("span", :text => "2")
100
+ end
101
+ end
102
+ end
103
+
104
+ # def render_property_tree(name, hash, options = {}, hierarchy = [], &block)
105
+ # options.merge!(:class => "group level_#{hierarchy.length}")
106
+ # last_key = hash.keys.last
107
+ # html = content_tag :div, options do
108
+ # hash.each do |field, value|
109
+ # if value.keys.include?("o")
110
+ # block.call property_item(name, field, value, hierarchy), last_key == field ? 1 : -1, hierarchy
111
+ # else
112
+ # hierarchy.push(field)
113
+ # block.call render_property_tree(name, value, {}, hierarchy, &block), last_key == field ? 0 : -1, hierarchy
114
+ # end
115
+ # end
116
+ # end if hash.present?
117
+ # hierarchy.pop()
118
+ # html
119
+ # end
120
+ describe "#render_property_tree" do
121
+ context "with an empty hash" do
122
+ it "returns nil" do
123
+ helper.render_property_tree("f", {}, {}).should be_nil
124
+ end
125
+ end
126
+ context "hash value has name and value key" do
127
+ it "should render the next level of the hash" do
128
+ inner_hash = {:these => {"o" => 1, "v" => "values"}}
129
+ helper.should_receive(:property_item).with("f", :these, {:type =>"string"}, {"o" => 1, "v" => "values"}, []).once
130
+ helper.render_property_tree("f", {:these => {:type => "string"}}, inner_hash, {}, []) do |a, b, c|
131
+ "#{a}, #{b}, #{c}"
132
+ end
133
+ end
134
+ end
135
+ context "hash value does not have name and value key" do
136
+ it "should render the next level of the hash" do
137
+ inner_hash = {"these" => {"o" => 1, "v" => "values"}}
138
+ html = helper.render_property_tree("f", {:these => {:type => "text_field"}}, {"key" => inner_hash}, {}, []) do |a, b, c|
139
+ "#{a}, #{b}, #{c}"
140
+ end
141
+ html.should have_selector("div[class='group level_0']")
142
+ end
143
+ end
144
+ end
145
+
146
+ describe "#property_item" do
147
+ before(:each) do
148
+ helper.stub(:nested_property_prefix).and_return("prefix")
149
+ helper.stub(:property_value_field).and_return("")
150
+ helper.should_receive(:property_value_field).once
151
+ # Cullender::Event.stub(:field_operators).with('field_name').and_return({"name1" => "value1", "name2" => "value2", "name3" => "value3"})
152
+ # Cullender::Event.stub(:properties).and_return(['field_name', 'field1', 'field2', 'field3'])
153
+ # Cullender::Event.stub(:property_types).and_return({'field_name' => 'string', 'field2' => 'string', 'field3' => 'string'})
154
+
155
+ end
156
+ it "wraps the content with a tag with the field name as a class" do
157
+ html = helper.property_item("name", :field_name, {:type => "string"}, {}, [1,2,3])
158
+ html.should have_selector("div[class='item field_name']")
159
+ end
160
+
161
+ it "is html safe" do
162
+ html = helper.property_item("name", :field_name, {:type => "string"}, {}, [1,2,3])
163
+ html.should be_html_safe
164
+ end
165
+
166
+ it "returns a label with the field name" do
167
+ html = helper.property_item("name", :field_name, {:type => "string"}, {}, [1,2,3])
168
+ html.should have_selector("label[for='prefix[field_name][v]']", :text => "field_name")
169
+ end
170
+ # it "returns a hidden field with the field name" do
171
+ # html = helper.property_item("name", "field_name", {}, [1,2,3])
172
+ # puts html
173
+ # html.should have_selector("input[name='prefix[n]'][type='hidden']")
174
+ # end
175
+
176
+ context "without an operator set in the value_hash" do
177
+ it "returns a select menu to select an operator" do
178
+ html = helper.property_item("name", :field_name, {:type => "string"}, {}, [1,2,3])
179
+ html.should have_selector("select[name='prefix[field_name][o]']")
180
+ (1..3).each {|i| html.should have_selector("option[value='term']", :text => I18n.t("cullender.operators.term"))}
181
+ end
182
+ end
183
+
184
+ context "with an operator set in the value_hash" do
185
+ it "returns a select menu with the operator selected" do
186
+ html = helper.property_item("name", :field_name, {:type => "string"}, {"o" => "term"}, [1,2,3])
187
+ html.should have_selector("option[value='term'][selected='selected']")
188
+ end
189
+ end
190
+ end
191
+
192
+ describe "#property_value_field" do
193
+ context "with invalid value" do
194
+ before(:each) do
195
+ helper.stub(:call_options).with("field_name").and_return({:class => "my_property"})
196
+ end
197
+ context "when field type is a number" do
198
+ it "returns a number field with the value set" do
199
+ # Cullender::Event.stub(:field_type).with("field_name").and_return("number")
200
+ html = helper.property_value_field("field_name", "number_field", nil, {}, "prefix")
201
+ html.should have_selector("input[type='number'][name='prefix[field_name][v]']")
202
+ end
203
+ end
204
+ context "when field type is a range" do
205
+ it "returns a range field with the value set" do
206
+ # Cullender::Event.stub(:field_type).with("field_name").and_return("range")
207
+ html = helper.property_value_field("field_name", "range_field", nil, {}, "prefix")
208
+ html.should have_selector("input[type='range'][name='prefix[field_name][v]']")
209
+ end
210
+ end
211
+ context "when field type is a select menu" do
212
+ it "returns a select menu with the value set" do
213
+ helper.stub(:options_for_select).with({}, nil).and_return("options_for_select")
214
+ # Cullender::Event.stub(:field_type).with("field_name").and_return("select")
215
+ html = helper.property_value_field("field_name", "select", nil, {}, "prefix")
216
+ html.should have_selector("select[name='prefix[field_name][v]']", :text => "options_for_select")
217
+ end
218
+ end
219
+ context "when field type is text" do
220
+ # it "returns a text field with the value set" do
221
+ # Event.stub(:field_type).with("field_name").and_return(Event::TEXT)
222
+ # html = helper.property_value_field("field_name", nil, "prefix")
223
+ # html.should have_selector("input", :type => "text", :name => "prefix[v]", :class => "my_property")
224
+ # end
225
+ end
226
+ context "when field type is not found" do
227
+ it "returns a text field with the value set" do
228
+ # Cullender::Event.stub(:field_type).with("field_name").and_return(3454)
229
+ html = helper.property_value_field("field_name", "text_field", nil, {}, "prefix")
230
+ html.should have_selector("input[type='text'][name='prefix[field_name][v]']")
231
+ end
232
+ end
233
+ context "when field type is datetime" do
234
+ it "returns datetime select menus with the value set" do
235
+ time = Time.zone.now
236
+ helper.stub(:set_datetime).and_return(time)
237
+ # Cullender::Event.stub(:field_type).with("field_name").and_return("datetime")
238
+ html = helper.property_value_field("field_name", "datetime", nil, {}, "prefix")
239
+ html.should have_selector("select[name='prefix[field_name][v][year]']")
240
+ html.should have_selector("select[name='prefix[field_name][v][month]']")
241
+ html.should have_selector("select[name='prefix[field_name][v][day]']")
242
+ html.should have_selector("select[name='prefix[field_name][v][hour]']")
243
+ html.should have_selector("select[name='prefix[field_name][v][minute]']")
244
+ end
245
+ end
246
+ context "when field type is date" do
247
+ it "returns date select menus with the value set" do
248
+ date = Date.today
249
+ helper.stub(:set_date).and_return(date)
250
+ # Cullender::Event.stub(:field_type).with("field_name").and_return("date")
251
+ html = helper.property_value_field("field_name", "date", nil, {}, "prefix")
252
+ html.should have_selector("select[name='prefix[field_name][v][year]']")
253
+ html.should have_selector("select[name='prefix[field_name][v][month]']")
254
+ html.should have_selector("select[name='prefix[field_name][v][day]']")
255
+ end
256
+ end
257
+ end
258
+
259
+ context "with a valid value" do
260
+ before(:each) do
261
+ helper.stub(:call_options).with("field_name").and_return({})
262
+ end
263
+ context "when field type is a number" do
264
+ it "returns a number field with the value set" do
265
+ # Cullender::Event.stub(:field_type).with("field_name").and_return("number")
266
+ html = helper.property_value_field("field_name", "number_field", 3, {}, "prefix")
267
+ html.should have_selector("input[type='number'][name ='prefix[field_name][v]'][value='3']")
268
+ end
269
+ end
270
+ context "when field type is a range" do
271
+ it "returns a range field with the value set" do
272
+ # Cullender::Event.stub(:field_type).with("field_name").and_return("range")
273
+ html = helper.property_value_field("field_name", "range_field", 3, {}, "prefix")
274
+ html.should have_selector("input[type='range'][name ='prefix[field_name][v]'][value='3']")
275
+ end
276
+ end
277
+ context "when field type is text" do
278
+ # it "returns a text field with the value set" do
279
+ # Event.stub(:field_type).with("field_name").and_return(Event::TEXT)
280
+ # html = helper.property_value_field("field_name", "my_value", "prefix")
281
+ # html.should have_selector("input", :type => "text", :name => "prefix[v]", :value => "my_value")
282
+ # end
283
+ end
284
+ end
285
+ end
286
+
287
+
288
+ # def nested_property_prefix(hierarchy)
289
+ # "f#{hierarchy.inject("") {|result, item| result += "[#{item}]"}}"
290
+ # end
291
+ describe "#nested_property_prefix" do
292
+ it "returns a string with the proper hash code" do
293
+ helper.nested_property_prefix([1,2,3,4,5]).should == "[1][2][3][4][5]"
294
+ end
295
+ it "returns a string with the proper hash code and a prefix" do
296
+ helper.nested_property_prefix([1,2,3,4,5], "pre").should == "pre[1][2][3][4][5]"
297
+ end
298
+ end
299
+
300
+ describe ".formatted_triggers" do
301
+ it "displays the 'AND'ed triggers" do
302
+ input = {"amount"=>{"o"=>"lt", "v"=>"fsfdb"}, "card_number"=>{"o"=>"gt", "v"=>"fdbsb"}, "start_at"=>{"o"=>"gt", "v"=>"dfbsb"}}
303
+ output = "(amount < fsfdb AND card_number > fdbsb AND start_at > dfbsb)"
304
+ helper.formatted_triggers(input).should eql(output)
305
+ end
306
+
307
+ it "displays nested 'OR'ed triggers" do
308
+ input = {"0"=>{"0"=>{"amount"=>{"o"=>"lt", "v"=>"fsfdb"}, "card_number"=>{"o"=>"gt", "v"=>"fdbsb"}, "start_at"=>{"o"=>"gt", "v"=>"dfbsb"}}, "1"=>{"card_bank_number"=>{"o"=>"gt", "v"=>"fbdsb"}}}, "1"=>{"card_bank_number"=>{"o"=>"gt", "v"=>"fsdbfd"}}}
309
+ output = "(((amount < fsfdb AND card_number > fdbsb AND start_at > dfbsb) OR (card_bank_number > fbdsb)) OR (card_bank_number > fsdbfd))"
310
+ helper.formatted_triggers(input).should eql(output)
311
+ end
312
+
313
+ end
314
+
315
+ describe ".filter_to_s" do
316
+ it "writes the filter as a string" do
317
+ helper.filter_to_s("amount", {"o"=>"lt", "v"=>"fsfdb"}).should eql("amount < fsfdb")
318
+ end
319
+ end
320
+
321
+ # describe "#format_for_datatype" do
322
+ # it "calls number_to_currency when type is a currency" do
323
+ # helper.should_receive(:number_to_currency).with(123.23)
324
+ # helper.format_for_datatype(123.23, Event::CURRENCY)
325
+ # end
326
+ # it "calls short localize when type is a date" do
327
+ # I18n.should_receive(:localize).with(Time.zone.at(1333078177), :format => :short)
328
+ # helper.format_for_datatype(1333078177, Event::DATE)
329
+ # end
330
+ # it "calls short localize when type is a datetime" do
331
+ # I18n.should_receive(:localize).with(Time.zone.at(1333078177), :format => :long)
332
+ # helper.format_for_datatype(1333078177, Event::DATETIME)
333
+ # end
334
+
335
+ # it "calls number_with_delimiter when type is an integer" do
336
+ # helper.should_receive(:number_with_delimiter).with(12323)
337
+ # helper.format_for_datatype(12323, Event::INTEGER)
338
+ # end
339
+
340
+ # it "calls number_with_precision when type is an decimal" do
341
+ # helper.should_receive(:number_with_precision).with(12323.23242)
342
+ # helper.format_for_datatype(12323.23242, Event::DECIMAL)
343
+ # end
344
+
345
+ # it "calls number_to_percentage when type is a percentage" do
346
+ # helper.should_receive(:number_to_percentage).with(12)
347
+ # helper.format_for_datatype(12, Event::PERCENTAGE)
348
+ # end
349
+
350
+ # it "calls number_to_human_size when type is a filesize" do
351
+ # helper.should_receive(:number_to_human_size).with(1333078177)
352
+ # helper.format_for_datatype(1333078177, Event::FILESIZE)
353
+ # end
354
+
355
+ # it "returns the value if case is not present" do
356
+ # helper.format_for_datatype(1333078177, 9999).should == 1333078177
357
+ # end
358
+ # end
359
+
360
+ end