serpentine 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/{LICENSE → MIT-LICENSE} +2 -4
  2. data/Rakefile +39 -1
  3. data/lib/serpentine.rb +33 -3
  4. data/lib/serpentine/railtie.rb +9 -0
  5. data/lib/serpentine/version.rb +1 -1
  6. data/readme.md +74 -0
  7. data/test/dummy/README.rdoc +261 -0
  8. data/test/dummy/Rakefile +7 -0
  9. data/test/dummy/app/assets/javascripts/application.js +15 -0
  10. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  11. data/test/dummy/app/controllers/application_controller.rb +3 -0
  12. data/test/dummy/app/helpers/application_helper.rb +2 -0
  13. data/test/dummy/app/models/user.rb +3 -0
  14. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  15. data/test/dummy/config.ru +4 -0
  16. data/test/dummy/config/application.rb +65 -0
  17. data/test/dummy/config/boot.rb +10 -0
  18. data/test/dummy/config/database.yml +25 -0
  19. data/test/dummy/config/environment.rb +5 -0
  20. data/test/dummy/config/environments/development.rb +37 -0
  21. data/test/dummy/config/environments/production.rb +67 -0
  22. data/test/dummy/config/environments/test.rb +37 -0
  23. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  24. data/test/dummy/config/initializers/inflections.rb +15 -0
  25. data/test/dummy/config/initializers/mime_types.rb +5 -0
  26. data/test/dummy/config/initializers/secret_token.rb +7 -0
  27. data/test/dummy/config/initializers/session_store.rb +8 -0
  28. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  29. data/test/dummy/config/locales/en.yml +5 -0
  30. data/test/dummy/config/routes.rb +0 -0
  31. data/test/dummy/db/development.sqlite3 +0 -0
  32. data/test/dummy/db/migrate/20120622090434_create_users.rb +11 -0
  33. data/test/dummy/db/schema.rb +20 -0
  34. data/test/dummy/db/test.sqlite3 +0 -0
  35. data/test/dummy/log/development.log +43 -0
  36. data/test/dummy/log/test.log +979 -0
  37. data/test/dummy/public/404.html +26 -0
  38. data/test/dummy/public/422.html +26 -0
  39. data/test/dummy/public/500.html +25 -0
  40. data/test/dummy/public/favicon.ico +0 -0
  41. data/test/dummy/script/rails +6 -0
  42. data/test/integration/basic_filter_test.rb +35 -0
  43. data/test/integration/conditional_filters_test.rb +83 -0
  44. data/test/integration/multiple_filter_test.rb +40 -0
  45. data/test/test_helper.rb +27 -0
  46. metadata +141 -17
  47. data/.gitignore +0 -17
  48. data/Gemfile +0 -4
  49. data/README.md +0 -29
  50. data/serpentine.gemspec +0 -17
