will_filter 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/.loadpath +12 -0
  2. data/.project +18 -0
  3. data/CHANGELOG.rdoc +1 -0
  4. data/Gemfile +32 -0
  5. data/Gemfile.lock +73 -0
  6. data/LICENSE +18 -0
  7. data/README.rdoc +74 -0
  8. data/Rakefile +54 -0
  9. data/VERSION +1 -0
  10. data/app/controllers/application_controller.rb +27 -0
  11. data/app/controllers/will_filter/calendar_controller.rb +31 -0
  12. data/app/controllers/will_filter/exporter_controller.rb +122 -0
  13. data/app/controllers/will_filter/filter_controller.rb +107 -0
  14. data/app/helpers/application_helper.rb +26 -0
  15. data/app/models/will_filter/filter.rb +694 -0
  16. data/app/views/layouts/application.html.erb +11 -0
  17. data/app/views/will_filter/calendar/_annual.html.erb +14 -0
  18. data/app/views/will_filter/calendar/_month.html.erb +39 -0
  19. data/app/views/will_filter/calendar/_quarter.html.erb +15 -0
  20. data/app/views/will_filter/calendar/index.html.erb +52 -0
  21. data/app/views/will_filter/common/_actions_bar.html.erb +5 -0
  22. data/app/views/will_filter/common/_results_table.html.erb +129 -0
  23. data/app/views/will_filter/common/_scripts.html.erb +10 -0
  24. data/app/views/will_filter/exporter/export.html.erb +11 -0
  25. data/app/views/will_filter/exporter/index.html.erb +47 -0
  26. data/app/views/will_filter/filter/_condition.html.erb +30 -0
  27. data/app/views/will_filter/filter/_conditions.html.erb +56 -0
  28. data/app/views/will_filter/filter/_container.html.erb +31 -0
  29. data/app/views/will_filter/filter/containers/_blank.html.erb +1 -0
  30. data/app/views/will_filter/filter/containers/_boolean.html.erb +5 -0
  31. data/app/views/will_filter/filter/containers/_date.html.erb +12 -0
  32. data/app/views/will_filter/filter/containers/_date_range.html.erb +20 -0
  33. data/app/views/will_filter/filter/containers/_date_time.html.erb +12 -0
  34. data/app/views/will_filter/filter/containers/_date_time_range.html.erb +20 -0
  35. data/app/views/will_filter/filter/containers/_list.html.erb +7 -0
  36. data/app/views/will_filter/filter/containers/_numeric_range.html.erb +13 -0
  37. data/app/views/will_filter/filter/containers/_text.html.erb +7 -0
  38. data/app/views/will_filter/filter/index.html.erb +4 -0
  39. data/config/application.rb +45 -0
  40. data/config/boot.rb +6 -0
  41. data/config/database.yml +22 -0
  42. data/config/environment.rb +13 -0
  43. data/config/environments/development.rb +26 -0
  44. data/config/environments/production.rb +49 -0
  45. data/config/environments/test.rb +38 -0
  46. data/config/routes.rb +64 -0
  47. data/config/will_filter/config.yml +97 -0
  48. data/config.ru +4 -0
  49. data/db/development.sqlite3 +0 -0
  50. data/db/migrate/20090730070119_create_will_filter_tables.rb +19 -0
  51. data/db/seeds.rb +7 -0
  52. data/db/test.sqlite3 +0 -0
  53. data/doc/README_FOR_APP +2 -0
  54. data/examples/README +1 -0
  55. data/lib/application_helper.rb +45 -0
  56. data/lib/core_ext/active_record/base.rb +44 -0
  57. data/lib/core_ext/array.rb +34 -0
  58. data/lib/core_ext/object.rb +34 -0
  59. data/lib/generators/will_filter/templates/config.yml +97 -0
  60. data/lib/generators/will_filter/templates/create_will_filter_tables.rb +19 -0
  61. data/lib/generators/will_filter/will_filter_generator.rb +24 -0
  62. data/lib/tasks/.gitkeep +0 -0
  63. data/lib/tasks/will_filter_tasks.rake +32 -0
  64. data/lib/will_filter/calendar.rb +168 -0
  65. data/lib/will_filter/common_methods.rb +49 -0
  66. data/lib/will_filter/config.rb +104 -0
  67. data/lib/will_filter/containers/boolean.rb +43 -0
  68. data/lib/will_filter/containers/date.rb +51 -0
  69. data/lib/will_filter/containers/date_range.rb +56 -0
  70. data/lib/will_filter/containers/date_time.rb +50 -0
  71. data/lib/will_filter/containers/date_time_range.rb +64 -0
  72. data/lib/will_filter/containers/filter_list.rb +59 -0
  73. data/lib/will_filter/containers/list.rb +56 -0
  74. data/lib/will_filter/containers/nil.rb +45 -0
  75. data/lib/will_filter/containers/numeric.rb +52 -0
  76. data/lib/will_filter/containers/numeric_delimited.rb +50 -0
  77. data/lib/will_filter/containers/numeric_range.rb +60 -0
  78. data/lib/will_filter/containers/single_date.rb +57 -0
  79. data/lib/will_filter/containers/text.rb +45 -0
  80. data/lib/will_filter/containers/text_delimited.rb +51 -0
  81. data/lib/will_filter/engine.rb +11 -0
  82. data/lib/will_filter/filter_condition.rb +59 -0
  83. data/lib/will_filter/filter_container.rb +73 -0
  84. data/lib/will_filter/filter_exception.rb +27 -0
  85. data/lib/will_filter.rb +15 -0
  86. data/pkg/will_filter-0.1.0.gem +0 -0
  87. data/pkg/will_filter-0.1.1.gem +0 -0
  88. data/public/404.html +26 -0
  89. data/public/422.html +26 -0
  90. data/public/500.html +26 -0
  91. data/public/favicon.ico +0 -0
  92. data/public/robots.txt +5 -0
  93. data/public/will_filter/images/buttons.png +0 -0
  94. data/public/will_filter/images/calendar.png +0 -0
  95. data/public/will_filter/images/clock.png +0 -0
  96. data/public/will_filter/images/close.gif +0 -0
  97. data/public/will_filter/images/results_table_th_active.gif +0 -0
  98. data/public/will_filter/images/sort_arrow_all.gif +0 -0
  99. data/public/will_filter/images/sort_bg.gif +0 -0
  100. data/public/will_filter/images/spinner.gif +0 -0
  101. data/public/will_filter/javascripts/will_filter.js +568 -0
  102. data/public/will_filter/javascripts/will_filter_prototype_effects.js +15 -0
  103. data/public/will_filter/stylesheets/will_filter.css +168 -0
  104. data/script/rails +6 -0
  105. data/test/functional/models/will_filter/filter_test.rb +297 -0
  106. data/test/performance/browsing_test.rb +9 -0
  107. data/test/test_helper.rb +71 -0
  108. data/uninstall.rb +24 -0
  109. data/will_filter.gemspec +7 -0
  110. metadata +208 -0
