exposed 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +138 -0
  3. data/Rakefile +40 -0
  4. data/app/controllers/exposed/base.rb +84 -0
  5. data/config/routes.rb +2 -0
  6. data/lib/exposed.rb +4 -0
  7. data/lib/exposed/engine.rb +5 -0
  8. data/lib/exposed/version.rb +3 -0
  9. data/lib/tasks/exposed_tasks.rake +4 -0
  10. data/test/dummy/README.rdoc +261 -0
  11. data/test/dummy/Rakefile +7 -0
  12. data/test/dummy/app/assets/javascripts/application.js +15 -0
  13. data/test/dummy/app/assets/javascripts/posts.js +2 -0
  14. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  15. data/test/dummy/app/assets/stylesheets/posts.css +4 -0
  16. data/test/dummy/app/controllers/application_controller.rb +2 -0
  17. data/test/dummy/app/controllers/posts_controller.rb +2 -0
  18. data/test/dummy/app/helpers/application_helper.rb +2 -0
  19. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  20. data/test/dummy/app/models/comment.rb +4 -0
  21. data/test/dummy/app/models/post.rb +4 -0
  22. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  23. data/test/dummy/config.ru +4 -0
  24. data/test/dummy/config/application.rb +59 -0
  25. data/test/dummy/config/boot.rb +10 -0
  26. data/test/dummy/config/database.yml +25 -0
  27. data/test/dummy/config/environment.rb +5 -0
  28. data/test/dummy/config/environments/development.rb +37 -0
  29. data/test/dummy/config/environments/production.rb +67 -0
  30. data/test/dummy/config/environments/test.rb +37 -0
  31. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  32. data/test/dummy/config/initializers/inflections.rb +15 -0
  33. data/test/dummy/config/initializers/mime_types.rb +5 -0
  34. data/test/dummy/config/initializers/secret_token.rb +7 -0
  35. data/test/dummy/config/initializers/session_store.rb +8 -0
  36. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  37. data/test/dummy/config/locales/en.yml +5 -0
  38. data/test/dummy/config/routes.rb +5 -0
  39. data/test/dummy/db/development.sqlite3 +0 -0
  40. data/test/dummy/db/migrate/20121013230139_create_posts.rb +10 -0
  41. data/test/dummy/db/migrate/20121013230216_create_comments.rb +10 -0
  42. data/test/dummy/db/schema.rb +30 -0
  43. data/test/dummy/db/test.sqlite3 +0 -0
  44. data/test/dummy/log/development.log +422 -0
  45. data/test/dummy/log/test.log +2067 -0
  46. data/test/dummy/public/404.html +26 -0
  47. data/test/dummy/public/422.html +26 -0
  48. data/test/dummy/public/500.html +25 -0
  49. data/test/dummy/public/favicon.ico +0 -0
  50. data/test/dummy/script/rails +6 -0
  51. data/test/dummy/test/fixtures/comments.yml +13 -0
  52. data/test/dummy/test/fixtures/posts.yml +11 -0
  53. data/test/dummy/test/functional/posts_controller_test.rb +18 -0
  54. data/test/dummy/test/unit/comment_test.rb +7 -0
  55. data/test/dummy/test/unit/helpers/posts_helper_test.rb +4 -0
  56. data/test/dummy/test/unit/post_test.rb +7 -0
  57. data/test/dummy/tmp/pids/server.pid +1 -0
  58. data/test/exposed_test.rb +7 -0
  59. data/test/integration/delete_test.rb +25 -0
  60. data/test/integration/get_test.rb +53 -0
  61. data/test/integration/post_test.rb +25 -0
  62. data/test/integration/put_test.rb +25 -0
  63. data/test/test_helper.rb +41 -0
  64. metadata +186 -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,13 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ comment_1:
