magick_columns 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 (50) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +45 -0
  3. data/Rakefile +38 -0
  4. data/lib/magick_columns/defaults.rb +31 -0
  5. data/lib/magick_columns/magick_columns.rb +80 -0
  6. data/lib/magick_columns/version.rb +3 -0
  7. data/lib/magick_columns.rb +6 -0
  8. data/lib/tasks/magick_columns_tasks.rake +4 -0
  9. data/test/dummy/README.rdoc +261 -0
  10. data/test/dummy/Rakefile +7 -0
  11. data/test/dummy/app/assets/javascripts/application.js +15 -0
  12. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  13. data/test/dummy/app/controllers/application_controller.rb +3 -0
  14. data/test/dummy/app/helpers/application_helper.rb +2 -0
  15. data/test/dummy/app/models/article.rb +3 -0
  16. data/test/dummy/app/models/person.rb +3 -0
  17. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  18. data/test/dummy/config/application.rb +56 -0
  19. data/test/dummy/config/boot.rb +10 -0
  20. data/test/dummy/config/database.yml +55 -0
  21. data/test/dummy/config/environment.rb +5 -0
  22. data/test/dummy/config/environments/development.rb +37 -0
  23. data/test/dummy/config/environments/production.rb +67 -0
  24. data/test/dummy/config/environments/test.rb +37 -0
  25. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  26. data/test/dummy/config/initializers/inflections.rb +15 -0
  27. data/test/dummy/config/initializers/mime_types.rb +5 -0
  28. data/test/dummy/config/initializers/secret_token.rb +7 -0
  29. data/test/dummy/config/initializers/session_store.rb +8 -0
  30. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  31. data/test/dummy/config/locales/en.yml +5 -0
  32. data/test/dummy/config/routes.rb +58 -0
  33. data/test/dummy/config.ru +4 -0
  34. data/test/dummy/db/migrate/20120312175303_create_people.rb +11 -0
  35. data/test/dummy/db/migrate/20120312175442_create_articles.rb +10 -0
  36. data/test/dummy/db/schema.rb +31 -0
  37. data/test/dummy/log/development.log +118 -0
  38. data/test/dummy/log/test.log +618 -0
  39. data/test/dummy/public/404.html +26 -0
  40. data/test/dummy/public/422.html +26 -0
  41. data/test/dummy/public/500.html +25 -0
  42. data/test/dummy/public/favicon.ico +0 -0
  43. data/test/dummy/script/rails +6 -0
  44. data/test/dummy/test/fixtures/articles.yml +7 -0
  45. data/test/dummy/test/fixtures/people.yml +14 -0
  46. data/test/dummy/test/unit/article_test.rb +7 -0
  47. data/test/dummy/test/unit/person_test.rb +7 -0
  48. data/test/query_builder_test.rb +109 -0
  49. data/test/test_helper.rb +10 -0
  50. metadata +189 -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 ruby1.9.1
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,7 @@
1
+ lightsaber:
2
+ name: Lightsaber
3
+ code: 1
4
+
5
+ ship:
6
+ name: Ship
7
+ code: 2
@@ -0,0 +1,14 @@
1
+ obi_wan:
2
+ name: 'Obi-Wan Kenobi'
3
+ email: 'obi@sw.com'
4
+ birth: <%= 1000.years.from_now.to_date.to_s(:db) %>
5
+
6
+ luke:
7
+ name: 'Luke Skywalker'
8
+ email: 'luke@sw.com'
9
+ birth: <%= 1040.years.from_now.to_date.to_s(:db) %>
10
+
11
+ anakin:
12
+ name: 'Anakin Skywalker'
13
+ email: 'anakin@sw.com'
14
+ birth: <%= 1020.years.from_now.to_date.to_s(:db) %>
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ArticleTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class PersonTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,109 @@
1
+ require 'test_helper'
2
+
3
+ class MagickColumnsTest < ActiveSupport::TestCase
4
+ test 'correct definition' do
5
+ assert_kind_of Module, MagickColumns
6
+ end
7
+
8
+ test 'extract magick query terms' do
9
+ terms = Person.send(:_extract_magick_query_terms, 'a b')
10
+ assert_equal [['a', 'b']], terms
11
+
12
+ terms = Person.send(:_extract_magick_query_terms, 'a or b')
13
+ assert_equal [['a'], ['b']], terms
14
+
15
+ terms = Person.send(:_extract_magick_query_terms, 'long_abc')
16
+ assert_equal [['long_abc']], terms
17
+
18
+ terms = Person.send(:_extract_magick_query_terms, ' ')
19
+ assert_equal [], terms
20
+ end
21
+
22
+ test 'map magick column operator' do
23
+ operator = Person.send(:_map_magick_column_operator, '=', 'PostgreSQL')
24
+ assert_equal '=', operator
25
+
26
+ operator = Person.send(:_map_magick_column_operator, :like)
27
+ assert_equal 'ILIKE', operator
28
+
29
+ operator = Person.send(:_map_magick_column_operator, :like, 'MySQL')
30
+ assert_equal 'LIKE', operator
31
+ end
32
+
33
+ test 'string magick search' do
34
+ people = Person.magick_search('obi')
35
+
36
+ assert_equal 1, people.count
37
+ assert people.first.name =~ /obi/i
38
+
39
+ people = Person.magick_search('skywalker')
40
+
41
+ assert_equal 2, people.count
42
+ assert people.all? { |p| p.name =~ /skywalker/i }
43
+
44
+ people = Person.magick_search('anakin skywalker')
45
+
46
+ assert_equal 1, people.count
47
+ assert people.first.name =~ /anakin skywalker/i
48
+
49
+ people = Person.magick_search('anakin or skywalker')
50
+
51
+ assert_equal 2, people.count
52
+ assert people.all? { |p| p.name =~ /anakin|skywalker/i }
53
+
54
+ people = Person.magick_search('nobody')
55
+
56
+ assert people.empty?
57
+ end
58
+
59
+ test 'email magick search' do
60
+ people = Person.magick_search('obi@')
61
+
62
+ assert_equal 1, people.count
63
+ assert people.first.email =~ /obi@/i
64
+
65
+ people = Person.magick_search('@sw.com')
66
+
67
+ assert_equal 3, people.count
68
+ assert people.all? { |p| p.email =~ /@sw.com/i }
69
+
70
+ people = Person.magick_search('nobody@sw.com')
71
+
72
+ assert people.empty?
73
+ end
74
+
75
+ test 'integer magick search' do
76
+ articles = Article.magick_search('1')
77
+
78
+ assert_equal 1, articles.count
79
+ assert articles.first.code == 1
80
+
81
+ articles = Article.magick_search('100')
82
+
83
+ assert articles.empty?
84
+ end
85
+
86
+ test 'date magick search' do
87
+ people = Person.magick_search("#{1000.years.from_now.to_date}")
88
+
89
+ assert_equal 1, people.count
90
+ assert people.first.birth == 1000.years.from_now.to_date
91
+
92
+ people = Person.magick_search("#{1020.years.from_now.to_date}")
93
+
94
+ assert_equal 1, people.count
95
+ assert people.first.birth == 1020.years.from_now.to_date
96
+
97
+ people = Person.magick_search("#{Date.today}")
98
+
99
+ assert people.empty?
100
+ end
101
+
102
+ test 'combine date and string in magick search' do
103
+ birth = 1000.years.from_now.to_date
104
+ people = Person.magick_search("#{birth} or luke")
105
+
106
+ assert_equal 2, people.count
107
+ assert people.all? { |p| p.birth == birth || p.name =~ /luke/i }
108
+ end
109
+ end
@@ -0,0 +1,10 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magick_columns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Franco Catena
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: timeliness
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.3'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pg
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Tokenize a simple strings and builds an ActiveRecord query
63
+ email:
64
+ - francocatena@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/tasks/magick_columns_tasks.rake
70
+ - lib/magick_columns/magick_columns.rb
71
+ - lib/magick_columns/defaults.rb
72
+ - lib/magick_columns/version.rb
73
+ - lib/magick_columns.rb
74
+ - MIT-LICENSE
75
+ - Rakefile
76
+ - README.rdoc
77
+ - test/dummy/Rakefile
78
+ - test/dummy/script/rails
79
+ - test/dummy/public/500.html
80
+ - test/dummy/public/422.html
81
+ - test/dummy/public/404.html
82
+ - test/dummy/public/favicon.ico
83
+ - test/dummy/README.rdoc
84
+ - test/dummy/log/test.log
85
+ - test/dummy/log/development.log
86
+ - test/dummy/config/boot.rb
87
+ - test/dummy/config/application.rb
88
+ - test/dummy/config/initializers/backtrace_silencers.rb
89
+ - test/dummy/config/initializers/inflections.rb
90
+ - test/dummy/config/initializers/session_store.rb
91
+ - test/dummy/config/initializers/secret_token.rb
92
+ - test/dummy/config/initializers/wrap_parameters.rb
93
+ - test/dummy/config/initializers/mime_types.rb
94
+ - test/dummy/config/database.yml
95
+ - test/dummy/config/routes.rb
96
+ - test/dummy/config/environments/development.rb
97
+ - test/dummy/config/environments/production.rb
98
+ - test/dummy/config/environments/test.rb
99
+ - test/dummy/config/locales/en.yml
100
+ - test/dummy/config/environment.rb
101
+ - test/dummy/app/assets/stylesheets/application.css
102
+ - test/dummy/app/assets/javascripts/application.js
103
+ - test/dummy/app/views/layouts/application.html.erb
104
+ - test/dummy/app/controllers/application_controller.rb
105
+ - test/dummy/app/models/article.rb
106
+ - test/dummy/app/models/person.rb
107
+ - test/dummy/app/helpers/application_helper.rb
108
+ - test/dummy/config.ru
109
+ - test/dummy/db/migrate/20120312175442_create_articles.rb
110
+ - test/dummy/db/migrate/20120312175303_create_people.rb
111
+ - test/dummy/db/schema.rb
112
+ - test/dummy/test/unit/person_test.rb
113
+ - test/dummy/test/unit/article_test.rb
114
+ - test/dummy/test/fixtures/articles.yml
115
+ - test/dummy/test/fixtures/people.yml
116
+ - test/test_helper.rb
117
+ - test/query_builder_test.rb
118
+ homepage: http://github.com/francocatena/magick_columns
119
+ licenses: []
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ segments:
131
+ - 0
132
+ hash: 3819401529936594819
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ segments:
140
+ - 0
141
+ hash: 3819401529936594819
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 1.8.18
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: Build query conditions from simple strings
148
+ test_files:
149
+ - test/dummy/Rakefile
150
+ - test/dummy/script/rails
151
+ - test/dummy/public/500.html
152
+ - test/dummy/public/422.html
153
+ - test/dummy/public/404.html
154
+ - test/dummy/public/favicon.ico
155
+ - test/dummy/README.rdoc
156
+ - test/dummy/log/test.log
157
+ - test/dummy/log/development.log
158
+ - test/dummy/config/boot.rb
159
+ - test/dummy/config/application.rb
160
+ - test/dummy/config/initializers/backtrace_silencers.rb
161
+ - test/dummy/config/initializers/inflections.rb
162
+ - test/dummy/config/initializers/session_store.rb
163
+ - test/dummy/config/initializers/secret_token.rb
164
+ - test/dummy/config/initializers/wrap_parameters.rb
165
+ - test/dummy/config/initializers/mime_types.rb
166
+ - test/dummy/config/database.yml
167
+ - test/dummy/config/routes.rb
168
+ - test/dummy/config/environments/development.rb
169
+ - test/dummy/config/environments/production.rb
170
+ - test/dummy/config/environments/test.rb
171
+ - test/dummy/config/locales/en.yml
172
+ - test/dummy/config/environment.rb
173
+ - test/dummy/app/assets/stylesheets/application.css
174
+ - test/dummy/app/assets/javascripts/application.js
175
+ - test/dummy/app/views/layouts/application.html.erb
176
+ - test/dummy/app/controllers/application_controller.rb
177
+ - test/dummy/app/models/article.rb
178
+ - test/dummy/app/models/person.rb
179
+ - test/dummy/app/helpers/application_helper.rb
180
+ - test/dummy/config.ru
181
+ - test/dummy/db/migrate/20120312175442_create_articles.rb
182
+ - test/dummy/db/migrate/20120312175303_create_people.rb
183
+ - test/dummy/db/schema.rb
184
+ - test/dummy/test/unit/person_test.rb
185
+ - test/dummy/test/unit/article_test.rb
186
+ - test/dummy/test/fixtures/articles.yml
187
+ - test/dummy/test/fixtures/people.yml
188
+ - test/test_helper.rb
189
+ - test/query_builder_test.rb