api_engine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +20 -0
  3. data/README.md +33 -0
  4. data/Rakefile +16 -0
  5. data/app/assets/javascripts/api_engine/application.js +15 -0
  6. data/app/assets/stylesheets/api_engine/application.css +13 -0
  7. data/app/controllers/api_engine/application_controller.rb +90 -0
  8. data/app/helpers/api_engine/application_helper.rb +4 -0
  9. data/app/views/layouts/api_engine/application.html.erb +14 -0
  10. data/config/routes.rb +11 -0
  11. data/lib/api_engine.rb +6 -0
  12. data/lib/api_engine/config.rb +24 -0
  13. data/lib/api_engine/engine.rb +13 -0
  14. data/lib/api_engine/version.rb +3 -0
  15. data/lib/generators/api_engine/config_generator.rb +16 -0
  16. data/lib/generators/api_engine/templates/api_engine_config.rb +9 -0
  17. data/lib/tasks/api_engine_tasks.rake +4 -0
  18. data/spec/dummy/README.rdoc +261 -0
  19. data/spec/dummy/Rakefile +7 -0
  20. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  21. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  22. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  23. data/spec/dummy/app/controllers/posts_controller.rb +3 -0
  24. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/dummy/app/models/post.rb +3 -0
  26. data/spec/dummy/app/serializers/post_serializer.rb +3 -0
  27. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  28. data/spec/dummy/config.ru +4 -0
  29. data/spec/dummy/config/application.rb +65 -0
  30. data/spec/dummy/config/boot.rb +10 -0
  31. data/spec/dummy/config/database.yml +24 -0
  32. data/spec/dummy/config/environment.rb +5 -0
  33. data/spec/dummy/config/environments/development.rb +37 -0
  34. data/spec/dummy/config/environments/production.rb +67 -0
  35. data/spec/dummy/config/environments/test.rb +37 -0
  36. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  37. data/spec/dummy/config/initializers/inflections.rb +15 -0
  38. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  39. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  40. data/spec/dummy/config/initializers/session_store.rb +8 -0
  41. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  42. data/spec/dummy/config/locales/en.yml +5 -0
  43. data/spec/dummy/config/routes.rb +3 -0
  44. data/spec/dummy/db/development.sqlite3 +0 -0
  45. data/spec/dummy/db/migrate/20130408032158_create_posts.rb +9 -0
  46. data/spec/dummy/db/schema.rb +22 -0
  47. data/spec/dummy/db/test.sqlite3 +0 -0
  48. data/spec/dummy/log/development.log +1557 -0
  49. data/spec/dummy/log/test.log +14900 -0
  50. data/spec/dummy/public/404.html +26 -0
  51. data/spec/dummy/public/422.html +26 -0
  52. data/spec/dummy/public/500.html +25 -0
  53. data/spec/dummy/public/favicon.ico +0 -0
  54. data/spec/dummy/script/rails +6 -0
  55. data/spec/requests/configuration_spec.rb +42 -0
  56. data/spec/requests/default_api_spec.rb +138 -0
  57. data/spec/spec_helper.rb +27 -0
  58. metadata +238 -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,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Configuration Spec' do
