plyushkin 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +24 -1
- data/lib/plyushkin.rb +1 -0
- data/lib/plyushkin/base_value.rb +35 -3
- data/lib/plyushkin/core_ext/active_record_base.rb +1 -1
- data/lib/plyushkin/error.rb +1 -0
- data/lib/plyushkin/model.rb +4 -0
- data/lib/plyushkin/property.rb +4 -0
- data/lib/plyushkin/test.rb +1 -0
- data/lib/plyushkin/test/hoarded_attribute_matcher.rb +98 -0
- data/lib/plyushkin/test/matcher_base.rb +30 -0
- data/lib/plyushkin/test/matchers.rb +15 -0
- data/lib/plyushkin/test/persisted_attribute_matcher.rb +37 -0
- data/lib/plyushkin/test/value_types.rb +10 -0
- data/lib/plyushkin/version.rb +1 -1
- data/spec/lib/base_value_spec.rb +85 -0
- data/spec/lib/core_ext/active_record_base_spec.rb +1 -1
- data/spec/lib/model_spec.rb +10 -0
- data/spec/lib/property_spec.rb +13 -0
- data/spec/lib/test/matchers_spec.rb +31 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/sqlite.rb +6 -0
- metadata +18 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3ffa197a5ec8d8b23b72ba77444540524c17062
|
4
|
+
data.tar.gz: cfd45839d46278a89f81904eee6cc4cedb490b97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 20a5449a85d1753e8a08ec0bac1063827a1ddc3d1325edfd57d805072f9f90d4cf6bf581e2da6a51457daaf7c493543e750e9652b08e62b1f4dd1782b575ae8a
|
7
|
+
data.tar.gz: 0e26387d0792ec1ec44f78d8f5e1e738dd1f7c51cc1163305087dc76d52b0d6a67be1f84ad8674828452d2fcbcacb281ddebe85c113d29e0d3edcda897e9c28a
|
data/README.md
CHANGED
@@ -18,7 +18,30 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Configure the backend service that plyushkin will use in your environments/<environment>.rb file.
|
22
|
+
For example, to configure the stub service for running specs, the following code would go in your
|
23
|
+
config/environments/test.rb file of a Rails application.
|
24
|
+
|
25
|
+
config.before_initialize do |c|
|
26
|
+
Plyushkin::Service.service = Plyushkin::Service::Stub.new
|
27
|
+
end
|
28
|
+
|
29
|
+
To use plyushkin against a live web service,
|
30
|
+
assign an instance of ``Plyushkin::Service::Web.new(:url => 'http://yourservice.com')``
|
31
|
+
|
32
|
+
## Testing
|
33
|
+
|
34
|
+
Plyushkin provides RSpec matchers for testing class macros. To use these matchers,
|
35
|
+
add ``config.include Plyushkin::Test::Matchers`` to your RSpec.configure in spec_helper.
|
36
|
+
|
37
|
+
To test Plyushkin configuration in your model:
|
38
|
+
|
39
|
+
describe YourModel do
|
40
|
+
it { should persist_attribute(:your_attribute) }
|
41
|
+
it { should_not persist_attribute(:your_non_plyushkin_attribute) }
|
42
|
+
it { should persist_attribute(:your_attribute).with_format(:to_date) }
|
43
|
+
it { should_not persist_attribute(:your_attribute).with_format(:not_a_formatter) }
|
44
|
+
end
|
22
45
|
|
23
46
|
## Contributing
|
24
47
|
|
data/lib/plyushkin.rb
CHANGED
data/lib/plyushkin/base_value.rb
CHANGED
@@ -9,12 +9,19 @@ class Plyushkin::BaseValue
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
def formatters
|
13
|
+
@formatters.dup
|
14
|
+
end
|
15
|
+
|
12
16
|
def self.persisted_attr(*attributes)
|
13
17
|
opts = attributes.last.is_a?(Hash) ? attributes.pop : {}
|
14
18
|
names = attributes
|
15
19
|
formatter = opts[:formatter]
|
16
20
|
|
21
|
+
names.each{|name| formatters[name] = formatter}
|
22
|
+
|
17
23
|
persisted_attributes.concat(names)
|
24
|
+
|
18
25
|
attr_writer *names
|
19
26
|
names.each do |name|
|
20
27
|
define_method(name) do
|
@@ -29,16 +36,24 @@ class Plyushkin::BaseValue
|
|
29
36
|
end
|
30
37
|
|
31
38
|
def self.persisted_attributes
|
32
|
-
if self.superclass == Object
|
39
|
+
if self.superclass == Object && self.superclass.class == Class
|
33
40
|
@persisted_attributes ||= []
|
34
41
|
else
|
35
42
|
@persisted_attributes ||= superclass.persisted_attributes.dup
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
46
|
+
def self.formatters
|
47
|
+
if self.superclass == Object
|
48
|
+
@formatters ||= {}
|
49
|
+
else
|
50
|
+
@formatters ||= superclass.formatters.dup
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
39
54
|
persisted_attr :date, :formatter => :to_date
|
40
55
|
validates_each :date do |record, attr_name, value|
|
41
|
-
record.errors.add(attr_name, "cannot be in the future") unless value
|
56
|
+
record.errors.add(attr_name, "cannot be in the future") unless value <= Time.now
|
42
57
|
end
|
43
58
|
|
44
59
|
def equal_value?(other)
|
@@ -49,11 +64,28 @@ class Plyushkin::BaseValue
|
|
49
64
|
end
|
50
65
|
|
51
66
|
def to_i(value)
|
52
|
-
value.to_i
|
67
|
+
value =~ /\A\d+\Z/ ? value.to_i : value
|
68
|
+
end
|
69
|
+
|
70
|
+
#TODO: Maybe this can be nicer.
|
71
|
+
def to_f(value)
|
72
|
+
begin
|
73
|
+
Float(value)
|
74
|
+
rescue ArgumentError => e
|
75
|
+
value
|
76
|
+
rescue TypeError => e
|
77
|
+
value
|
78
|
+
end
|
53
79
|
end
|
54
80
|
|
55
81
|
def to_date(value)
|
56
82
|
value.is_a?(String) ? DateTime.parse(value) : value
|
57
83
|
end
|
58
84
|
|
85
|
+
def to_bool(value)
|
86
|
+
return true if value == "true"
|
87
|
+
return false if value == "false"
|
88
|
+
return value
|
89
|
+
end
|
90
|
+
|
59
91
|
end
|
@@ -7,7 +7,7 @@ ActiveRecord::Base.instance_eval do
|
|
7
7
|
end
|
8
8
|
validates name, :plyushkin => true
|
9
9
|
|
10
|
-
plyushkin_model.register(name, opts[:type], opts)
|
10
|
+
plyushkin_model.register(name, opts[:type] || Plyushkin::StringValue, opts)
|
11
11
|
plyushkin_model.register_callback(name, :after_create, opts[:after_create]) if opts[:after_create]
|
12
12
|
end
|
13
13
|
|
@@ -0,0 +1 @@
|
|
1
|
+
class Plyushkin::Error < StandardError; end
|
data/lib/plyushkin/model.rb
CHANGED
@@ -2,6 +2,10 @@ class Plyushkin::Model
|
|
2
2
|
attr_reader :service, :name, :cache
|
3
3
|
|
4
4
|
def initialize(service, name, cache)
|
5
|
+
raise Plyushkin::Error.new <<-ERROR unless service
|
6
|
+
Service cannot be nil. Set Plyushkin::Service.service to a service instance in an initializer.
|
7
|
+
ERROR
|
8
|
+
|
5
9
|
@service = service
|
6
10
|
@types = {}
|
7
11
|
@ignore_unchanged_values = {}
|
data/lib/plyushkin/property.rb
CHANGED
data/lib/plyushkin/test.rb
CHANGED
@@ -0,0 +1,98 @@
|
|
1
|
+
module Plyushkin::Test
|
2
|
+
class HoardedAttributeMatcher < Plyushkin::Test::MatcherBase
|
3
|
+
def initialize(attribute)
|
4
|
+
@attribute = attribute
|
5
|
+
end
|
6
|
+
|
7
|
+
def of_type(type)
|
8
|
+
matchers << OfTypeMatcher.new(@attribute, type)
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def and_ignore_unchanged_values
|
13
|
+
matchers << IgnoreUnchangedMatcher.new(@attribute)
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def and_after_create_call(sym)
|
18
|
+
matchers << CallbackMatcher.new(@attribute, sym)
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def matches?(subject)
|
23
|
+
unless subject.class.plyushkin_model.registered_types.keys.include?(@attribute)
|
24
|
+
@failure_message = "Plyushkin: does not hoard attribute #{@attribute}"
|
25
|
+
@negative_failure_message = "Plyushkin: hoards attribute #{@attribute}"
|
26
|
+
end
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
class OfTypeMatcher
|
31
|
+
def initialize(attr_name, type)
|
32
|
+
@attr_name, @type = attr_name, type
|
33
|
+
end
|
34
|
+
|
35
|
+
def match(subject)
|
36
|
+
subject.class.plyushkin_model.registered_types[@attr_name] == @type
|
37
|
+
end
|
38
|
+
|
39
|
+
def failure_message
|
40
|
+
message(false)
|
41
|
+
end
|
42
|
+
|
43
|
+
def negative_failure_message
|
44
|
+
message(true)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def message(negate)
|
49
|
+
"Plyushkin: Hoarded attribute #{@attr_name} is #{negate ? "" : "not"} of type #{@type}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class IgnoreUnchangedMatcher
|
54
|
+
def initialize(attr_name)
|
55
|
+
@attr_name = attr_name
|
56
|
+
end
|
57
|
+
|
58
|
+
def match(subject)
|
59
|
+
subject.class.plyushkin_model.ignore_unchanged_values[@attr_name]
|
60
|
+
end
|
61
|
+
|
62
|
+
def failure_message
|
63
|
+
message(true)
|
64
|
+
end
|
65
|
+
|
66
|
+
def negative_failure_message
|
67
|
+
message(false)
|
68
|
+
end
|
69
|
+
|
70
|
+
def message(negate)
|
71
|
+
"Plyushkin:: Hoarded attribute #{@attr_name} #{negate ? "ignores" : "does not ignore"} unchanged values"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class CallbackMatcher
|
76
|
+
def initialize(attr_name, callback)
|
77
|
+
@attr_name, @callback = attr_name, callback
|
78
|
+
end
|
79
|
+
|
80
|
+
def match(subject)
|
81
|
+
callbacks = subject.class.plyushkin_model.callbacks[@attr_name]
|
82
|
+
callbacks && (callbacks[:after_create] == @callback)
|
83
|
+
end
|
84
|
+
|
85
|
+
def failure_message
|
86
|
+
message(true)
|
87
|
+
end
|
88
|
+
|
89
|
+
def negative_failure_message
|
90
|
+
message(false)
|
91
|
+
end
|
92
|
+
|
93
|
+
def message(negate)
|
94
|
+
"Plyushkin:: Hoarded attribute #{@attr_name} #{negate ? "does not callback" : "calls back"} #{@callback}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Plyushkin::Test
|
2
|
+
class MatcherBase
|
3
|
+
def matchers
|
4
|
+
@matchers ||= []
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(subject)
|
8
|
+
matchers.each do |m|
|
9
|
+
unless m.match(subject)
|
10
|
+
@failure_message = m.failure_message
|
11
|
+
@negative_failure_message = m.negative_failure_message
|
12
|
+
break
|
13
|
+
end
|
14
|
+
end
|
15
|
+
return @failure_message.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure_message
|
19
|
+
@failure_message
|
20
|
+
end
|
21
|
+
|
22
|
+
def negative_failure_message
|
23
|
+
@negative_failure_message
|
24
|
+
end
|
25
|
+
|
26
|
+
def description
|
27
|
+
"Description not set"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative "matcher_base.rb"
|
2
|
+
require_relative "persisted_attribute_matcher.rb"
|
3
|
+
require_relative "hoarded_attribute_matcher.rb"
|
4
|
+
|
5
|
+
module Plyushkin::Test
|
6
|
+
module Matchers
|
7
|
+
def persist_attribute(name)
|
8
|
+
Plyushkin::Test::PersistedAttributeMatcher.new(name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def hoard(attribute)
|
12
|
+
Plyushkin::Test::HoardedAttributeMatcher.new(attribute)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Plyushkin::Test
|
2
|
+
class PersistedAttributeMatcher < Plyushkin::Test::MatcherBase
|
3
|
+
def initialize(attr_name)
|
4
|
+
@attr_name = attr_name
|
5
|
+
end
|
6
|
+
|
7
|
+
def with_format(formatter)
|
8
|
+
matchers << WithFormatMatcher.new(@attr_name, formatter)
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def matches?(subject)
|
13
|
+
@failure_message = "Plyushkin: no persisted attribute with name '#{@attr_name}'" unless subject.class.persisted_attributes.include?(@attr_name)
|
14
|
+
@negative_failure_message = "Plyushkin: persisted attribute with name '#{@attr_name}' exists" unless subject.class.persisted_attributes.include?(@attr_name)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
class WithFormatMatcher
|
19
|
+
def initialize(attr_name, formatter)
|
20
|
+
@attr_name, @formatter = attr_name, formatter
|
21
|
+
end
|
22
|
+
|
23
|
+
def match(subject)
|
24
|
+
subject.class.formatters[@attr_name] == @formatter
|
25
|
+
end
|
26
|
+
|
27
|
+
def failure_message
|
28
|
+
"Plyushkin: attribute #{@attr_name} is not formatting with #{@formatter}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def negative_failure_message
|
32
|
+
"Plyushkin: attribute #{@attr_name} is formatting with #{@formatter}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -12,8 +12,18 @@ module Plyushkin::Test
|
|
12
12
|
class Plyushkin::Test::Member < ActiveRecord::Base; end
|
13
13
|
class Plyushkin::Test::WidgetOne < ActiveRecord::Base; hoards :apples; end
|
14
14
|
class Plyushkin::Test::WidgetTwo < ActiveRecord::Base; hoards :beans; end
|
15
|
+
class Plyushkin::Test::IgnoresUnchangedWidget < ActiveRecord::Base
|
16
|
+
hoards :apples, :ignore_unchanged_values => true
|
17
|
+
hoards :beans
|
18
|
+
end
|
19
|
+
|
20
|
+
class Plyushkin::Test::CallbackWidget < ActiveRecord::Base
|
21
|
+
hoards :apples, :after_create => :core
|
22
|
+
hoards :beans
|
23
|
+
end
|
15
24
|
|
16
25
|
class Plyushkin::Test::DateValue < Plyushkin::BaseValue
|
17
26
|
persisted_attr :value, :formatter => :to_date
|
18
27
|
end
|
28
|
+
|
19
29
|
end
|
data/lib/plyushkin/version.rb
CHANGED
data/spec/lib/base_value_spec.rb
CHANGED
@@ -19,6 +19,31 @@ describe Plyushkin::BaseValue do
|
|
19
19
|
value.should_not be_valid
|
20
20
|
value.errors.full_messages.should == ["Date cannot be in the future"]
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'should be valid if date is equal to now' do
|
24
|
+
Timecop.freeze(DateTime.now) do
|
25
|
+
Plyushkin::StringValue.new.should be_valid
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should be valid if date is equal to current' do
|
30
|
+
Timecop.freeze(DateTime.current) do
|
31
|
+
Plyushkin::StringValue.new.should be_valid
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#numericality' do
|
36
|
+
it 'should not be valid if not an integer' do
|
37
|
+
clazz = Class.new(Plyushkin::StringValue) do
|
38
|
+
validates :value, :numericality => true
|
39
|
+
end
|
40
|
+
clazz.stub(:name).and_return("Clazz")
|
41
|
+
|
42
|
+
c = clazz.new
|
43
|
+
c.value = 'abcd'
|
44
|
+
c.should_not be_valid
|
45
|
+
end
|
46
|
+
end
|
22
47
|
end
|
23
48
|
|
24
49
|
describe '##persisted_attr' do
|
@@ -78,6 +103,48 @@ describe Plyushkin::BaseValue do
|
|
78
103
|
value.my_attr.should == 5
|
79
104
|
value.my_attr2.should == 9999
|
80
105
|
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe 'formatter methods' do
|
109
|
+
describe '#to_i' do
|
110
|
+
it 'should return the same value if it contains non-numeric characters' do
|
111
|
+
Plyushkin::BaseValue.new.to_i("abcd").should == "abcd"
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should return an integer if string is a number' do
|
115
|
+
Plyushkin::BaseValue.new.to_i("1234").should == 1234
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should return an integer if arg is an integer' do
|
119
|
+
Plyushkin::BaseValue.new.to_i(1234).should == 1234
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should return nil when arg is nil' do
|
123
|
+
Plyushkin::BaseValue.new.to_i(nil).should be_nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#to_f' do
|
128
|
+
it 'should return the same value if it contains non-numeric characters' do
|
129
|
+
Plyushkin::BaseValue.new.to_f("abcd").should == "abcd"
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should return a float if string is a number' do
|
133
|
+
Plyushkin::BaseValue.new.to_f("12.34").should == 12.34
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should return a float if arg is a float' do
|
137
|
+
Plyushkin::BaseValue.new.to_f(123.4).should == 123.4
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should return a float if arg is an integer' do
|
141
|
+
Plyushkin::BaseValue.new.to_f(455).should == 455.0
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should return nil when arg is nil' do
|
145
|
+
Plyushkin::BaseValue.new.to_f(nil).should be_nil
|
146
|
+
end
|
147
|
+
end
|
81
148
|
|
82
149
|
describe '#to_date' do
|
83
150
|
it 'format a json string to a date' do
|
@@ -87,6 +154,24 @@ describe Plyushkin::BaseValue do
|
|
87
154
|
end
|
88
155
|
end
|
89
156
|
|
157
|
+
describe '#to_bool' do
|
158
|
+
it 'should return true if string true is passed in' do
|
159
|
+
Plyushkin::BaseValue.new.to_bool("true").should be_true
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should return false if string false is passed in' do
|
163
|
+
Plyushkin::BaseValue.new.to_bool("false").should be_false
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should return nil if nil is passed in' do
|
167
|
+
Plyushkin::BaseValue.new.to_bool(nil).should be_nil
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should return the same value if it cannot covert to boolean' do
|
171
|
+
Plyushkin::BaseValue.new.to_bool('railsconf').should == 'railsconf'
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
90
175
|
end
|
91
176
|
|
92
177
|
describe '#equal_value' do
|
@@ -20,7 +20,7 @@ describe ActiveRecord::Base do
|
|
20
20
|
hoards :geolocation, :type => Plyushkin::Test::CoordinateValue
|
21
21
|
end
|
22
22
|
|
23
|
-
clazz.plyushkin_model.registered_types[:login_date].should
|
23
|
+
clazz.plyushkin_model.registered_types[:login_date].should == Plyushkin::StringValue
|
24
24
|
clazz.plyushkin_model.registered_types[:geolocation].should == Plyushkin::Test::CoordinateValue
|
25
25
|
end
|
26
26
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Plyushkin::Model do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'should raise an error if no service is provided' do
|
6
|
+
expect {Plyushkin::Model.new(nil, 'name', nil)}
|
7
|
+
.to raise_error(Plyushkin::Error, /Service cannot be nil/)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/spec/lib/property_spec.rb
CHANGED
@@ -167,6 +167,19 @@ describe Plyushkin::Property do
|
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
+
describe '#nil?' do
|
171
|
+
it 'should be true if last value is NilValue' do
|
172
|
+
property = Plyushkin::Property.new(:property_name, :type => Plyushkin::Test::PresenceTestValue)
|
173
|
+
property.should be_nil
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should be false if last value is not a NilValue' do
|
177
|
+
property = Plyushkin::Property.new(:property_name, :type => Plyushkin::Test::PresenceTestValue)
|
178
|
+
property.create
|
179
|
+
property.should_not be_nil
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
170
183
|
it '#insert_position' do
|
171
184
|
property = Plyushkin::Property.new(:property_name)
|
172
185
|
value1 = property.create(:value => 7, :date => DateTime.now - 7.days)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Plyushkin::Test::DateValue do
|
4
|
+
it { should persist_attribute(:value) }
|
5
|
+
it { should_not persist_attribute(:value2) }
|
6
|
+
it { should persist_attribute(:value).with_format(:to_date) }
|
7
|
+
it { should_not persist_attribute(:value).with_format(:to_datetime) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Plyushkin::Test::WidgetOne do
|
11
|
+
it { should hoard(:apples) }
|
12
|
+
it { should hoard(:apples).of_type(Plyushkin::StringValue) }
|
13
|
+
it { should_not hoard(:beans) }
|
14
|
+
it { should_not hoard(:apples).of_type(Plyushkin::Test::DateValue) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Plyushkin::Test::IgnoresUnchangedWidget do
|
18
|
+
it { should hoard(:apples).and_ignore_unchanged_values }
|
19
|
+
it {
|
20
|
+
should hoard(:beans)
|
21
|
+
should_not hoard(:beans).and_ignore_unchanged_values
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Plyushkin::Test::CallbackWidget do
|
26
|
+
it { should hoard(:apples).of_type(Plyushkin::StringValue).and_after_create_call(:core) }
|
27
|
+
it { should hoard(:apples)
|
28
|
+
should_not hoard(:apples).and_after_create_call(:core2) }
|
29
|
+
it { should hoard(:beans)
|
30
|
+
should_not hoard(:beans).and_after_create_call(:core) }
|
31
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/sqlite.rb
CHANGED
@@ -13,6 +13,12 @@ class CreateMembers < ActiveRecord::Migration
|
|
13
13
|
create_table :widget_twos do |t|
|
14
14
|
t.timestamps
|
15
15
|
end
|
16
|
+
create_table :ignores_unchanged_widgets do |t|
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
create_table :callback_widgets do |t|
|
20
|
+
t.timestamps
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
18
24
|
CreateMembers.up
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plyushkin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Craig Israel
|
@@ -10,12 +9,11 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2014-
|
12
|
+
date: 2014-02-28 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: activerecord
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
18
|
- - ~>
|
21
19
|
- !ruby/object:Gem::Version
|
@@ -23,7 +21,6 @@ dependencies:
|
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
25
|
- - ~>
|
29
26
|
- !ruby/object:Gem::Version
|
@@ -31,7 +28,6 @@ dependencies:
|
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: bundler
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
32
|
- - ~>
|
37
33
|
- !ruby/object:Gem::Version
|
@@ -39,7 +35,6 @@ dependencies:
|
|
39
35
|
type: :development
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
39
|
- - ~>
|
45
40
|
- !ruby/object:Gem::Version
|
@@ -47,17 +42,15 @@ dependencies:
|
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: rake
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- -
|
46
|
+
- - '>='
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: '0'
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- -
|
53
|
+
- - '>='
|
61
54
|
- !ruby/object:Gem::Version
|
62
55
|
version: '0'
|
63
56
|
description: Provides active record extension to capture historical property data
|
@@ -82,6 +75,7 @@ files:
|
|
82
75
|
- lib/plyushkin/cache/stub.rb
|
83
76
|
- lib/plyushkin/core_ext/active_record_base.rb
|
84
77
|
- lib/plyushkin/core_ext/plyushkin_extensions.rb
|
78
|
+
- lib/plyushkin/error.rb
|
85
79
|
- lib/plyushkin/model.rb
|
86
80
|
- lib/plyushkin/nil_value.rb
|
87
81
|
- lib/plyushkin/persistence.rb
|
@@ -91,6 +85,10 @@ files:
|
|
91
85
|
- lib/plyushkin/service/web.rb
|
92
86
|
- lib/plyushkin/string_value.rb
|
93
87
|
- lib/plyushkin/test.rb
|
88
|
+
- lib/plyushkin/test/hoarded_attribute_matcher.rb
|
89
|
+
- lib/plyushkin/test/matcher_base.rb
|
90
|
+
- lib/plyushkin/test/matchers.rb
|
91
|
+
- lib/plyushkin/test/persisted_attribute_matcher.rb
|
94
92
|
- lib/plyushkin/test/value_types.rb
|
95
93
|
- lib/plyushkin/validators/presence.rb
|
96
94
|
- lib/plyushkin/version.rb
|
@@ -98,48 +96,51 @@ files:
|
|
98
96
|
- spec/lib/base_value_spec.rb
|
99
97
|
- spec/lib/cache/stub_spec.rb
|
100
98
|
- spec/lib/core_ext/active_record_base_spec.rb
|
99
|
+
- spec/lib/model_spec.rb
|
101
100
|
- spec/lib/nil_value_spec.rb
|
102
101
|
- spec/lib/persistence_spec.rb
|
103
102
|
- spec/lib/property_spec.rb
|
104
103
|
- spec/lib/service/stub_spec.rb
|
105
104
|
- spec/lib/service/web_spec.rb
|
105
|
+
- spec/lib/test/matchers_spec.rb
|
106
106
|
- spec/lib/value_spec.rb
|
107
107
|
- spec/spec_helper.rb
|
108
108
|
- spec/support/sqlite.rb
|
109
109
|
homepage: http://github.com/OnlifeHealth/plyushkin
|
110
110
|
licenses:
|
111
111
|
- MIT
|
112
|
+
metadata: {}
|
112
113
|
post_install_message:
|
113
114
|
rdoc_options: []
|
114
115
|
require_paths:
|
115
116
|
- lib
|
116
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
118
|
requirements:
|
119
|
-
- -
|
119
|
+
- - '>='
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
123
|
requirements:
|
125
|
-
- -
|
124
|
+
- - '>='
|
126
125
|
- !ruby/object:Gem::Version
|
127
126
|
version: '0'
|
128
127
|
requirements: []
|
129
128
|
rubyforge_project:
|
130
|
-
rubygems_version:
|
129
|
+
rubygems_version: 2.0.3
|
131
130
|
signing_key:
|
132
|
-
specification_version:
|
131
|
+
specification_version: 4
|
133
132
|
summary: Plyushkin - the attribute hoarder
|
134
133
|
test_files:
|
135
134
|
- spec/lib/base_value_spec.rb
|
136
135
|
- spec/lib/cache/stub_spec.rb
|
137
136
|
- spec/lib/core_ext/active_record_base_spec.rb
|
137
|
+
- spec/lib/model_spec.rb
|
138
138
|
- spec/lib/nil_value_spec.rb
|
139
139
|
- spec/lib/persistence_spec.rb
|
140
140
|
- spec/lib/property_spec.rb
|
141
141
|
- spec/lib/service/stub_spec.rb
|
142
142
|
- spec/lib/service/web_spec.rb
|
143
|
+
- spec/lib/test/matchers_spec.rb
|
143
144
|
- spec/lib/value_spec.rb
|
144
145
|
- spec/spec_helper.rb
|
145
146
|
- spec/support/sqlite.rb
|