@@ -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,35 @@
1
+ require 'test_helper'
2
+
3
+ class BasicFilterController < ApplicationController
4
+ filter_collection :by_key
5
+
6
+ def index
7
+ apply_scopes!
8
+
9
+ render_results
10
+ end
11
+
12
+ def collection
13
+ @collection ||= User.scoped
14
+ end
15
+
16
+ def by_key
17
+ collection.where :key => params[:keys]
18
+ end
19
+ end
20
+
21
+ class BasicFilterTest < ActionDispatch::IntegrationTest
22
+ def test_a_basic_filter
23
+ User.create! :key => 1
24
+ User.create! :key => 2
25
+ User.create! :key => 3
26
+ User.create! :key => 4
27
+
28
+ get '/basic_filter/index', :keys => %w(1 2 3)
29
+
30
+ assert_response :success
31
+
32
+ keys = JSON.parse response.body
33
+ assert_equal %w(1 2 3), keys
34
+ end
35
+ end
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+
3
+ class IfFilterController < ApplicationController
4
+ filter_collection :by_key, :if => proc { |params| params[:monkey] }
5
+
6
+ def index
7
+ apply_scopes!
8
+
9
+ render_results
10
+ end
11
+
12
+ def collection
13
+ @collection ||= User.scoped
14
+ end
15
+
16
+ def by_key
17
+ collection.where :key => params[:keys]
18
+ end
19
+ end
20
+
21
+ class IfFilterTest < ActionDispatch::IntegrationTest
22
+ def test_an_if_conditional
23
+ User.create! :key => 1
24
+ User.create! :key => 2
25
+ User.create! :key => 3
26
+ User.create! :key => 4
27
+
28
+ get '/if_filter/index', :keys => %w(1 2 3), :monkey => true
29
+
30
+ assert_response :success
31
+
32
+ keys = JSON.parse response.body
33
+ assert_equal %w(1 2 3), keys
34
+
35
+ get '/if_filter/index', :keys => %w(1 2 3)
36
+
37
+ assert_response :success
38
+
39
+ keys = JSON.parse response.body
40
+ assert_equal %w(1 2 3 4), keys
41
+ end
42
+ end
43
+
44
+ class UnlessFilterController < ApplicationController
45
+ filter_collection :by_key, :unless => proc { |params| params[:skip_filters] }
46
+
47
+ def index
48
+ apply_scopes!
49
+
50
+ render_results
51
+ end
52
+
53
+ def collection
54
+ @collection ||= User.scoped
55
+ end
56
+
57
+ def by_key
58
+ collection.where :key => params[:keys]
59
+ end
60
+ end
61
+
62
+ class UnlessFilterTest < ActionDispatch::IntegrationTest
63
+ def test_an_unless_conditional
64
+ User.create! :key => 1
65
+ User.create! :key => 2
66
+ User.create! :key => 3
67
+ User.create! :key => 4
68
+
69
+ get '/unless_filter/index', :keys => %w(1 2 3)
70
+
71
+ assert_response :success
72
+
73
+ keys = JSON.parse response.body
74
+ assert_equal %w(1 2 3), keys
75
+
76
+ get '/unless_filter/index', :keys => %w(1 2 3), :skip_filters => true
77
+
78
+ assert_response :success
79
+
80
+ keys = JSON.parse response.body
81
+ assert_equal %w(1 2 3 4), keys
82
+ end
83
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ class MultipleFiltersController < ApplicationController
4
+ filter_collection :by_key
5
+ filter_collection :to_nil
6
+
7
+ def index
8
+ apply_scopes!
9
+
10
+ render_results
11
+ end
12
+
13
+ def collection
14
+ @collection ||= User.scoped
15
+ end
16
+
17
+ def by_key
18
+ collection.where :key => params[:keys]
19
+ end
20
+
21
+ def to_nil
22
+ collection.where :key => nil
23
+ end
24
+ end
25
+
26
+ class MultipleFilterTest < ActionDispatch::IntegrationTest
27
+ def test_multiple_filters_applied
28
+ User.create! :key => 1
29
+ User.create! :key => 2
30
+ User.create! :key => 3
31
+ User.create! :key => 4
32
+
33
+ get '/multiple_filters/index', :keys => %w(1 2 3)
34
+
35
+ assert_response :success
36
+
37
+ keys = JSON.parse response.body
38
+ assert_equal [], keys
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+
7
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
8
+ require "rails/test_help"
9
+
10
+ Rails.backtrace_cleaner.remove_silencers!
11
+
12
+ # Load support files
13
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
+
15
+ Dummy::Application.routes.draw do
16
+ match ':controller(/:action(/:id))(.:format)'
17
+ end
18
+
19
+ class ApplicationController
20
+ def render_results
21
+ render :json => collection.map(&:key)
22
+ end
23
+
24
+ def collection=(value)
25
+ @collection = value
26
+ end
27
+ end
metadata CHANGED
@@ -1,16 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serpentine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - twinturbo
8
+ - Adam Hawkins
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-07 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-06-22 00:00:00.000000000 Z
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'
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'
30
+ - !ruby/object:Gem::Dependency
31
+ name: simplecov
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
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'
14
62
  description: ''
15
63
  email:
16
64
  - me@broadcastingadam.com
@@ -18,15 +66,52 @@ executables: []
18
66
  extensions: []
19
67
  extra_rdoc_files: []
20
68
  files:
21
- - .gitignore
22
- - Gemfile
23
- - LICENSE
24
- - README.md
25
- - Rakefile
26
- - lib/serpentine.rb
69
+ - lib/serpentine/railtie.rb
27
70
  - lib/serpentine/version.rb
