lazymodel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +42 -0
  3. data/Rakefile +38 -0
  4. data/lib/lazymodel/base.rb +57 -0
  5. data/lib/lazymodel/version.rb +3 -0
  6. data/lib/lazymodel.rb +3 -0
  7. data/lib/tasks/lazymodel_tasks.rake +4 -0
  8. data/test/dummy/README.rdoc +261 -0
  9. data/test/dummy/Rakefile +7 -0
  10. data/test/dummy/app/assets/javascripts/application.js +15 -0
  11. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  12. data/test/dummy/app/controllers/application_controller.rb +3 -0
  13. data/test/dummy/app/controllers/people_controller.rb +11 -0
  14. data/test/dummy/app/helpers/application_helper.rb +2 -0
  15. data/test/dummy/app/models/person.rb +5 -0
  16. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  17. data/test/dummy/app/views/people/_form.html.erb +25 -0
  18. data/test/dummy/app/views/people/new.html.erb +6 -0
  19. data/test/dummy/config/application.rb +59 -0
  20. data/test/dummy/config/boot.rb +10 -0
  21. data/test/dummy/config/database.yml +25 -0
  22. data/test/dummy/config/environment.rb +5 -0
  23. data/test/dummy/config/environments/development.rb +37 -0
  24. data/test/dummy/config/environments/production.rb +67 -0
  25. data/test/dummy/config/environments/test.rb +37 -0
  26. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  27. data/test/dummy/config/initializers/inflections.rb +15 -0
  28. data/test/dummy/config/initializers/mime_types.rb +5 -0
  29. data/test/dummy/config/initializers/secret_token.rb +7 -0
  30. data/test/dummy/config/initializers/session_store.rb +8 -0
  31. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  32. data/test/dummy/config/locales/en.yml +5 -0
  33. data/test/dummy/config/routes.rb +62 -0
  34. data/test/dummy/config.ru +4 -0
  35. data/test/dummy/db/development.sqlite3 +0 -0
  36. data/test/dummy/db/schema.rb +16 -0
  37. data/test/dummy/db/test.sqlite3 +0 -0
  38. data/test/dummy/log/development.log +199 -0
  39. data/test/dummy/log/test.log +1901 -0
  40. data/test/dummy/public/404.html +26 -0
  41. data/test/dummy/public/422.html +26 -0
  42. data/test/dummy/public/500.html +25 -0
  43. data/test/dummy/public/favicon.ico +0 -0
  44. data/test/dummy/script/rails +6 -0
  45. data/test/dummy/test/functional/people_controller_test.rb +8 -0
  46. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  47. data/test/dummy/tmp/cache/assets/D04/E10/sprockets%2Ff9a58934847d69f991643ea9ce593d0c +0 -0
  48. data/test/dummy/tmp/cache/assets/D24/8A0/sprockets%2F6c57bde1948f1b0941485d675c2f98ec +0 -0
  49. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  50. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  51. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  52. data/test/dummy/tmp/cache/assets/D95/110/sprockets%2Fb163af63a5cf08224ec72ba45c84bc8e +0 -0
  53. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  54. data/test/dummy/tmp/cache/assets/E00/F20/sprockets%2Ff3fc35f5618dfeec2cb7bc6b415c227f +0 -0
  55. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  56. data/test/dummy/tmp/pids/server.pid +1 -0
  57. data/test/fixtures/sample_model.rb +13 -0
  58. data/test/integration/people_validation_test.rb +23 -0
  59. data/test/lazymodel_test.rb +7 -0
  60. data/test/sample_model_test.rb +57 -0
  61. data/test/test_helper.rb +17 -0
  62. metadata +246 -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,8 @@
