lazymodel 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +24 -5
- data/lib/lazymodel/base.rb +13 -0
- data/lib/lazymodel/version.rb +1 -1
- data/test/dummy/log/test.log +1239 -0
- data/test/fixtures/sample_model.rb +29 -1
- data/test/integration/people_validation_test.rb +3 -3
- data/test/sample_model_test.rb +19 -6
- metadata +4 -6
- data/test/dummy/tmp/pids/server.pid +0 -1
@@ -1,5 +1,20 @@
|
|
1
1
|
class SampleModel < Lazymodel::Base
|
2
|
-
activemodel_attributes :name, :surname, :prefix => 'clear_', :suffix => '?'
|
2
|
+
activemodel_attributes :name, :surname, :prefix => 'clear_', :suffix => '?',
|
3
|
+
:callbacks => {:before_save => :capitalize_attributes, :after_update => [:notify_admin, :update_genealogy]}
|
4
|
+
|
5
|
+
|
6
|
+
def save
|
7
|
+
run_callbacks :save do
|
8
|
+
# saving...
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def update
|
13
|
+
run_callbacks :update do
|
14
|
+
# updating...
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
3
18
|
|
4
19
|
private
|
5
20
|
|
@@ -10,4 +25,17 @@ class SampleModel < Lazymodel::Base
|
|
10
25
|
def attribute?(attribute)
|
11
26
|
send(attribute).present?
|
12
27
|
end
|
28
|
+
|
29
|
+
def capitalize_attributes
|
30
|
+
self.name = name.capitalize
|
31
|
+
self.surname = surname.capitalize
|
32
|
+
end
|
33
|
+
|
34
|
+
def notify_admin
|
35
|
+
#...
|
36
|
+
end
|
37
|
+
|
38
|
+
def update_genealogy
|
39
|
+
#...
|
40
|
+
end
|
13
41
|
end
|
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
class PeopleValidationClass < ActiveSupport::TestCase
|
4
4
|
test 'renders person form' do
|
5
5
|
visit '/people/new'
|
6
|
-
assert_match
|
6
|
+
assert_match 'Validate Person', page.body
|
7
7
|
end
|
8
8
|
|
9
9
|
test 'successfully validates valid person' do
|
@@ -11,13 +11,13 @@ class PeopleValidationClass < ActiveSupport::TestCase
|
|
11
11
|
fill_in 'Name', :with => 'john'
|
12
12
|
fill_in 'Surname', :with => 'doe'
|
13
13
|
click_button 'Validate'
|
14
|
-
assert_match
|
14
|
+
assert_match 'Person is valid', page.body
|
15
15
|
end
|
16
16
|
|
17
17
|
test 'does not validate invalid person' do
|
18
18
|
visit '/people/new'
|
19
19
|
fill_in 'Name', :with => 'john'
|
20
20
|
click_button 'Validate'
|
21
|
-
assert_match
|
21
|
+
assert_match 'Person is not valid', page.body
|
22
22
|
end
|
23
23
|
end
|
data/test/sample_model_test.rb
CHANGED
@@ -33,12 +33,17 @@ class SampleModelTest < ActiveSupport::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
test 'has expected attributes' do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
expected = [[:name, 'john'], [:surname, 'doe']]
|
37
|
+
expected.each do |arr|
|
38
|
+
attribute, value = arr
|
39
|
+
assert_equal value, @model.attributes[attribute]
|
40
|
+
end
|
41
|
+
assert_equal expected.size, @model.attributes.size
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'attributes can be accessed both with hash and string keys' do
|
45
|
+
assert @model.attributes[:name]
|
46
|
+
assert_equal @model.attributes[:name], @model.attributes['name']
|
42
47
|
end
|
43
48
|
|
44
49
|
test 'allows for translations' do
|
@@ -48,6 +53,14 @@ class SampleModelTest < ActiveSupport::TestCase
|
|
48
53
|
I18n.backend.reload!
|
49
54
|
end
|
50
55
|
|
56
|
+
test 'when calling a callback enabled method, callbacks are called' do
|
57
|
+
@model.expects(:capitalize_attributes)
|
58
|
+
@model.save
|
59
|
+
@model.expects(:notify_admin)
|
60
|
+
@model.expects(:update_genealogy)
|
61
|
+
@model.update
|
62
|
+
end
|
63
|
+
|
51
64
|
private
|
52
65
|
|
53
66
|
def set_model_attributes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazymodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -153,7 +153,6 @@ files:
|
|
153
153
|
- test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
|
154
154
|
- test/dummy/tmp/cache/assets/E00/F20/sprockets%2Ff3fc35f5618dfeec2cb7bc6b415c227f
|
155
155
|
- test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
|
156
|
-
- test/dummy/tmp/pids/server.pid
|
157
156
|
- test/fixtures/sample_model.rb
|
158
157
|
- test/integration/people_validation_test.rb
|
159
158
|
- test/lazymodel_test.rb
|
@@ -173,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
172
|
version: '0'
|
174
173
|
segments:
|
175
174
|
- 0
|
176
|
-
hash: -
|
175
|
+
hash: -336096010538101371
|
177
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
177
|
none: false
|
179
178
|
requirements:
|
@@ -182,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
181
|
version: '0'
|
183
182
|
segments:
|
184
183
|
- 0
|
185
|
-
hash: -
|
184
|
+
hash: -336096010538101371
|
186
185
|
requirements: []
|
187
186
|
rubyforge_project:
|
188
187
|
rubygems_version: 1.8.24
|
@@ -238,7 +237,6 @@ test_files:
|
|
238
237
|
- test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
|
239
238
|
- test/dummy/tmp/cache/assets/E00/F20/sprockets%2Ff3fc35f5618dfeec2cb7bc6b415c227f
|
240
239
|
- test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
|
241
|
-
- test/dummy/tmp/pids/server.pid
|
242
240
|
- test/fixtures/sample_model.rb
|
243
241
|
- test/integration/people_validation_test.rb
|
244
242
|
- test/lazymodel_test.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
52162
|