28
- - serpentine.gemspec
29
- homepage: ''
71
+ - lib/serpentine.rb
72
+ - MIT-LICENSE
73
+ - Rakefile
74
+ - readme.md
75
+ - test/dummy/app/assets/javascripts/application.js
76
+ - test/dummy/app/assets/stylesheets/application.css
77
+ - test/dummy/app/controllers/application_controller.rb
78
+ - test/dummy/app/helpers/application_helper.rb
79
+ - test/dummy/app/models/user.rb
80
+ - test/dummy/app/views/layouts/application.html.erb
81
+ - test/dummy/config/application.rb
82
+ - test/dummy/config/boot.rb
83
+ - test/dummy/config/database.yml
84
+ - test/dummy/config/environment.rb
85
+ - test/dummy/config/environments/development.rb
86
+ - test/dummy/config/environments/production.rb
87
+ - test/dummy/config/environments/test.rb
88
+ - test/dummy/config/initializers/backtrace_silencers.rb
89
+ - test/dummy/config/initializers/inflections.rb
90
+ - test/dummy/config/initializers/mime_types.rb
91
+ - test/dummy/config/initializers/secret_token.rb
92
+ - test/dummy/config/initializers/session_store.rb
93
+ - test/dummy/config/initializers/wrap_parameters.rb
94
+ - test/dummy/config/locales/en.yml
95
+ - test/dummy/config/routes.rb
96
+ - test/dummy/config.ru
97
+ - test/dummy/db/development.sqlite3
98
+ - test/dummy/db/migrate/20120622090434_create_users.rb
99
+ - test/dummy/db/schema.rb
100
+ - test/dummy/db/test.sqlite3
101
+ - test/dummy/log/development.log
102
+ - test/dummy/log/test.log
103
+ - test/dummy/public/404.html
104
+ - test/dummy/public/422.html
105
+ - test/dummy/public/500.html
106
+ - test/dummy/public/favicon.ico
107
+ - test/dummy/Rakefile
108
+ - test/dummy/README.rdoc
109
+ - test/dummy/script/rails
110
+ - test/integration/basic_filter_test.rb
111
+ - test/integration/conditional_filters_test.rb
112
+ - test/integration/multiple_filter_test.rb
113
+ - test/test_helper.rb
114
+ homepage: https://github.com/twinturbo/serpentine
30
115
  licenses: []
31
116
  post_install_message:
32
117
  rdoc_options: []
@@ -40,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
40
125
  version: '0'
41
126
  segments:
42
127
  - 0
43
- hash: -2163525270219734173
128
+ hash: 1826887560178753735
44
129
  required_rubygems_version: !ruby/object:Gem::Requirement
45
130
  none: false
46
131
  requirements:
@@ -49,11 +134,50 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
134
  version: '0'
50
135
  segments:
51
136
  - 0
52
- hash: -2163525270219734173
137
+ hash: 1826887560178753735
53
138
  requirements: []
54
139
  rubyforge_project:
55
- rubygems_version: 1.8.11
140
+ rubygems_version: 1.8.24
56
141
  signing_key:
57
142
  specification_version: 3
58
- summary: ''
59
- test_files: []
143
+ summary: Easy query parameter filters for Rails applications
144
+ test_files:
145
+ - test/dummy/app/assets/javascripts/application.js
146
+ - test/dummy/app/assets/stylesheets/application.css
147
+ - test/dummy/app/controllers/application_controller.rb
148
+ - test/dummy/app/helpers/application_helper.rb
149
+ - test/dummy/app/models/user.rb
150
+ - test/dummy/app/views/layouts/application.html.erb
151
+ - test/dummy/config/application.rb
152
+ - test/dummy/config/boot.rb
153
+ - test/dummy/config/database.yml
154
+ - test/dummy/config/environment.rb
155
+ - test/dummy/config/environments/development.rb
156
+ - test/dummy/config/environments/production.rb
157
+ - test/dummy/config/environments/test.rb
158
+ - test/dummy/config/initializers/backtrace_silencers.rb
159
+ - test/dummy/config/initializers/inflections.rb
160
+ - test/dummy/config/initializers/mime_types.rb
161
+ - test/dummy/config/initializers/secret_token.rb
162
+ - test/dummy/config/initializers/session_store.rb
163
+ - test/dummy/config/initializers/wrap_parameters.rb
164
+ - test/dummy/config/locales/en.yml
165
+ - test/dummy/config/routes.rb
166
+ - test/dummy/config.ru
167
+ - test/dummy/db/development.sqlite3
168
+ - test/dummy/db/migrate/20120622090434_create_users.rb
169
+ - test/dummy/db/schema.rb
170
+ - test/dummy/db/test.sqlite3
171
+ - test/dummy/log/development.log
172
+ - test/dummy/log/test.log
173
+ - test/dummy/public/404.html
174
+ - test/dummy/public/422.html
175
+ - test/dummy/public/500.html
176
+ - test/dummy/public/favicon.ico
177
+ - test/dummy/Rakefile
178
+ - test/dummy/README.rdoc
179
+ - test/dummy/script/rails
180
+ - test/integration/basic_filter_test.rb
181
+ - test/integration/conditional_filters_test.rb
182
+ - test/integration/multiple_filter_test.rb
183
+ - test/test_helper.rb