@@ -0,0 +1,168 @@
1
+ .wf_container {padding:0px; background:#f1f4f9; margin:0px; margin-bottom:10px; font-size: 12px; font-family: Arial; width: 100%; border:solid 1px #e8e8e8;border-color:#e8e8e8 #bababa #bababa #e8e8e8;}
2
+ .wf_container input {border: 1px solid #ccc; font-size: 12px; font-family: Arial; margin:0px; padding: 2px !important; }
3
+ .wf_container select {border: 1px solid #ccc; font-size: 12px; font-family: Arial; margin:0px; padding: 1px !important; }
4
+ .wf_container .spinner {font-size: 10px;}
5
+ .wf_container .debug {font-size:10px; border-top:1px solid #ccc; width:100%; margin-top:3px;}
6
+ .wf_container a {text-decoration:none; color:#16b; outline:none; border:0px;}
7
+ .wf_container img {border:0px;}
8
+ .wf_container .conditions {padding:0px; margin:0px;}
9
+ .wf_container_panel {padding:5px; background:white; border:solid 1px #bababa;border-color:#bababa #e8e8e8 #e8e8e8 #bababa;}
10
+ .wf_debugger {padding:5px; margin:2px; background:white; border:solid 1px #bababa;border-color:#bababa #e8e8e8 #e8e8e8 #bababa; font-size:10px; color: #777;}
11
+
12
+ .wf_input {}
13
+
14
+ .wf_header {margin:0px; height:25px; padding:5px;}
15
+ .wf_action {border: 0px; vertical-align:middle;}
16
+ .wf_match_header {margin:5px;}
17
+
18
+ .wf_footer {padding:5px; margin-top:3px;}
19
+
20
+ .wf_conditions_table {border:0px; width:100%; margin:0px; padding:0px; }
21
+ .wf_conditions_table td {vertical-align:top; padding-right: 3px; padding: 1px; white-space:nowrap; }
22
+
23
+ .wf_condition {padding-left:5px; padding-right:2px; padding-bottom:0px; width:20%; white-space:nowrap; vertical-align: top; }
24
+ .wf_operator {padding-right:2px; padding-bottom:0px; width:15%; white-space:nowrap; vertical-align: top; }
25
+ .wf_values {padding-right:2px; width:70%; margin:0px; vertical-align:top; }
26
+
27
+ .wf_values_table {border:0px; width:100%; margin:0px; padding:0px; }
28
+ .wf_values_table td {vertical-align:top; padding: 0px; margin: 0px; }
29
+
30
+ .wf_condition_actions {padding-right:5px; padding-bottom:2px; white-space:nowrap; text-align:right; width:100px; vertical-align: top; }
31
+ .wf_button {text-align:center; padding: 0px; margin: 0px; }
32
+ .wf_dirty_msg {color:red; font-size:10px;}
33
+
34
+ .wf_calendar_trigger {border:0px; padding-left:2px; padding-right:2px;}
35
+
36
+ .wf_calendar {background-color:#eee; position:absolute; padding: 2px; font-size:10px; border:solid 1px #e8e8e8; border-color:#e8e8e8 #bababa #bababa #e8e8e8;}
37
+ .wf_calendar_table {width:100%;}
38
+ .wf_calendar_table td {padding:2px; margin:2px; text-align:center; vertical-align:top;}
39
+ .wf_calendar_container {background-color:white; padding: 1px; margin: 1px; font-size:10px; border:solid 1px #bababa; border-color:#bababa #e8e8e8 #e8e8e8 #bababa; }
40
+ .wf_calendar img {border: 0px;}
41
+ .wf_calendar input {border: 1px solid #ccc; font-size: 12px; font-family: Arial; }
42
+ .wf_calendar select {border: 1px solid #ccc; font-size: 12px; font-family: Arial; }
43
+ .wf_calendar_cells {border:1px dotted #ccc; width:100%; padding:2px; margin:0px; }
44
+ .wf_calendar_cells td {padding:2px; border: 0px; text-align:center; vertical-align:middle; font-size:8px; color:black; background-color:white;cursor:pointer;}
45
+ .wf_calendar_title {text-align:center; border-top:1px solid #ccc; border-bottom:1px solid #ccc; background: #eee;}
46
+ .wf_calendar_date_cell {width:11px; border: 1px solid #ccc; padding:2px; margin:1px; cursor:pointer; vertical-align:middle; text-align:center; background-color:white;}
47
+ .wf_calendar_date_cell.today {background-color:lightblue; }
48
+ .wf_calendar_date_cell.selected {background-color:#ccc; }
49
+ .wf_calendar_date_cell:hover {background-color:#ccc; }
50
+ .wf_exporter {background-color:#eee; position:absolute; width:230px; padding: 2px; font-size:10px; border:solid 1px #e8e8e8; border-color:#e8e8e8 #bababa #bababa #e8e8e8;}
51
+ .wf_exporter img {border: 0px;}
52
+ .wf_exporter input {border: 1px solid #ccc; font-size: 12px; font-family: Arial; }
53
+ .wf_exporter select {border: 1px solid #ccc; font-size: 12px; font-family: Arial; }
54
+ .wf_exporter table {width:100%;border-collapse: collapse; font-size:12px; padding:0px; margin:0px;}
55
+ .wf_exporter td {vertical-align:top; padding: 0px; margin: 0px; }
56
+ .wf_exporter_container {background-color:white; padding: 1px; margin: 1px; font-size:10px; border:solid 1px #bababa; border-color:#bababa #e8e8e8 #e8e8e8 #bababa; }
57
+
58
+ .wf_filter_error {background-color: #ffeded; border: 1px #f58a8a solid; border-left:none; border-right:none; color:#b60e0e; padding:5px; margin-left:3px; margin-right:3px; }
59
+ .wf_condition_error {padding-left:10px; padding-right:10px; margin-bottom:2px; font-size: 10px; background-color: #ffeded; font-family: Arial; border: 1px #f58a8a solid; border-left:none; border-right:none; color:#b60e0e;}
60
+
61
+ /*
62
+ Pure CSS Buttons.
63
+ Learn more ~ http://www.halmatferello.com/lab/pure-css-buttons/
64
+
65
+ Licensed under GPL and MIT.
66
+ */
67
+ .wf_pcb, .wf_pcb span {background: url('/will_filter/images/buttons.png') no-repeat; height: 23px; line-height: 23px; padding: 3px 0 7px 0; }
68
+ .wf_pcb, a.wf_pcb:link, a.wf_pcb:visited {color: #333; font-size: 12px; font-style:bold; font-family:arial; padding-left: 14px; text-decoration: none !important; }
69
+
70
+ /* ie 6 hack */
71
+ * html div#frame .wf_pcb {color: #333; padding-top: 0px; padding-bottom: 0px; text-decoration: none; }
72
+
73
+ /* ie 7 hack */
74
+ *:first-child+html .wf_pcb {color: #333; padding-top: 0px; padding-bottom: 0px; text-decoration: none; }
75
+
76
+ .wf_pcb span {background-position: right -326px; padding-right: 14px; }
77
+ a.wf_grey_button {background-position: left -219px; padding-top: 3px; }
78
+ a.wf_grey_button span {background-position: right -545px; padding-top: 3px; }
79
+ a.wf_grey_button:hover {background-position: left -246px; }
80
+ a.wf_grey_button:hover span {background-position: right -572px; }
81
+ a.wf_grey_button:active, .grey_active_button {background-position: left -273px; }
82
+ a.wf_grey_button:active span, .grey_active_button span {background-position: right -599px; }
83
+ body.wf_grey_disabled_button {background-position: left -300px; color: #bbb !important; }
84
+ body.wf_grey_disabled_button span {background-position: right -626px; }
85
+
86
+ .wf_paginator { width:100%; margin-bottom: 10px; font-size: 12px; font-family: Arial;}
87
+
88
+ .wf_results_table {
89
+ width: 100%;
90
+ font-size: 12px;
91
+ border: 1px #e5e5e5 solid;
92
+ border-collapse: collapse;
93
+ background-color: white;
94
+ margin-bottom: 10px;
95
+ }
96
+
97
+ .wf_results_table thead th {
98
+ background-color:#F5F5F5;
99
+ border-bottom:1px solid #CCCCCC;
100
+ border-top:1px solid #CCCCCC;
101
+ font-size:12px;
102
+ padding:5px 5px 5px 10px;
103
+ text-align:left;
104
+ white-space:nowrap;
105
+ }
106
+ .wf_results_table th,
107
+ .wf_results_table td {padding-right:10px;padding-left:10px; border-left:1px solid #eee;}
108
+ .wf_results_table td {padding:10px;border-bottom:solid 1px #ddd;vertical-align:top;}
109
+ .wf_results_table th {border-left:1px solid #ccc;padding-right:0px;font-weight:normal}
110
+ .wf_results_table th.first {border-left:none;}
111
+ .wf_results_table th {background: transparent url(/will_filter/images/sort_bg.gif) repeat-x scroll 0 0;}
112
+
113
+ .wf_results_table th.sortable:hover {background-color:#ddd;}
114
+ .wf_results_table th.sortable:hover .sort_control {display:block;}
115
+ .wf_results_table th.sortable .sort_link {text-decoration:none;;width:100%;display:block;}
116
+
117
+ .wf_results_table th.current_sort {background: transparent url(/will_filter/images/sort_bg.gif) repeat-x scroll 0 -100px;}
118
+ .wf_results_table th.current_sort .sort_control {display:block;}
119
+ .wf_results_table th.current_sort .sort_link {color:#000}
120
+
121
+ .wf_results_table th.desc .sort_control {display:block;}
122
+ .wf_results_table th.asc .sort_control .up {background: url(/will_filter/images/sort_arrow_all.gif) -17px 0 no-repeat;}
123
+ .wf_results_table th.desc .sort_control .down {background: url(/will_filter/images/sort_arrow_all.gif) -17px -13px no-repeat;}
124
+ .wf_results_table td.current_sort {font-weight:bold;border-left:1px solid #ccc;border-right:1px solid #ccc;}
125
+ .wf_results_table tr.data_row:hover {background-color: #eee;}
126
+
127
+ .wf_results_table .sort_title {float:left;}
128
+ .wf_results_table .table_head_container {position:relative;padding-right:20px;}
129
+
130
+ .wf_results_table .edit_location th,
131
+ .wf_results_table .edit_location td {background:none;padding:1px 2px;border:none;font-size:11px;}
132
+ .wf_results_table .edit_location_link {font-size:11px;}
133
+
134
+ .wf_results_table .sort_control {position:absolute;right:21px;margin:-5px -20px -5px 5px;display:none;height:24px;}
135
+ .wf_results_table .sort_control .up {width:17px;height:11px;display:block;background: url(/will_filter/images/sort_arrow_all.gif) 0 0 no-repeat;}
136
+ .wf_results_table .sort_control .up:hover {width:17px;height:11px;display:block;background: url(/will_filter/images/sort_arrow_all.gif) -17px 0 no-repeat;}
137
+ .wf_results_table .sort_control .down {width:17px;height:11px;display:block;background: url(/will_filter/images/sort_arrow_all.gif) 0 -13px no-repeat;}
138
+ .wf_results_table .sort_control .down:hover {width:17px;height:11px;display:block;background: url(/will_filter/images/sort_arrow_all.gif) -17px -13px no-repeat;}
139
+
140
+ .wf_results_table th .sort_control .up,
141
+ .wf_results_table th .sort_control .down {_height:12px !important;overflow:hidden;}
142
+
143
+ .wf_results_table {width:100%;margin:0}
144
+ .wf_results_table.short {margin-bottom:200px;}
145
+
146
+ .wf_results_table thead th {padding:5px 5px 5px 10px;text-align:left;font-size:12px;border-bottom:solid 1px #ccc;border-top:solid 1px #eee;background-color:#f5f5f5;white-space:nowrap;}
147
+ .wf_results_table th.active {background:url(/will_filter/images/results_table_th_active.gif) repeat-x;color:#fff;border-left:solid 1px #ccc;border-right:solid 1px #ccc}
148
+ .wf_results_table th.active a {color:#fff;}
149
+
150
+ .wf_actions_bar_yellow {
151
+ margin-top:10px;
152
+ margin-bottom:10px;
153
+ padding:10px;
154
+ background-color: #f9f8f7;
155
+ border-color: #E8E8E8 #BABABA #BABABA #E8E8E8;
156
+ border-style: solid;
157
+ border-width: 1px;
158
+ }
159
+
160
+ .wf_actions_bar_blue {
161
+ margin-top:10px;
162
+ margin-bottom:10px;
163
+ padding:10px;
164
+ background-color: #f1f4fa;
165
+ border-color: #E8E8E8 #BABABA #BABABA #E8E8E8;
166
+ border-style: solid;
167
+ border-width: 1px;
168
+ }
data/script/rails ADDED
@@ -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,297 @@
1
+ require File.expand_path('../../../../test_helper', __FILE__)
2
+
3
+ module WillFilter
4
+ class FilterTest < ActiveSupport::TestCase
5
+
6
+ test "boolean container" do
7
+ params = {:wf_type=>"UserFilter",
8
+ :wf_c0=>:admin,
9
+ :wf_o0=>:is,
10
+ :wf_v0_0=>"1"}
11
+ filter = WillFilter::Filter.deserialize_from_params(params)
12
+ assert_equal 1, filter.conditions.size
13
+ assert_equal 2, filter.sql_conditions.size
14
+ assert_equal " users.admin = ? ", filter.sql_conditions.first
15
+ assert_equal true, filter.sql_conditions.last
16
+
17
+ params = {:wf_type=>"UserFilter",
18
+ :wf_c0=>:admin,
19
+ :wf_o0=>:is,
20
+ :wf_v0_0=>"0"}
21
+ filter = WillFilter::Filter.deserialize_from_params(params)
22
+ assert_equal 1, filter.conditions.size
23
+ assert_equal 2, filter.sql_conditions.size
24
+ assert_equal " users.admin = ? ", filter.sql_conditions.first
25
+ assert_equal false, filter.sql_conditions.last
26
+ end
27
+
28
+ test "date range container" do
29
+ params = {:wf_type=>"UserFilter",
30
+ :wf_c0=>:birth_date,
31
+ :wf_o0=>:is_in_the_range,
32
+ :wf_v0_0=>"1971-11-09",
33
+ :wf_v0_1=>"1974-11-09"}
34
+ filter = WillFilter::Filter.deserialize_from_params(params)
35
+ assert_equal 1, filter.conditions.size
36
+ assert_equal 3, filter.sql_conditions.size
37
+ assert_equal " (users.birth_date >= ? and users.birth_date <= ?) ", filter.sql_conditions.first
38
+ end
39
+
40
+ test "date time range container" do
41
+ params = {:wf_type=>"UserFilter",
42
+ :wf_c0=>:created_at,
43
+ :wf_o0=>:is_in_the_range,
44
+ :wf_v0_0=>"1971-11-09 8:00",
45
+ :wf_v0_1=>"1971-11-09 12:00"}
46
+ filter = WillFilter::Filter.deserialize_from_params(params)
47
+ assert_equal 1, filter.conditions.size
48
+ assert_equal 3, filter.sql_conditions.size
49
+ assert_equal " (users.created_at >= ? and users.created_at <= ?) ", filter.sql_conditions.first
50
+ end
51
+
52
+ test "date time container" do
53
+ params = {:wf_type=>"UserFilter",
54
+ :wf_c0=>:created_at,
55
+ :wf_o0=>:is,
56
+ :wf_v0_0=>"1971-11-09 8:00"}
57
+ filter = WillFilter::Filter.deserialize_from_params(params)
58
+ assert_equal 1, filter.conditions.size
59
+ assert_equal 2, filter.sql_conditions.size
60
+ assert_equal " users.created_at = ? ", filter.sql_conditions.first
61
+
62
+ params = {:wf_type=>"UserFilter",
63
+ :wf_c0=>:created_at,
64
+ :wf_o0=>:is_not,
65
+ :wf_v0_0=>"1971-11-09 8:00"}
66
+ filter = WillFilter::Filter.deserialize_from_params(params)
67
+ assert_equal 1, filter.conditions.size
68
+ assert_equal 2, filter.sql_conditions.size
69
+ assert_equal " users.created_at <> ? ", filter.sql_conditions.first
70
+
71
+ params = {:wf_type=>"UserFilter",
72
+ :wf_c0=>:created_at,
73
+ :wf_o0=>:is_after,
74
+ :wf_v0_0=>"1971-11-09 8:00"}
75
+ filter = WillFilter::Filter.deserialize_from_params(params)
76
+ assert_equal 1, filter.conditions.size
77
+ assert_equal 2, filter.sql_conditions.size
78
+ assert_equal " users.created_at > ? ", filter.sql_conditions.first
79
+
80
+ params = {:wf_type=>"UserFilter",
81
+ :wf_c0=>:created_at,
82
+ :wf_o0=>:is_before,
83
+ :wf_v0_0=>"1971-11-09 8:00"}
84
+ filter = WillFilter::Filter.deserialize_from_params(params)
85
+ assert_equal 1, filter.conditions.size
86
+ assert_equal 2, filter.sql_conditions.size
87
+ assert_equal " users.created_at < ? ", filter.sql_conditions.first
88
+ end
89
+
90
+ test "date container" do
91
+ params = {:wf_type=>"UserFilter",
92
+ :wf_c0=>:birth_date,
93
+ :wf_o0=>:is,
94
+ :wf_v0_0=>"1971-11-09"}
95
+ filter = WillFilter::Filter.deserialize_from_params(params)
96
+ assert_equal 1, filter.conditions.size
97
+ assert_equal 2, filter.sql_conditions.size
98
+ assert_equal " users.birth_date = ? ", filter.sql_conditions.first
99
+
100
+ params = {:wf_type=>"UserFilter",
101
+ :wf_c0=>:birth_date,
102
+ :wf_o0=>:is_not,
103
+ :wf_v0_0=>"1971-11-09 8:00"}
104
+ filter = WillFilter::Filter.deserialize_from_params(params)
105
+ assert_equal 1, filter.conditions.size
106
+ assert_equal 2, filter.sql_conditions.size
107
+ assert_equal " users.birth_date <> ? ", filter.sql_conditions.first
108
+
109
+ params = {:wf_type=>"UserFilter",
110
+ :wf_c0=>:birth_date,
111
+ :wf_o0=>:is_after,
112
+ :wf_v0_0=>"1971-11-09 8:00"}
113
+ filter = WillFilter::Filter.deserialize_from_params(params)
114
+ assert_equal 1, filter.conditions.size
115
+ assert_equal 2, filter.sql_conditions.size
116
+ assert_equal " users.birth_date > ? ", filter.sql_conditions.first
117
+
118
+ params = {:wf_type=>"UserFilter",
119
+ :wf_c0=>:birth_date,
120
+ :wf_o0=>:is_before,
121
+ :wf_v0_0=>"1971-11-09 8:00"}
122
+ filter = WillFilter::Filter.deserialize_from_params(params)
123
+ assert_equal 1, filter.conditions.size
124
+ assert_equal 2, filter.sql_conditions.size
125
+ assert_equal " users.birth_date < ? ", filter.sql_conditions.first
126
+ end
127
+
128
+ test "numeric delimited container" do
129
+ params = {:wf_type=>"UserFilter",
130
+ :wf_c0=>:id,
131
+ :wf_o0=>:is_in,
132
+ :wf_v0_0=>"1,2,3,4,5,6"}
133
+ filter = WillFilter::Filter.deserialize_from_params(params)
134
+ assert_equal 1, filter.conditions.size
135
+ assert_equal 2, filter.sql_conditions.size
136
+ assert_equal " users.id in (?) ", filter.sql_conditions.first
137
+ end
138
+
139
+ test "numeric range container" do
140
+ params = {:wf_type=>"UserFilter",
141
+ :wf_c0=>:id,
142
+ :wf_o0=>:is_in_the_range,
143
+ :wf_v0_0=>"1",
144
+ :wf_v0_1=>"10"}
145
+ filter = WillFilter::Filter.deserialize_from_params(params)
146
+ assert_equal 1, filter.conditions.size
147
+ assert_equal 3, filter.sql_conditions.size
148
+ assert_equal " (users.id >= ? and users.id <= ?) ", filter.sql_conditions.first
149
+ end
150
+
151
+ test "numeric container" do
152
+ params = {:wf_type=>"UserFilter",
153
+ :wf_c0=>:id,
154
+ :wf_o0=>:is,
155
+ :wf_v0_0=>"1"}
156
+ filter = WillFilter::Filter.deserialize_from_params(params)
157
+ assert_equal 1, filter.conditions.size
158
+ assert_equal 2, filter.sql_conditions.size
159
+ assert_equal " users.id = ? ", filter.sql_conditions.first
160
+
161
+ params = {:wf_type=>"UserFilter",
162
+ :wf_c0=>:id,
163
+ :wf_o0=>:is_not,
164
+ :wf_v0_0=>"1"}
165
+ filter = WillFilter::Filter.deserialize_from_params(params)
166
+ assert_equal 1, filter.conditions.size
167
+ assert_equal 2, filter.sql_conditions.size
168
+ assert_equal " users.id <> ? ", filter.sql_conditions.first
169
+
170
+ params = {:wf_type=>"UserFilter",
171
+ :wf_c0=>:id,
172
+ :wf_o0=>:is_less_than,
173
+ :wf_v0_0=>"1"}
174
+ filter = WillFilter::Filter.deserialize_from_params(params)
175
+ assert_equal 1, filter.conditions.size
176
+ assert_equal 2, filter.sql_conditions.size
177
+ assert_equal " users.id < ? ", filter.sql_conditions.first
178
+
179
+ params = {:wf_type=>"UserFilter",
180
+ :wf_c0=>:id,
181
+ :wf_o0=>:is_greater_than,
182
+ :wf_v0_0=>"1"}
183
+ filter = WillFilter::Filter.deserialize_from_params(params)
184
+ assert_equal 1, filter.conditions.size
185
+ assert_equal 2, filter.sql_conditions.size
186
+ assert_equal " users.id > ? ", filter.sql_conditions.first
187
+ end
188
+
189
+ test "single date container" do
190
+ params = {:wf_type=>"UserFilter",
191
+ :wf_c0=>:created_at,
192
+ :wf_o0=>:is_on,
193
+ :wf_v0_0=>"1971-11-09"}
194
+ filter = WillFilter::Filter.deserialize_from_params(params)
195
+ assert_equal 1, filter.conditions.size
196
+ assert_equal 3, filter.sql_conditions.size
197
+ assert_equal " users.created_at >= ? and users.created_at < ? ", filter.sql_conditions.first
198
+
199
+ params = {:wf_type=>"UserFilter",
200
+ :wf_c0=>:created_at,
201
+ :wf_o0=>:is_not_on,
202
+ :wf_v0_0=>"1971-11-09"}
203
+ filter = WillFilter::Filter.deserialize_from_params(params)
204
+ assert_equal 1, filter.conditions.size
205
+ assert_equal 3, filter.sql_conditions.size
206
+ assert_equal " users.created_at < ? and users.created_at >= ? ", filter.sql_conditions.first
207
+ end
208
+
209
+ test "text delimited container" do
210
+ params = {:wf_type=>"UserFilter",
211
+ :wf_c0=>:name,
212
+ :wf_o0=>:is_in,
213
+ :wf_v0_0=>"a,b,c,d,e,f,g"}
214
+ filter = WillFilter::Filter.deserialize_from_params(params)
215
+ assert_equal 1, filter.conditions.size
216
+ assert_equal 2, filter.sql_conditions.size
217
+ assert_equal " users.name in (?) ", filter.sql_conditions.first
218
+
219
+ params = {:wf_type=>"UserFilter",
220
+ :wf_c0=>:name,
221
+ :wf_o0=>:is_not_in,
222
+ :wf_v0_0=>"a,b,c,d,e,f,g"}
223
+ filter = WillFilter::Filter.deserialize_from_params(params)
224
+ assert_equal 1, filter.conditions.size
225
+ assert_equal 2, filter.sql_conditions.size
226
+ assert_equal " users.name not in (?) ", filter.sql_conditions.first
227
+ end
228
+
229
+ test "text container" do
230
+ params = {:wf_type=>"UserFilter",
231
+ :wf_c0=>:name,
232
+ :wf_o0=>:is,
233
+ :wf_v0_0=>"Mike"}
234
+ filter = WillFilter::Filter.deserialize_from_params(params)
235
+ assert_equal 2, filter.sql_conditions.size
236
+ assert_equal " users.name = ? ", filter.sql_conditions.first
237
+ assert_equal "Mike", filter.sql_conditions.last
238
+
239
+ params = {:wf_type=>"UserFilter",
240
+ :wf_c0=>:name,
241
+ :wf_o0=>:is_not,
242
+ :wf_v0_0=>"Mike"}
243
+ filter = WillFilter::Filter.deserialize_from_params(params)
244
+ assert_equal 2, filter.sql_conditions.size
245
+ assert_equal " users.name <> ? ", filter.sql_conditions.first
246
+
247
+ params = {:wf_type=>"UserFilter",
248
+ :wf_c0=>:name,
249
+ :wf_o0=>:contains,
250
+ :wf_v0_0=>"Mike"}
251
+ filter = WillFilter::Filter.deserialize_from_params(params)
252
+ assert_equal 2, filter.sql_conditions.size
253
+ assert_equal " users.name like ? ", filter.sql_conditions.first
254
+
255
+ params = {:wf_type=>"UserFilter",
256
+ :wf_c0=>:name,
257
+ :wf_o0=>:does_not_contain,
258
+ :wf_v0_0=>"Mike"}
259
+ filter = WillFilter::Filter.deserialize_from_params(params)
260
+ assert_equal 2, filter.sql_conditions.size
261
+ assert_equal " users.name not like ? ", filter.sql_conditions.first
262
+
263
+ params = {:wf_type=>"UserFilter",
264
+ :wf_c0=>:name,
265
+ :wf_o0=>:starts_with,
266
+ :wf_v0_0=>"Mike"}
267
+ filter = WillFilter::Filter.deserialize_from_params(params)
268
+ assert_equal 2, filter.sql_conditions.size
269
+ assert_equal " users.name like ? ", filter.sql_conditions.first
270
+ assert_equal "Mike%", filter.sql_conditions.last
271
+
272
+ params = {:wf_type=>"UserFilter",
273
+ :wf_c0=>:name,
274
+ :wf_o0=>:ends_with,
275
+ :wf_v0_0=>"Mike"}
276
+ filter = WillFilter::Filter.deserialize_from_params(params)
277
+ assert_equal 2, filter.sql_conditions.size
278
+ assert_equal " users.name like ? ", filter.sql_conditions.first
279
+ assert_equal "%Mike", filter.sql_conditions.last
280
+ end
281
+
282
+ test "compound filter" do
283
+ params = {:wf_type=>"UserFilter",
284
+ :wf_c0=>:name,
285
+ :wf_o0=>:is,
286
+ :wf_v0_0=>"Mike",
287
+ :wf_c1=>:birth_date,
288
+ :wf_o1=>:is_before,
289
+ :wf_v1_0=>"1971-11-09 8:00"
290
+ }
291
+ filter = WillFilter::Filter.deserialize_from_params(params)
292
+ assert_equal 3, filter.sql_conditions.size
293
+ assert_equal " users.name = ? AND users.birth_date < ? ", filter.sql_conditions.first
294
+ end
295
+
296
+ end
297
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'rails/performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionDispatch::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,71 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7
+ #
8
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
+ # -- they do not yet inherit this setting
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
14
+
15
+ # Dummy UserFilter object for testing filter containers
16
+ class UserFilter < WillFilter::Filter
17
+ def table_name
18
+ "users"
19
+ end
20
+
21
+ def definition
22
+ {:id=>
23
+ {:is_provided=>"nil",
24
+ :is_not_provided=>"nil",
25
+ :is=>"numeric",
26
+ :is_not=>"numeric",
27
+ :is_less_than=>"numeric",
28
+ :is_greater_than=>"numeric",
29
+ :is_in_the_range=>"numeric_range",
30
+ :is_in=>"numeric_delimited",
31
+ :is_filtered_by=>:filter_list},
32
+ :name=>
33
+ {:is_provided=>"nil",
34
+ :is_not_provided=>"nil",
35
+ :is=>"text",
36
+ :is_not=>"text",
37
+ :contains=>"text",
38
+ :does_not_contain=>"text",
39
+ :starts_with=>"text",
40
+ :ends_with=>"text",
41
+ :is_in=>"text_delimited",
42
+ :is_not_in=>"text_delimited"},
43
+ :admin=>
44
+ {:is_provided=>"nil",
45
+ :is_not_provided=>"nil",
46
+ :is=>"boolean"
47
+ },
48
+ :birth_date =>
49
+ {:is_provided=>"nil",
50
+ :is_not_provided=>"nil",
51
+ :is=>"date",
52
+ :is_not=>"date",
53
+ :is_after=>"date",
54
+ :is_before=>"date",
55
+ :is_in_the_range=>"date_range"
56
+ },
57
+ :created_at=>
58
+ {:is_provided=>"nil",
59
+ :is_not_provided=>"nil",
60
+ :is=>"date_time",
61
+ :is_not=>"date_time",
62
+ :is_after=>"date_time",
63
+ :is_before=>"date_time",
64
+ :is_in_the_range=>"date_time_range",
65
+ :is_on=>"single_date",
66
+ :is_not_on=>"single_date"}
67
+ }
68
+ end
69
+
70
+
71
+ end
data/uninstall.rb ADDED
@@ -0,0 +1,24 @@
1
+ #--
2
+ # Copyright (c) 2010 Michael Berkovich, Geni Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ # Uninstall hook code here
@@ -0,0 +1,7 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "will_filter"
3
+ spec.version = "0.0.1"
4
+ spec.summary = "WillFilter"
5
+ spec.authors = ["Me"]
6
+ spec.files = Dir["{app,config,public,lib}/**/*"]
7
+ end