ardm 0.0.1
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.
- checksums.yaml +15 -0
- data/.gitignore +35 -0
- data/Gemfile +13 -0
- data/LICENSE +21 -0
- data/README.md +70 -0
- data/Rakefile +4 -0
- data/ardm.gemspec +29 -0
- data/db/.gitignore +1 -0
- data/lib/ardm/active_record/associations.rb +80 -0
- data/lib/ardm/active_record/base.rb +49 -0
- data/lib/ardm/active_record/dirty.rb +25 -0
- data/lib/ardm/active_record/hooks.rb +31 -0
- data/lib/ardm/active_record/inheritance.rb +37 -0
- data/lib/ardm/active_record/is/state_machine.rb +21 -0
- data/lib/ardm/active_record/is.rb +22 -0
- data/lib/ardm/active_record/not_found.rb +7 -0
- data/lib/ardm/active_record/predicate_builder/array_handler.rb +31 -0
- data/lib/ardm/active_record/predicate_builder/rails3.rb +147 -0
- data/lib/ardm/active_record/predicate_builder/rails4.rb +139 -0
- data/lib/ardm/active_record/predicate_builder/relation_handler.rb +15 -0
- data/lib/ardm/active_record/predicate_builder.rb +19 -0
- data/lib/ardm/active_record/property.rb +357 -0
- data/lib/ardm/active_record/query.rb +108 -0
- data/lib/ardm/active_record/record.rb +70 -0
- data/lib/ardm/active_record/relation.rb +83 -0
- data/lib/ardm/active_record/repository.rb +38 -0
- data/lib/ardm/active_record/serialization.rb +164 -0
- data/lib/ardm/active_record/storage_names.rb +28 -0
- data/lib/ardm/active_record/validations.rb +111 -0
- data/lib/ardm/active_record.rb +43 -0
- data/lib/ardm/data_mapper/not_found.rb +5 -0
- data/lib/ardm/data_mapper/record.rb +41 -0
- data/lib/ardm/data_mapper.rb +5 -0
- data/lib/ardm/env.rb +5 -0
- data/lib/ardm/property/api_key.rb +30 -0
- data/lib/ardm/property/bcrypt_hash.rb +31 -0
- data/lib/ardm/property/binary.rb +23 -0
- data/lib/ardm/property/boolean.rb +29 -0
- data/lib/ardm/property/class.rb +19 -0
- data/lib/ardm/property/comma_separated_list.rb +28 -0
- data/lib/ardm/property/csv.rb +35 -0
- data/lib/ardm/property/date.rb +12 -0
- data/lib/ardm/property/datetime.rb +12 -0
- data/lib/ardm/property/decimal.rb +38 -0
- data/lib/ardm/property/discriminator.rb +65 -0
- data/lib/ardm/property/enum.rb +51 -0
- data/lib/ardm/property/epoch_time.rb +38 -0
- data/lib/ardm/property/file_path.rb +25 -0
- data/lib/ardm/property/flag.rb +65 -0
- data/lib/ardm/property/float.rb +18 -0
- data/lib/ardm/property/integer.rb +24 -0
- data/lib/ardm/property/invalid_value_error.rb +22 -0
- data/lib/ardm/property/ip_address.rb +35 -0
- data/lib/ardm/property/json.rb +49 -0
- data/lib/ardm/property/lookup.rb +29 -0
- data/lib/ardm/property/numeric.rb +40 -0
- data/lib/ardm/property/object.rb +36 -0
- data/lib/ardm/property/paranoid_boolean.rb +18 -0
- data/lib/ardm/property/paranoid_datetime.rb +17 -0
- data/lib/ardm/property/regexp.rb +22 -0
- data/lib/ardm/property/serial.rb +16 -0
- data/lib/ardm/property/slug.rb +29 -0
- data/lib/ardm/property/string.rb +40 -0
- data/lib/ardm/property/support/dirty_minder.rb +169 -0
- data/lib/ardm/property/support/flags.rb +41 -0
- data/lib/ardm/property/support/paranoid_base.rb +78 -0
- data/lib/ardm/property/text.rb +11 -0
- data/lib/ardm/property/time.rb +12 -0
- data/lib/ardm/property/uri.rb +27 -0
- data/lib/ardm/property/uuid.rb +65 -0
- data/lib/ardm/property/validation.rb +208 -0
- data/lib/ardm/property/yaml.rb +38 -0
- data/lib/ardm/property.rb +891 -0
- data/lib/ardm/property_set.rb +152 -0
- data/lib/ardm/query/expression.rb +85 -0
- data/lib/ardm/query/ext/symbol.rb +37 -0
- data/lib/ardm/query/operator.rb +64 -0
- data/lib/ardm/record.rb +1 -0
- data/lib/ardm/support/assertions.rb +8 -0
- data/lib/ardm/support/deprecate.rb +12 -0
- data/lib/ardm/support/descendant_set.rb +89 -0
- data/lib/ardm/support/equalizer.rb +48 -0
- data/lib/ardm/support/ext/array.rb +22 -0
- data/lib/ardm/support/ext/blank.rb +25 -0
- data/lib/ardm/support/ext/hash.rb +67 -0
- data/lib/ardm/support/ext/module.rb +47 -0
- data/lib/ardm/support/ext/object.rb +57 -0
- data/lib/ardm/support/ext/string.rb +24 -0
- data/lib/ardm/support/ext/try_dup.rb +12 -0
- data/lib/ardm/support/hook.rb +405 -0
- data/lib/ardm/support/lazy_array.rb +451 -0
- data/lib/ardm/support/local_object_space.rb +13 -0
- data/lib/ardm/support/logger.rb +201 -0
- data/lib/ardm/support/mash.rb +176 -0
- data/lib/ardm/support/naming_conventions.rb +90 -0
- data/lib/ardm/support/ordered_set.rb +380 -0
- data/lib/ardm/support/subject.rb +33 -0
- data/lib/ardm/support/subject_set.rb +250 -0
- data/lib/ardm/version.rb +3 -0
- data/lib/ardm.rb +56 -0
- data/spec/fixtures/api_user.rb +11 -0
- data/spec/fixtures/article.rb +22 -0
- data/spec/fixtures/bookmark.rb +14 -0
- data/spec/fixtures/invention.rb +5 -0
- data/spec/fixtures/network_node.rb +23 -0
- data/spec/fixtures/person.rb +17 -0
- data/spec/fixtures/software_package.rb +22 -0
- data/spec/fixtures/ticket.rb +12 -0
- data/spec/fixtures/tshirt.rb +15 -0
- data/spec/integration/api_key_spec.rb +25 -0
- data/spec/integration/bcrypt_hash_spec.rb +45 -0
- data/spec/integration/comma_separated_list_spec.rb +85 -0
- data/spec/integration/dirty_minder_spec.rb +197 -0
- data/spec/integration/enum_spec.rb +79 -0
- data/spec/integration/epoch_time_spec.rb +59 -0
- data/spec/integration/file_path_spec.rb +158 -0
- data/spec/integration/flag_spec.rb +72 -0
- data/spec/integration/ip_address_spec.rb +151 -0
- data/spec/integration/json_spec.rb +70 -0
- data/spec/integration/slug_spec.rb +65 -0
- data/spec/integration/uri_spec.rb +136 -0
- data/spec/integration/uuid_spec.rb +102 -0
- data/spec/integration/yaml_spec.rb +85 -0
- data/spec/public/property/binary_spec.rb +41 -0
- data/spec/public/property/boolean_spec.rb +30 -0
- data/spec/public/property/class_spec.rb +28 -0
- data/spec/public/property/date_spec.rb +22 -0
- data/spec/public/property/date_time_spec.rb +22 -0
- data/spec/public/property/decimal_spec.rb +23 -0
- data/spec/public/property/discriminator_spec.rb +133 -0
- data/spec/public/property/float_spec.rb +22 -0
- data/spec/public/property/integer_spec.rb +22 -0
- data/spec/public/property/object_spec.rb +103 -0
- data/spec/public/property/serial_spec.rb +22 -0
- data/spec/public/property/string_spec.rb +22 -0
- data/spec/public/property/text_spec.rb +23 -0
- data/spec/public/property/time_spec.rb +22 -0
- data/spec/public/property_spec.rb +316 -0
- data/spec/rcov.opts +6 -0
- data/spec/schema.rb +86 -0
- data/spec/semipublic/property/binary_spec.rb +14 -0
- data/spec/semipublic/property/boolean_spec.rb +48 -0
- data/spec/semipublic/property/class_spec.rb +36 -0
- data/spec/semipublic/property/date_spec.rb +44 -0
- data/spec/semipublic/property/date_time_spec.rb +47 -0
- data/spec/semipublic/property/decimal_spec.rb +83 -0
- data/spec/semipublic/property/discriminator_spec.rb +22 -0
- data/spec/semipublic/property/float_spec.rb +83 -0
- data/spec/semipublic/property/integer_spec.rb +83 -0
- data/spec/semipublic/property/lookup_spec.rb +27 -0
- data/spec/semipublic/property/serial_spec.rb +14 -0
- data/spec/semipublic/property/string_spec.rb +14 -0
- data/spec/semipublic/property/text_spec.rb +30 -0
- data/spec/semipublic/property/time_spec.rb +49 -0
- data/spec/semipublic/property_spec.rb +51 -0
- data/spec/shared/flags_shared_spec.rb +36 -0
- data/spec/shared/identity_function_group.rb +5 -0
- data/spec/shared/public_property_spec.rb +229 -0
- data/spec/shared/semipublic_property_spec.rb +159 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/unit/bcrypt_hash_spec.rb +154 -0
- data/spec/unit/csv_spec.rb +139 -0
- data/spec/unit/dirty_minder_spec.rb +64 -0
- data/spec/unit/enum_spec.rb +125 -0
- data/spec/unit/epoch_time_spec.rb +72 -0
- data/spec/unit/file_path_spec.rb +75 -0
- data/spec/unit/flag_spec.rb +114 -0
- data/spec/unit/ip_address_spec.rb +109 -0
- data/spec/unit/json_spec.rb +127 -0
- data/spec/unit/paranoid_boolean_spec.rb +142 -0
- data/spec/unit/paranoid_datetime_spec.rb +149 -0
- data/spec/unit/regexp_spec.rb +62 -0
- data/spec/unit/uri_spec.rb +64 -0
- data/spec/unit/yaml_spec.rb +111 -0
- data/tasks/spec.rake +40 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +350 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module ::ParanoidDateTimeBlog
|
|
4
|
+
class Draft < Ardm::Record
|
|
5
|
+
self.table_name = "articles"
|
|
6
|
+
|
|
7
|
+
property :id, Serial
|
|
8
|
+
property :deleted_at, ParanoidDateTime
|
|
9
|
+
|
|
10
|
+
before_destroy :before_destroy
|
|
11
|
+
|
|
12
|
+
def before_destroy; end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class Article < Draft; end
|
|
16
|
+
|
|
17
|
+
class Review < Article; end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
describe Ardm::Property::ParanoidDateTime do
|
|
22
|
+
before do
|
|
23
|
+
@model = ::ParanoidDateTimeBlog::Article
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe 'Model#destroy' do
|
|
27
|
+
before do
|
|
28
|
+
pending 'Does not work with < 1.8.7, see if backports fixes it' if RUBY_VERSION < '1.8.7'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
subject { @resource.destroy }
|
|
32
|
+
|
|
33
|
+
describe 'with a new resource' do
|
|
34
|
+
before do
|
|
35
|
+
@resource = @model.new
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should not delete the resource from the datastore' do
|
|
39
|
+
method(:subject).should_not change { @model.with_deleted.size }.from(0)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should not set the paranoid column' do
|
|
43
|
+
method(:subject).should_not change { @resource.deleted_at }.from(nil)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'should run the destroy hook' do
|
|
47
|
+
# NOTE: changed behavior because AR doesn't call hooks on destroying new objects
|
|
48
|
+
@resource.should_not_receive(:before_destroy).with(no_args)
|
|
49
|
+
subject
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe 'with a saved resource' do
|
|
54
|
+
before do
|
|
55
|
+
@resource = @model.create
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it { (!!subject).should be_true }
|
|
59
|
+
|
|
60
|
+
it 'should not delete the resource from the datastore' do
|
|
61
|
+
method(:subject).should_not change { @model.with_deleted.size }.from(1)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'should set the paranoid column' do
|
|
65
|
+
method(:subject).should change { @resource.deleted_at }.from(nil)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'should run the destroy hook' do
|
|
69
|
+
@resource.should_receive(:before_destroy).with(no_args)
|
|
70
|
+
subject
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe 'Model#delete' do
|
|
76
|
+
subject { @resource.delete }
|
|
77
|
+
|
|
78
|
+
describe 'with a new resource' do
|
|
79
|
+
before do
|
|
80
|
+
@resource = @model.new
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'should not delete the resource from the datastore' do
|
|
84
|
+
method(:subject).should_not change { @model.with_deleted.size }.from(0)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'should not set the paranoid column' do
|
|
88
|
+
method(:subject).should_not change { @resource.deleted_at }.from(nil)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'should not run the destroy hook' do
|
|
92
|
+
@resource.should_not_receive(:before_destroy).with(no_args)
|
|
93
|
+
subject
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe 'with a saved resource' do
|
|
98
|
+
before do
|
|
99
|
+
@resource = @model.create
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it { (!!subject).should be_true }
|
|
103
|
+
|
|
104
|
+
it 'should delete the resource from the datastore' do
|
|
105
|
+
method(:subject).should change { @model.with_deleted.size }.from(1).to(0)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'should not set the paranoid column' do
|
|
109
|
+
method(:subject).should_not change { @resource.deleted_at }.from(nil)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'should not run the destroy hook' do
|
|
113
|
+
@resource.should_not_receive(:before_destroy).with(no_args)
|
|
114
|
+
subject
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe 'Model#with_deleted' do
|
|
120
|
+
before do
|
|
121
|
+
pending 'Does not work with < 1.8.7, see if backports fixes it' if RUBY_VERSION < '1.8.7'
|
|
122
|
+
@resource = @model.create
|
|
123
|
+
@resource.destroy
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
describe 'with a block' do
|
|
127
|
+
subject { @model.with_deleted { @model.all } }
|
|
128
|
+
|
|
129
|
+
it 'should scope the block to return all resources' do
|
|
130
|
+
subject.map { |resource| resource.key }.should == [ @resource.key ]
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
describe 'without a block' do
|
|
135
|
+
subject { @model.with_deleted }
|
|
136
|
+
|
|
137
|
+
it 'should return a collection scoped to return all resources' do
|
|
138
|
+
subject.map { |resource| resource.key }.should == [ @resource.key ]
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
describe 'Model.inherited' do
|
|
144
|
+
it 'sets @paranoid_properties' do
|
|
145
|
+
::ParanoidDateTimeBlog::Review.instance_variable_get(:@paranoid_properties).should ==
|
|
146
|
+
::ParanoidDateTimeBlog::Article.instance_variable_get(:@paranoid_properties)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
try_spec do
|
|
4
|
+
describe Ardm::Property::Regexp do
|
|
5
|
+
before do
|
|
6
|
+
class ::User < Ardm::Record
|
|
7
|
+
property :id, Serial
|
|
8
|
+
property :regexp, Regexp
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
@property = User.properties[:regexp]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe '.load' do
|
|
15
|
+
describe 'when argument is a string' do
|
|
16
|
+
before do
|
|
17
|
+
@input = '[a-z]\d+'
|
|
18
|
+
@result = @property.load(@input)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'create a regexp instance from argument' do
|
|
22
|
+
@result.should == Regexp.new(@input)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe 'when argument is nil' do
|
|
27
|
+
before do
|
|
28
|
+
@input = nil
|
|
29
|
+
@result = @property.load(@input)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'returns nil' do
|
|
33
|
+
@result.should be_nil
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe '.dump' do
|
|
39
|
+
describe 'when argument is a regular expression' do
|
|
40
|
+
before do
|
|
41
|
+
@input = /\d+/
|
|
42
|
+
@result = @property.dump(@input)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'escapes the argument' do
|
|
46
|
+
@result.should == '\\d+'
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe 'when argument is nil' do
|
|
51
|
+
before do
|
|
52
|
+
@input = nil
|
|
53
|
+
@result = @property.dump(@input)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'returns nil' do
|
|
57
|
+
@result.should be_nil
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
require './spec/fixtures/bookmark'
|
|
4
|
+
|
|
5
|
+
try_spec do
|
|
6
|
+
describe Ardm::Property::URI do
|
|
7
|
+
before do
|
|
8
|
+
@uri_str = 'http://example.com/path/to/resource/'
|
|
9
|
+
@uri = Addressable::URI.parse(@uri_str)
|
|
10
|
+
|
|
11
|
+
@property = Ardm::Fixtures::Bookmark.properties[:uri]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe '.dump' do
|
|
15
|
+
it 'returns the URI as a String' do
|
|
16
|
+
@property.dump(@uri).should == @uri_str
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe 'when given nil' do
|
|
20
|
+
it 'returns nil' do
|
|
21
|
+
@property.dump(nil).should be_nil
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe 'when given an empty string' do
|
|
26
|
+
it 'returns an empty URI' do
|
|
27
|
+
@property.dump('').should == ''
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe '.load' do
|
|
33
|
+
it 'returns the URI as Addressable' do
|
|
34
|
+
@property.load(@uri_str).should == @uri
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe 'when given nil' do
|
|
38
|
+
it 'returns nil' do
|
|
39
|
+
@property.load(nil).should be_nil
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe 'if given an empty String' do
|
|
44
|
+
it 'returns an empty URI' do
|
|
45
|
+
@property.load('').should == Addressable::URI.parse('')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe '.typecast' do
|
|
51
|
+
describe 'given instance of Addressable::URI' do
|
|
52
|
+
it 'does nothing' do
|
|
53
|
+
@property.typecast(@uri).should == @uri
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe 'when given a string' do
|
|
58
|
+
it 'delegates to .load' do
|
|
59
|
+
@property.typecast(@uri_str).should == @uri
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'shared/identity_function_group'
|
|
3
|
+
|
|
4
|
+
try_spec do
|
|
5
|
+
|
|
6
|
+
require './spec/fixtures/person'
|
|
7
|
+
|
|
8
|
+
describe Ardm::Property::Yaml do
|
|
9
|
+
before do
|
|
10
|
+
@property = Ardm::Fixtures::Person.properties[:inventions]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '.load' do
|
|
14
|
+
describe 'when nil is provided' do
|
|
15
|
+
it 'returns nil' do
|
|
16
|
+
@property.load(nil).should be_nil
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe 'when YAML encoded primitive string is provided' do
|
|
21
|
+
it 'returns decoded value as Ruby string' do
|
|
22
|
+
@property.load("--- yaml string\n").should == 'yaml string'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe 'when something else is provided' do
|
|
27
|
+
it 'raises ArgumentError with a meaningful message' do
|
|
28
|
+
lambda {
|
|
29
|
+
@property.load(:sym)
|
|
30
|
+
}.should raise_error(ArgumentError, '+value+ of a property of YAML type must be nil or a String')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe '.dump' do
|
|
36
|
+
describe 'when nil is provided' do
|
|
37
|
+
it 'returns nil' do
|
|
38
|
+
@property.dump(nil).should be_nil
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe 'when YAML encoded primitive string is provided' do
|
|
43
|
+
it 'does not do double encoding' do
|
|
44
|
+
YAML.load(@property.dump("--- yaml encoded string\n")).should == 'yaml encoded string'
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe 'when regular Ruby string is provided' do
|
|
49
|
+
it 'dumps argument to YAML' do
|
|
50
|
+
YAML.load(@property.dump('dump me (to yaml)')).should == 'dump me (to yaml)'
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe 'when Ruby array is provided' do
|
|
55
|
+
it 'dumps argument to YAML' do
|
|
56
|
+
YAML.load(@property.dump([ 1, 2, 3 ])).should == [ 1, 2, 3 ]
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe 'when Ruby hash is provided' do
|
|
61
|
+
it 'dumps argument to YAML' do
|
|
62
|
+
YAML.load(@property.dump({ :datamapper => 'Data access layer in Ruby' })).should == { :datamapper => 'Data access layer in Ruby' }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe '.typecast' do
|
|
68
|
+
class ::SerializeMe
|
|
69
|
+
attr_accessor :name
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe 'given a number' do
|
|
73
|
+
before do
|
|
74
|
+
@input = 15
|
|
75
|
+
@result = 15
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it_should_behave_like 'identity function'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe 'given an Array instance' do
|
|
82
|
+
before do
|
|
83
|
+
@input = ['ardm', 'dm-more']
|
|
84
|
+
@result = ['ardm', 'dm-more']
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it_should_behave_like 'identity function'
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
describe 'given a Hash instance' do
|
|
91
|
+
before do
|
|
92
|
+
@input = { :format => 'yaml' }
|
|
93
|
+
@result = { :format => 'yaml' }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it_should_behave_like 'identity function'
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe 'given a plain old Ruby object' do
|
|
100
|
+
before do
|
|
101
|
+
@input = SerializeMe.new
|
|
102
|
+
@input.name = 'yamly'
|
|
103
|
+
|
|
104
|
+
@result = @input
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it_should_behave_like 'identity function'
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
data/tasks/spec.rake
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
spec_defaults = lambda do |spec|
|
|
2
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
3
|
+
spec.libs << 'lib' << 'spec'
|
|
4
|
+
spec.spec_opts << '--options' << 'spec/spec.opts'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
begin
|
|
8
|
+
require 'rspec/core/rake_task'
|
|
9
|
+
RSpec::Core::RakeTask.new do |t|
|
|
10
|
+
t.rspec_opts = %w[--color]
|
|
11
|
+
t.pattern = 'spec/**/*_spec.rb'
|
|
12
|
+
end
|
|
13
|
+
rescue LoadError
|
|
14
|
+
task :spec do
|
|
15
|
+
abort 'rspec is not available. In order to run spec, you must: gem install rspec'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
begin
|
|
20
|
+
require 'rcov'
|
|
21
|
+
require 'spec/rake/verify_rcov'
|
|
22
|
+
|
|
23
|
+
Spec::Rake::SpecTask.new(:rcov) do |rcov|
|
|
24
|
+
spec_defaults.call(rcov)
|
|
25
|
+
rcov.rcov = true
|
|
26
|
+
rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
|
|
30
|
+
rcov.threshold = 100
|
|
31
|
+
end
|
|
32
|
+
rescue LoadError
|
|
33
|
+
%w[ rcov verify_rcov ].each do |name|
|
|
34
|
+
task name do
|
|
35
|
+
abort "rcov is not available. In order to run #{name}, you must: gem install rcov"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
task :default => :spec
|
data/tasks/yard.rake
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'pathname'
|
|
3
|
+
require 'yardstick/rake/measurement'
|
|
4
|
+
require 'yardstick/rake/verify'
|
|
5
|
+
|
|
6
|
+
# yardstick_measure task
|
|
7
|
+
Yardstick::Rake::Measurement.new
|
|
8
|
+
|
|
9
|
+
# verify_measurements task
|
|
10
|
+
Yardstick::Rake::Verify.new do |verify|
|
|
11
|
+
verify.threshold = 100
|
|
12
|
+
end
|
|
13
|
+
rescue LoadError
|
|
14
|
+
%w[ yardstick_measure verify_measurements ].each do |name|
|
|
15
|
+
task name.to_s do
|
|
16
|
+
abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|