4
+ describe 'config.whitelist' do
5
+
6
+ before { Post.create(title: "Test") }
7
+
8
+ after do
9
+ ApiEngine.configure do |config|
10
+ config.whitelist = false
11
+ end
12
+ end
13
+
14
+ context 'Post is not on the whitelist' do
15
+
16
+ before do
17
+ ApiEngine.configure do |config|
18
+ config.whitelist = [:comment]
19
+ end
20
+ end
21
+
22
+ it "allows access to the model's API" do
23
+ get '/api/posts'
24
+ response.status.should eq(404)
25
+ end
26
+ end
27
+
28
+ context 'Post is on the whitelist' do
29
+
30
+ before do
31
+ ApiEngine.configure do |config|
32
+ config.whitelist = [:post]
33
+ end
34
+ end
35
+
36
+ it "allows access to the model's API" do
37
+ get '/api/posts'
38
+ response.status.should eq(200)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,138 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Default API' do
4
+ describe '#index' do
5
+ before do
6
+ Post.create(title: "Test")
7
+ get '/api/posts'
8
+ end
9
+
10
+ it "uses a plural json root" do
11
+ JSON.parse(response.body).should have_key('posts')
12
+ end
13
+
14
+ it "returns all the posts" do
15
+ JSON.parse(response.body).keys.should have(1).item
16
+ end
17
+ end
18
+
19
+ describe '#show' do
20
+ before do
21
+ Post.create(title: "Test")
22
+ get '/api/posts/1'
23
+ end
24
+
25
+ it "uses a singular json root" do
26
+ JSON.parse(response.body).should have_key('post')
27
+ end
28
+
29
+ it "returns the post" do
30
+ JSON.parse(response.body)['post']['title'].should eq('Test')
31
+ end
32
+ end
33
+
34
+ describe '#create' do
35
+ context "singular create" do
36
+ before do
37
+ post '/api/posts', post: { title: 'Created post'}
38
+ end
39
+
40
+ it "returns a correct response code" do
41
+ response.status.should eq(201)
42
+ end
43
+
44
+ it "creates a post" do
45
+ Post.first.title.should eq("Created post")
46
+ end
47
+
48
+ it "returns a post with an id" do
49
+ JSON.parse(response.body)['post']['id'].should_not be_nil
50
+ end
51
+ end
52
+
53
+ context "bulk create" do
54
+ before do
55
+ post '/api/posts', posts: [{ title: 'First new post' },{ title: 'Second new post' }]
56
+ end
57
+
58
+ it "returns a correct response code" do
59
+ response.status.should eq(201)
60
+ end
61
+
62
+ it "creates multiple posts" do
63
+ Post.count.should eq(2)
64
+ end
65
+ end
66
+ end
67
+
68
+ describe '#update' do
69
+ before do
70
+ Post.create(title: "Test")
71
+ put '/api/posts/1', post: { title: 'Changed' }
72
+ end
73
+
74
+ it "returns a correct response code" do
75
+ response.status.should eq(200)
76
+ end
77
+
78
+ it "returns the saved post" do
79
+ JSON.parse(response.body)['post'].should eq({'id' => 1, 'title' => 'Changed'})
80
+ end
81
+
82
+ it "updates a post" do
83
+ Post.find(1).title.should eq("Changed")
84
+ end
85
+ end
86
+
87
+ describe "#bulk_update" do
88
+ before do
89
+ Post.create(title: "Test")
90
+ Post.create(title: "Test 2")
91
+ put '/api/posts/bulk', posts: [{ id: 1, title: 'Changed' }, { id: 2, title: 'Changed 2'}]
92
+ end
93
+
94
+ it "returns a correct response code" do
95
+ response.status.should eq(200)
96
+ end
97
+
98
+ it "returns the saved posts" do
99
+ JSON.parse(response.body)['posts'].should =~ [{ 'id' => 1, 'title' => 'Changed' }, { 'id' => 2, 'title' => 'Changed 2'}]
100
+ end
101
+
102
+ it "updates the posts" do
103
+ Post.find(1).title.should eq("Changed")
104
+ Post.find(2).title.should eq("Changed 2")
105
+ end
106
+ end
107
+
108
+ describe '#destroy' do
109
+ before do
110
+ Post.create(title: "Test")
111
+ delete '/api/posts/1'
112
+ end
113
+
114
+ it "returns a correct response code" do
115
+ response.status.should eq(204)
116
+ end
117
+
118
+ it "deletes the record" do
119
+ Post.count.should eq(0)
120
+ end
121
+ end
122
+
123
+ describe '#bulk_destroy' do
124
+ before do
125
+ Post.create(title: "Test")
126
+ Post.create(title: "Test 2")
127
+ delete '/api/posts/bulk', posts: [{ id: 1, title: 'Test' }, { id: 2, title: 'Test 2'}]
128
+ end
129
+
130
+ it "returns a correct response code" do
131
+ response.status.should eq(204)
132
+ end
133
+
134
+ it "deletes the sent records" do
135
+ Post.count.should eq(0)
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,27 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+
3
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'factory_girl_rails'
6
+ require 'database_cleaner'
7
+ require 'pry'
8
+
9
+ Rails.backtrace_cleaner.remove_silencers!
10
+ # Load support files
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+
13
+ RSpec.configure do |config|
14
+ config.mock_with :rspec
15
+ config.order = "random"
16
+ config.use_transactional_fixtures = false
17
+
18
+ DatabaseCleaner.strategy = :truncation
19
+
20
+ config.before(:each) do
21
+ DatabaseCleaner.start
22
+ end
23
+
24
+ config.after(:each) do
25
+ DatabaseCleaner.clean
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,238 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: api_engine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steven Faulkner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.13
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.13
27
+ - !ruby/object:Gem::Dependency
28
+ name: active_model_serializers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl_rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: database_cleaner
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: An API engine for Rails. Structure of the API is opinionated and designed
112
+ to directly interface with ember-data.
113
+ email:
114
+ - southpolesteve@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - app/assets/javascripts/api_engine/application.js
120
+ - app/assets/stylesheets/api_engine/application.css
121
+ - app/controllers/api_engine/application_controller.rb
122
+ - app/helpers/api_engine/application_helper.rb
123
+ - app/views/layouts/api_engine/application.html.erb
124
+ - config/routes.rb
125
+ - lib/api_engine/config.rb
126
+ - lib/api_engine/engine.rb
127
+ - lib/api_engine/version.rb
128
+ - lib/api_engine.rb
129
+ - lib/generators/api_engine/config_generator.rb
130
+ - lib/generators/api_engine/templates/api_engine_config.rb
131
+ - lib/tasks/api_engine_tasks.rake
132
+ - LICENSE.md
133
+ - Rakefile
134
+ - README.md
135
+ - spec/dummy/app/assets/javascripts/application.js
136
+ - spec/dummy/app/assets/stylesheets/application.css
137
+ - spec/dummy/app/controllers/application_controller.rb
138
+ - spec/dummy/app/controllers/posts_controller.rb
139
+ - spec/dummy/app/helpers/application_helper.rb
140
+ - spec/dummy/app/models/post.rb
141
+ - spec/dummy/app/serializers/post_serializer.rb
142
+ - spec/dummy/app/views/layouts/application.html.erb
143
+ - spec/dummy/config/application.rb
144
+ - spec/dummy/config/boot.rb
145
+ - spec/dummy/config/database.yml
146
+ - spec/dummy/config/environment.rb
147
+ - spec/dummy/config/environments/development.rb
148
+ - spec/dummy/config/environments/production.rb
149
+ - spec/dummy/config/environments/test.rb
150
+ - spec/dummy/config/initializers/backtrace_silencers.rb
151
+ - spec/dummy/config/initializers/inflections.rb
152
+ - spec/dummy/config/initializers/mime_types.rb
153
+ - spec/dummy/config/initializers/secret_token.rb
154
+ - spec/dummy/config/initializers/session_store.rb
155
+ - spec/dummy/config/initializers/wrap_parameters.rb
156
+ - spec/dummy/config/locales/en.yml
157
+ - spec/dummy/config/routes.rb
158
+ - spec/dummy/config.ru
159
+ - spec/dummy/db/development.sqlite3
160
+ - spec/dummy/db/migrate/20130408032158_create_posts.rb
161
+ - spec/dummy/db/schema.rb
162
+ - spec/dummy/db/test.sqlite3
163
+ - spec/dummy/log/development.log
164
+ - spec/dummy/log/test.log
165
+ - spec/dummy/public/404.html
166
+ - spec/dummy/public/422.html
167
+ - spec/dummy/public/500.html
168
+ - spec/dummy/public/favicon.ico
169
+ - spec/dummy/Rakefile
170
+ - spec/dummy/README.rdoc
171
+ - spec/dummy/script/rails
172
+ - spec/requests/configuration_spec.rb
173
+ - spec/requests/default_api_spec.rb
174
+ - spec/spec_helper.rb
175
+ homepage: https://github.com/southpolesteve/api_engine
176
+ licenses: []
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.0.3
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: An API engine for Rails
198
+ test_files:
199
+ - spec/dummy/app/assets/javascripts/application.js
200
+ - spec/dummy/app/assets/stylesheets/application.css
201
+ - spec/dummy/app/controllers/application_controller.rb
202
+ - spec/dummy/app/controllers/posts_controller.rb
203
+ - spec/dummy/app/helpers/application_helper.rb
204
+ - spec/dummy/app/models/post.rb
205
+ - spec/dummy/app/serializers/post_serializer.rb
206
+ - spec/dummy/app/views/layouts/application.html.erb
207
+ - spec/dummy/config/application.rb
208
+ - spec/dummy/config/boot.rb
209
+ - spec/dummy/config/database.yml
210
+ - spec/dummy/config/environment.rb
211
+ - spec/dummy/config/environments/development.rb
212
+ - spec/dummy/config/environments/production.rb
213
+ - spec/dummy/config/environments/test.rb
214
+ - spec/dummy/config/initializers/backtrace_silencers.rb
215
+ - spec/dummy/config/initializers/inflections.rb
216
+ - spec/dummy/config/initializers/mime_types.rb
217
+ - spec/dummy/config/initializers/secret_token.rb
218
+ - spec/dummy/config/initializers/session_store.rb
219
+ - spec/dummy/config/initializers/wrap_parameters.rb
220
+ - spec/dummy/config/locales/en.yml
221
+ - spec/dummy/config/routes.rb
222
+ - spec/dummy/config.ru
223
+ - spec/dummy/db/development.sqlite3
224
+ - spec/dummy/db/migrate/20130408032158_create_posts.rb
225
+ - spec/dummy/db/schema.rb
226
+ - spec/dummy/db/test.sqlite3
227
+ - spec/dummy/log/development.log
228
+ - spec/dummy/log/test.log
229
+ - spec/dummy/public/404.html
230
+ - spec/dummy/public/422.html
231
+ - spec/dummy/public/500.html
232
+ - spec/dummy/public/favicon.ico
233
+ - spec/dummy/Rakefile
234
+ - spec/dummy/README.rdoc
235
+ - spec/dummy/script/rails
236
+ - spec/requests/configuration_spec.rb
237
+ - spec/requests/default_api_spec.rb
238
+ - spec/spec_helper.rb