hypermodel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +63 -0
  3. data/Rakefile +38 -0
  4. data/lib/hypermodel/responder.rb +29 -0
  5. data/lib/hypermodel/serializers/mongoid.rb +76 -0
  6. data/lib/hypermodel/version.rb +3 -0
  7. data/lib/hypermodel.rb +5 -0
  8. data/lib/tasks/hypermodel_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 +13 -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/controllers/posts_controller.rb +8 -0
  15. data/test/dummy/app/helpers/application_helper.rb +2 -0
  16. data/test/dummy/app/models/author.rb +8 -0
  17. data/test/dummy/app/models/comment.rb +8 -0
  18. data/test/dummy/app/models/post.rb +11 -0
  19. data/test/dummy/app/models/review.rb +8 -0
  20. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  21. data/test/dummy/config/application.rb +64 -0
  22. data/test/dummy/config/boot.rb +10 -0
  23. data/test/dummy/config/environment.rb +5 -0
  24. data/test/dummy/config/environments/development.rb +31 -0
  25. data/test/dummy/config/environments/production.rb +64 -0
  26. data/test/dummy/config/environments/test.rb +35 -0
  27. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/test/dummy/config/initializers/inflections.rb +15 -0
  29. data/test/dummy/config/initializers/mime_types.rb +5 -0
  30. data/test/dummy/config/initializers/secret_token.rb +7 -0
  31. data/test/dummy/config/initializers/session_store.rb +8 -0
  32. data/test/dummy/config/initializers/wrap_parameters.rb +10 -0
  33. data/test/dummy/config/locales/en.yml +5 -0
  34. data/test/dummy/config/mongoid.yml +20 -0
  35. data/test/dummy/config/routes.rb +6 -0
  36. data/test/dummy/config.ru +4 -0
  37. data/test/dummy/log/development.log +2 -0
  38. data/test/dummy/log/test.log +4107 -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/hypermodel_test.rb +63 -0
  45. data/test/test_helper.rb +15 -0
  46. metadata +183 -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,63 @@