1
+ require 'test_helper'
2
+
3
+ class PeopleControllerTest < ActionController::TestCase
4
+ test "should get new" do
5
+ get :new
6
+ assert_response :success
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ 52162
@@ -0,0 +1,13 @@
1
+ class SampleModel < Lazymodel::Base
2
+ activemodel_attributes :name, :surname, :prefix => 'clear_', :suffix => '?'
3
+
4
+ private
5
+
6
+ def clear_attribute(attribute)
7
+ send("#{attribute}=", nil)
8
+ end
9
+
10
+ def attribute?(attribute)
11
+ send(attribute).present?
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class PeopleValidationClass < ActiveSupport::TestCase
4
+ test 'renders person form' do
5
+ visit '/people/new'
6
+ assert_match /Validate Person/, page.body
7
+ end
8
+
9
+ test 'successfully validates valid person' do
10
+ visit '/people/new'
11
+ fill_in 'Name', :with => 'john'
12
+ fill_in 'Surname', :with => 'doe'
13
+ click_button 'Validate'
14
+ assert_match /Person is valid/, page.body
15
+ end
16
+
17
+ test 'does not validate invalid person' do
18
+ visit '/people/new'
19
+ fill_in 'Name', :with => 'john'
20
+ click_button 'Validate'
21
+ assert_match /Person is not valid/, page.body
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class LazymodelTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Lazymodel
6
+ end
7
+ end
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+ require 'fixtures/sample_model'
3
+
4
+ class SampleModelTest < ActiveSupport::TestCase
5
+ include ActiveModel::Lint::Tests
6
+
7
+ def setup
8
+ @model = SampleModel.new
9
+ set_model_attributes
10
+ end
11
+
12
+ test 'has name and surname attributes' do
13
+ assert_equal 'john', @model.name
14
+ assert_equal 'doe', @model.surname
15
+ end
16
+
17
+ test 'has clear prefix for attributes' do
18
+ @model.clear_name
19
+ @model.clear_surname
20
+ assert_nil @model.name
21
+ assert_nil @model.surname
22
+ end
23
+
24
+ test 'has ? suffix attributes' do
25
+ @model.clear_surname
26
+ assert @model.name?
27
+ assert !@model.surname?
28
+ end
29
+
30
+ test 'accepts attributes on initialization' do
31
+ model = SampleModel.new(:name => 'john')
32
+ assert_equal 'john', model.name
33
+ end
34
+
35
+ test 'has expected attributes' do
36
+ attributes = {
37
+ 'name' => 'john',
38
+ 'surname' => 'doe'
39
+ }
40
+ assert_empty attributes.keys - @model.attributes.keys
41
+ assert_empty attributes.values - @model.attributes.values
42
+ end
43
+
44
+ test 'allows for translations' do
45
+ translations = {:activemodel => {:models => {:sample_model => 'Sample'}}}
46
+ I18n.backend.store_translations :en, translations
47
+ assert_equal 'Sample', @model.class.model_name.human
48
+ I18n.backend.reload!
49
+ end
50
+
51
+ private
52
+
53
+ def set_model_attributes
54
+ @model.name = 'john'
55
+ @model.surname = 'doe'
56
+ end
57
+ end
@@ -0,0 +1,17 @@
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
+ require 'capybara/rails'
7
+ include Capybara::DSL
8
+
9
+ Rails.backtrace_cleaner.remove_silencers!
10
+
11
+ # Load support files
12
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
13
+
14
+ # Load fixtures from the engine
15
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
16
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
17
+ end
metadata ADDED
@@ -0,0 +1,246 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lazymodel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - andrea longhi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-08 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.7
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.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
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: mocha
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
+ - !ruby/object:Gem::Dependency
63
+ name: guard-test
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: capybara
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: adds basic activemodel goodness to your class in a eyeblink
95
+ email:
96
+ - andrea@spaghetticode.it
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - lib/lazymodel/base.rb
102
+ - lib/lazymodel/version.rb
103
+ - lib/lazymodel.rb
104
+ - lib/tasks/lazymodel_tasks.rake
105
+ - MIT-LICENSE
106
+ - Rakefile
107
+ - README.md
108
+ - test/dummy/app/assets/javascripts/application.js
109
+ - test/dummy/app/assets/stylesheets/application.css
110
+ - test/dummy/app/controllers/application_controller.rb
111
+ - test/dummy/app/controllers/people_controller.rb
112
+ - test/dummy/app/helpers/application_helper.rb
113
+ - test/dummy/app/models/person.rb
114
+ - test/dummy/app/views/layouts/application.html.erb
115
+ - test/dummy/app/views/people/_form.html.erb
116
+ - test/dummy/app/views/people/new.html.erb
117
+ - test/dummy/config/application.rb
118
+ - test/dummy/config/boot.rb
119
+ - test/dummy/config/database.yml
120
+ - test/dummy/config/environment.rb
121
+ - test/dummy/config/environments/development.rb
122
+ - test/dummy/config/environments/production.rb
123
+ - test/dummy/config/environments/test.rb
124
+ - test/dummy/config/initializers/backtrace_silencers.rb
125
+ - test/dummy/config/initializers/inflections.rb
126
+ - test/dummy/config/initializers/mime_types.rb
127
+ - test/dummy/config/initializers/secret_token.rb
128
+ - test/dummy/config/initializers/session_store.rb
129
+ - test/dummy/config/initializers/wrap_parameters.rb
130
+ - test/dummy/config/locales/en.yml
131
+ - test/dummy/config/routes.rb
132
+ - test/dummy/config.ru
133
+ - test/dummy/db/development.sqlite3
134
+ - test/dummy/db/schema.rb
135
+ - test/dummy/db/test.sqlite3
136
+ - test/dummy/log/development.log
137
+ - test/dummy/log/test.log
138
+ - test/dummy/public/404.html
139
+ - test/dummy/public/422.html
140
+ - test/dummy/public/500.html
141
+ - test/dummy/public/favicon.ico
142
+ - test/dummy/Rakefile
143
+ - test/dummy/README.rdoc
144
+ - test/dummy/script/rails
145
+ - test/dummy/test/functional/people_controller_test.rb
146
+ - test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953
147
+ - test/dummy/tmp/cache/assets/D04/E10/sprockets%2Ff9a58934847d69f991643ea9ce593d0c
148
+ - test/dummy/tmp/cache/assets/D24/8A0/sprockets%2F6c57bde1948f1b0941485d675c2f98ec
149
+ - test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705
150
+ - test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655
151
+ - test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6
152
+ - test/dummy/tmp/cache/assets/D95/110/sprockets%2Fb163af63a5cf08224ec72ba45c84bc8e
153
+ - test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
154
+ - test/dummy/tmp/cache/assets/E00/F20/sprockets%2Ff3fc35f5618dfeec2cb7bc6b415c227f
155
+ - test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
156
+ - test/dummy/tmp/pids/server.pid
157
+ - test/fixtures/sample_model.rb
158
+ - test/integration/people_validation_test.rb
159
+ - test/lazymodel_test.rb
160
+ - test/sample_model_test.rb
161
+ - test/test_helper.rb
162
+ homepage: ''
163
+ licenses: []
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ segments:
175
+ - 0
176
+ hash: -2666019996698459003
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ segments:
184
+ - 0
185
+ hash: -2666019996698459003
186
+ requirements: []
187
+ rubyforge_project:
188
+ rubygems_version: 1.8.24
189
+ signing_key:
190
+ specification_version: 3
191
+ summary: lazymodel is activemodel goodness for lazy people
192
+ test_files:
193
+ - test/dummy/app/assets/javascripts/application.js
194
+ - test/dummy/app/assets/stylesheets/application.css
195
+ - test/dummy/app/controllers/application_controller.rb
196
+ - test/dummy/app/controllers/people_controller.rb
197
+ - test/dummy/app/helpers/application_helper.rb
198
+ - test/dummy/app/models/person.rb
199
+ - test/dummy/app/views/layouts/application.html.erb
200
+ - test/dummy/app/views/people/_form.html.erb
201
+ - test/dummy/app/views/people/new.html.erb
202
+ - test/dummy/config/application.rb
203
+ - test/dummy/config/boot.rb
204
+ - test/dummy/config/database.yml
205
+ - test/dummy/config/environment.rb
206
+ - test/dummy/config/environments/development.rb
207
+ - test/dummy/config/environments/production.rb
208
+ - test/dummy/config/environments/test.rb
209
+ - test/dummy/config/initializers/backtrace_silencers.rb
210
+ - test/dummy/config/initializers/inflections.rb
211
+ - test/dummy/config/initializers/mime_types.rb
212
+ - test/dummy/config/initializers/secret_token.rb
213
+ - test/dummy/config/initializers/session_store.rb
214
+ - test/dummy/config/initializers/wrap_parameters.rb
215
+ - test/dummy/config/locales/en.yml
216
+ - test/dummy/config/routes.rb
217
+ - test/dummy/config.ru
218
+ - test/dummy/db/development.sqlite3
219
+ - test/dummy/db/schema.rb
220
+ - test/dummy/db/test.sqlite3
221
+ - test/dummy/log/development.log
222
+ - test/dummy/log/test.log
223
+ - test/dummy/public/404.html
224
+ - test/dummy/public/422.html
225
+ - test/dummy/public/500.html
226
+ - test/dummy/public/favicon.ico
227
+ - test/dummy/Rakefile
228
+ - test/dummy/README.rdoc
229
+ - test/dummy/script/rails
230
+ - test/dummy/test/functional/people_controller_test.rb
231
+ - test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953
232
+ - test/dummy/tmp/cache/assets/D04/E10/sprockets%2Ff9a58934847d69f991643ea9ce593d0c
233
+ - test/dummy/tmp/cache/assets/D24/8A0/sprockets%2F6c57bde1948f1b0941485d675c2f98ec
234
+ - test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705
235
+ - test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655
236
+ - test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6
237
+ - test/dummy/tmp/cache/assets/D95/110/sprockets%2Fb163af63a5cf08224ec72ba45c84bc8e
238
+ - test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
239
+ - test/dummy/tmp/cache/assets/E00/F20/sprockets%2Ff3fc35f5618dfeec2cb7bc6b415c227f
240
+ - test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
241
+ - test/dummy/tmp/pids/server.pid
242
+ - test/fixtures/sample_model.rb
243
+ - test/integration/people_validation_test.rb
244
+ - test/lazymodel_test.rb
245
+ - test/sample_model_test.rb
246
+ - test/test_helper.rb