4
+ post: post_1
5
+ content: You are right.
6
+
7
+ comment_2:
8
+ post: post_1
9
+ content: You are wrong.
10
+
11
+ comment_3:
12
+ post: post_2
13
+ content: You are both right and wrong.
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ post_1:
4
+ id: 1
5
+ title: First post
6
+ content: Content of the first post
7
+
8
+ post_2:
9
+ id: 2
10
+ title: Second post
11
+ content: Content of the second post
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class PostsControllerTest < ActionController::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+
8
+ def logger
9
+ ::Rails.logger
10
+ end
11
+
12
+ test "should get collection" do
13
+ get :index
14
+ logger.debug "Helloooo"
15
+ assert_response :success
16
+ #assert_not_nil assigns(:posts)
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class CommentTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class PostsHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class PostTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1 @@
1
+ 2311
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ExposedTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Exposed
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class DeleteTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ include ExposedTestDSL
7
+
8
+ test "should DELETE model" do
9
+ delete "/posts/2"
10
+
11
+ # Did we get something?
12
+ assert_response :success
13
+
14
+ # Did we get a hash?
15
+ assert_hash
16
+
17
+ # Did we get all the attributes?
18
+ assert_attrs
19
+
20
+ # Is the post missing now?
21
+ get "posts/2"
22
+ assert_response :missing
23
+ end
24
+ end
25
+
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ class GetTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ include ExposedTestDSL
7
+
8
+ test "should GET collection" do
9
+ get "/posts"
10
+
11
+ # Did we get something?
12
+ assert_response :success
13
+
14
+ # Did we get an array?
15
+ assert_array
16
+
17
+ # Did we get all the attributes?
18
+ assert_attrs
19
+ end
20
+
21
+ test "should GET collection with include" do
22
+ get "/posts?include=comments"
23
+
24
+ # Did we get something?
25
+ assert_response :success
26
+
27
+ # Did we get an array?
28
+ assert_array
29
+
30
+ # Did we get all the attributes?
31
+ assert_attrs
32
+
33
+ # Are comments one of the keys?
34
+ assert @keys.include? "comments"
35
+
36
+ # Are comments an array?
37
+ assert_instance_of Array, @posts.first["comments"]
38
+ end
39
+
40
+ test "should GET model" do
41
+ get "/posts/1"
42
+
43
+ # Did we get something?
44
+ assert_response :success
45
+
46
+ # Did we get a hash?
47
+ assert_hash
48
+
49
+ # Did we get all the attributes?
50
+ assert_attrs
51
+ end
52
+ end
53
+
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class PostTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ include ExposedTestDSL
7
+
8
+ test "should POST model" do
9
+ @data = { "title" => "Third post", "content" => "Content of the third post" }
10
+ post "/posts", @data.to_json, { "CONTENT_TYPE" => 'application/json', "ACCEPT" => "application/json" }
11
+
12
+ # Did we get something?
13
+ assert_response :success
14
+
15
+ # Did we get a hash?
16
+ assert_hash
17
+
18
+ # Did we get all the attributes?
19
+ assert_attrs
20
+
21
+ # Are attribute values right?
22
+ assert_values
23
+ end
24
+ end
25
+
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class PutTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ include ExposedTestDSL
7
+
8
+ test "should PUT model" do
9
+ @data = { "title" => "Changed post", "content" => "Content of the changed post" }
10
+ put "/posts/2", @data.to_json, { "CONTENT_TYPE" => 'application/json', "ACCEPT" => "application/json" }
11
+
12
+ # Did we get something?
13
+ assert_response :success
14
+
15
+ # Did we get a hash?
16
+ assert_hash
17
+
18
+ # Did we get all the attributes?
19
+ assert_attrs
20
+
21
+ # Are attributes values changed?
22
+ assert_values
23
+ end
24
+ end
25
+
@@ -0,0 +1,41 @@
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 }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../dummy/test/fixtures", __FILE__)
15
+ end
16
+
17
+ module ExposedTestDSL
18
+ def assert_array
19
+ @posts = JSON.parse response.body
20
+ assert_instance_of Array, @posts
21
+
22
+ @post = @posts.first
23
+ end
24
+
25
+ def assert_hash
26
+ @post = JSON.parse response.body
27
+ assert_instance_of Hash, @post
28
+ end
29
+
30
+ def assert_attrs
31
+ @keys = @post.keys
32
+ attrs = Post.accessible_attributes.to_a
33
+ diff = attrs - @keys
34
+ assert_equal 1, diff.length # It's OK if we get more than we need
35
+ end
36
+
37
+ def assert_values
38
+ diff = @data.to_a - @post.to_a
39
+ assert diff.empty?
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exposed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rodoljub Petrovic
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &80214180 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *80214180
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3
27
+ requirement: &80213930 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *80213930
36
+ description: A Rails engine that exposes ActiveRecord models as JSON API with minimum
37
+ hassle
38
+ email:
39
+ - me@rodpetrovic.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - app/controllers/exposed/base.rb
45
+ - config/routes.rb
46
+ - lib/tasks/exposed_tasks.rake
47
+ - lib/exposed.rb
48
+ - lib/exposed/engine.rb
49
+ - lib/exposed/version.rb
50
+ - MIT-LICENSE
51
+ - Rakefile
52
+ - README.md
53
+ - test/integration/get_test.rb
54
+ - test/integration/post_test.rb
55
+ - test/integration/delete_test.rb
56
+ - test/integration/put_test.rb
57
+ - test/exposed_test.rb
58
+ - test/test_helper.rb
59
+ - test/dummy/config/application.rb
60
+ - test/dummy/config/database.yml
61
+ - test/dummy/config/initializers/secret_token.rb
62
+ - test/dummy/config/initializers/wrap_parameters.rb
63
+ - test/dummy/config/initializers/backtrace_silencers.rb
64
+ - test/dummy/config/initializers/mime_types.rb
65
+ - test/dummy/config/initializers/session_store.rb
66
+ - test/dummy/config/initializers/inflections.rb
67
+ - test/dummy/config/environment.rb
68
+ - test/dummy/config/environments/development.rb
69
+ - test/dummy/config/environments/test.rb
70
+ - test/dummy/config/environments/production.rb
71
+ - test/dummy/config/boot.rb
72
+ - test/dummy/config/routes.rb
73
+ - test/dummy/config/locales/en.yml
74
+ - test/dummy/config.ru
75
+ - test/dummy/README.rdoc
76
+ - test/dummy/app/assets/stylesheets/posts.css
77
+ - test/dummy/app/assets/stylesheets/application.css
78
+ - test/dummy/app/assets/javascripts/posts.js
79
+ - test/dummy/app/assets/javascripts/application.js
80
+ - test/dummy/app/controllers/application_controller.rb
81
+ - test/dummy/app/controllers/posts_controller.rb
82
+ - test/dummy/app/views/layouts/application.html.erb
83
+ - test/dummy/app/helpers/posts_helper.rb
84
+ - test/dummy/app/helpers/application_helper.rb
85
+ - test/dummy/app/models/post.rb
86
+ - test/dummy/app/models/comment.rb
87
+ - test/dummy/Rakefile
88
+ - test/dummy/log/test.log
89
+ - test/dummy/log/development.log
90
+ - test/dummy/db/schema.rb
91
+ - test/dummy/db/test.sqlite3
92
+ - test/dummy/db/development.sqlite3
93
+ - test/dummy/db/migrate/20121013230216_create_comments.rb
94
+ - test/dummy/db/migrate/20121013230139_create_posts.rb
95
+ - test/dummy/public/404.html
96
+ - test/dummy/public/422.html
97
+ - test/dummy/public/500.html
98
+ - test/dummy/public/favicon.ico
99
+ - test/dummy/script/rails
100
+ - test/dummy/test/unit/post_test.rb
101
+ - test/dummy/test/unit/comment_test.rb
102
+ - test/dummy/test/unit/helpers/posts_helper_test.rb
103
+ - test/dummy/test/fixtures/posts.yml
104
+ - test/dummy/test/fixtures/comments.yml
105
+ - test/dummy/test/functional/posts_controller_test.rb
106
+ - test/dummy/tmp/pids/server.pid
107
+ homepage: https://github.com/rodp/exposed
108
+ licenses: []
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.10
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: A Rails engine that exposes ActiveRecord models as JSON API with minimum
131
+ hassle
132
+ test_files:
133
+ - test/integration/get_test.rb
134
+ - test/integration/post_test.rb
135
+ - test/integration/delete_test.rb
136
+ - test/integration/put_test.rb
137
+ - test/exposed_test.rb
138
+ - test/test_helper.rb
139
+ - test/dummy/config/application.rb
140
+ - test/dummy/config/database.yml
141
+ - test/dummy/config/initializers/secret_token.rb
142
+ - test/dummy/config/initializers/wrap_parameters.rb
143
+ - test/dummy/config/initializers/backtrace_silencers.rb
144
+ - test/dummy/config/initializers/mime_types.rb
145
+ - test/dummy/config/initializers/session_store.rb
146
+ - test/dummy/config/initializers/inflections.rb
147
+ - test/dummy/config/environment.rb
148
+ - test/dummy/config/environments/development.rb
149
+ - test/dummy/config/environments/test.rb
150
+ - test/dummy/config/environments/production.rb
151
+ - test/dummy/config/boot.rb
152
+ - test/dummy/config/routes.rb
153
+ - test/dummy/config/locales/en.yml
154
+ - test/dummy/config.ru
155
+ - test/dummy/README.rdoc
156
+ - test/dummy/app/assets/stylesheets/posts.css
157
+ - test/dummy/app/assets/stylesheets/application.css
158
+ - test/dummy/app/assets/javascripts/posts.js
159
+ - test/dummy/app/assets/javascripts/application.js
160
+ - test/dummy/app/controllers/application_controller.rb
161
+ - test/dummy/app/controllers/posts_controller.rb
162
+ - test/dummy/app/views/layouts/application.html.erb
163
+ - test/dummy/app/helpers/posts_helper.rb
164
+ - test/dummy/app/helpers/application_helper.rb
165
+ - test/dummy/app/models/post.rb
166
+ - test/dummy/app/models/comment.rb
167
+ - test/dummy/Rakefile
168
+ - test/dummy/log/test.log
169
+ - test/dummy/log/development.log
170
+ - test/dummy/db/schema.rb
171
+ - test/dummy/db/test.sqlite3
172
+ - test/dummy/db/development.sqlite3
173
+ - test/dummy/db/migrate/20121013230216_create_comments.rb
174
+ - test/dummy/db/migrate/20121013230139_create_posts.rb
175
+ - test/dummy/public/404.html
176
+ - test/dummy/public/422.html
177
+ - test/dummy/public/500.html
178
+ - test/dummy/public/favicon.ico
179
+ - test/dummy/script/rails
180
+ - test/dummy/test/unit/post_test.rb
181
+ - test/dummy/test/unit/comment_test.rb
182
+ - test/dummy/test/unit/helpers/posts_helper_test.rb
183
+ - test/dummy/test/fixtures/posts.yml
184
+ - test/dummy/test/fixtures/comments.yml
185
+ - test/dummy/test/functional/posts_controller_test.rb
186
+ - test/dummy/tmp/pids/server.pid