1
+ require 'test_helper'
2
+ require 'json'
3
+
4
+ class PostsControllerTest < ActionController::TestCase
5
+ def setup
6
+ @post = Post.create(
7
+ title: "My post",
8
+ body: "Foo bar baz.",
9
+ comments: [
10
+ Comment.new(body: 'Comment 1'),
11
+ Comment.new(body: 'Comment 2'),
12
+ ],
13
+ author: Author.create(name: 'John Smith'),
14
+ reviews: [
15
+ Review.create(body: 'This is bad'),
16
+ Review.create(body: 'This is good'),
17
+ ]
18
+ )
19
+
20
+ post :show, { id: @post.id, format: :json }
21
+ end
22
+
23
+ test "it returns a successful response" do
24
+ assert response.successful?
25
+ end
26
+
27
+ test "returns the post" do
28
+ body = JSON.load(response.body)
29
+
30
+ assert_equal @post.id.to_s, body['_id']
31
+ assert_equal 'My post', body['title']
32
+ assert_equal 'Foo bar baz.', body['body']
33
+ end
34
+
35
+ test "returns the embedded comments" do
36
+ body = JSON.load(response.body)
37
+
38
+ assert_nil body['comments']
39
+ comments = body['_embedded']['comments']
40
+
41
+ assert_equal 'Comment 1', comments.first['body']
42
+ assert_equal 'Comment 2', comments.last['body']
43
+ end
44
+
45
+ test "returns the self link" do
46
+ body = JSON.load(response.body)
47
+ assert_match /\/posts\/#{@post.id}/, body['_links']['self']['href']
48
+ end
49
+
50
+ test "returns the parent author" do
51
+ body = JSON.load(response.body)
52
+
53
+ assert_nil body['author']
54
+ assert_match /\/authors\/#{@post.author.id}/, body['_links']['author']['href']
55
+ end
56
+
57
+ test "returns the links to its reviews" do
58
+ body = JSON.load(response.body)
59
+
60
+ assert_nil body['reviews']
61
+ assert_match %r{/posts/#{@post.id}/reviews}, body['_links']['reviews']['href']
62
+ end
63
+ end
@@ -0,0 +1,15 @@
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("../fixtures", __FILE__)
15
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hypermodel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josep M. Bach
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-18 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.2.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.2.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: mongoid
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
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'
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'
62
+ description: Rails Responder to generate an automagic JSON HAL representation for
63
+ your Mongoid models
64
+ email:
65
+ - josep.m.bach@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - lib/hypermodel/responder.rb
71
+ - lib/hypermodel/serializers/mongoid.rb
72
+ - lib/hypermodel/version.rb
73
+ - lib/hypermodel.rb
74
+ - lib/tasks/hypermodel_tasks.rake
75
+ - MIT-LICENSE
76
+ - Rakefile
77
+ - README.md
78
+ - test/dummy/app/assets/javascripts/application.js
79
+ - test/dummy/app/assets/stylesheets/application.css
80
+ - test/dummy/app/controllers/application_controller.rb
81
+ - test/dummy/app/controllers/posts_controller.rb
82
+ - test/dummy/app/helpers/application_helper.rb
83
+ - test/dummy/app/models/author.rb
84
+ - test/dummy/app/models/comment.rb
85
+ - test/dummy/app/models/post.rb
86
+ - test/dummy/app/models/review.rb
87
+ - test/dummy/app/views/layouts/application.html.erb
88
+ - test/dummy/config/application.rb
89
+ - test/dummy/config/boot.rb
90
+ - test/dummy/config/environment.rb
91
+ - test/dummy/config/environments/development.rb
92
+ - test/dummy/config/environments/production.rb
93
+ - test/dummy/config/environments/test.rb
94
+ - test/dummy/config/initializers/backtrace_silencers.rb
95
+ - test/dummy/config/initializers/inflections.rb
96
+ - test/dummy/config/initializers/mime_types.rb
97
+ - test/dummy/config/initializers/secret_token.rb
98
+ - test/dummy/config/initializers/session_store.rb
99
+ - test/dummy/config/initializers/wrap_parameters.rb
100
+ - test/dummy/config/locales/en.yml
101
+ - test/dummy/config/mongoid.yml
102
+ - test/dummy/config/routes.rb
103
+ - test/dummy/config.ru
104
+ - test/dummy/log/development.log
105
+ - test/dummy/log/test.log
106
+ - test/dummy/public/404.html
107
+ - test/dummy/public/422.html
108
+ - test/dummy/public/500.html
109
+ - test/dummy/public/favicon.ico
110
+ - test/dummy/Rakefile
111
+ - test/dummy/README.rdoc
112
+ - test/dummy/script/rails
113
+ - test/hypermodel_test.rb
114
+ - test/test_helper.rb
115
+ homepage: https://github.com/codegram/hypermodel
116
+ licenses: []
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ segments:
128
+ - 0
129
+ hash: -711433516152694820
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ segments:
137
+ - 0
138
+ hash: -711433516152694820
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.21
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Rails Responder to generate an automagic JSON HAL representation for your
145
+ Mongoid models
146
+ test_files:
147
+ - test/dummy/app/assets/javascripts/application.js
148
+ - test/dummy/app/assets/stylesheets/application.css
149
+ - test/dummy/app/controllers/application_controller.rb
150
+ - test/dummy/app/controllers/posts_controller.rb
151
+ - test/dummy/app/helpers/application_helper.rb
152
+ - test/dummy/app/models/author.rb
153
+ - test/dummy/app/models/comment.rb
154
+ - test/dummy/app/models/post.rb
155
+ - test/dummy/app/models/review.rb
156
+ - test/dummy/app/views/layouts/application.html.erb
157
+ - test/dummy/config/application.rb
158
+ - test/dummy/config/boot.rb
159
+ - test/dummy/config/environment.rb
160
+ - test/dummy/config/environments/development.rb
161
+ - test/dummy/config/environments/production.rb
162
+ - test/dummy/config/environments/test.rb
163
+ - test/dummy/config/initializers/backtrace_silencers.rb
164
+ - test/dummy/config/initializers/inflections.rb
165
+ - test/dummy/config/initializers/mime_types.rb
166
+ - test/dummy/config/initializers/secret_token.rb
167
+ - test/dummy/config/initializers/session_store.rb
168
+ - test/dummy/config/initializers/wrap_parameters.rb
169
+ - test/dummy/config/locales/en.yml
170
+ - test/dummy/config/mongoid.yml
171
+ - test/dummy/config/routes.rb
172
+ - test/dummy/config.ru
173
+ - test/dummy/log/development.log
174
+ - test/dummy/log/test.log
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/Rakefile
180
+ - test/dummy/README.rdoc
181
+ - test/dummy/script/rails
182
+ - test/hypermodel_test.rb
183
+ - test/test_helper.rb