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,159 @@
|
|
|
1
|
+
share_examples_for 'A semipublic Property' do
|
|
2
|
+
module ::Blog
|
|
3
|
+
class Article < Ardm::Record
|
|
4
|
+
self.table_name = "articles"
|
|
5
|
+
property :id, Serial
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe '.new' do
|
|
10
|
+
describe 'when provided no options' do
|
|
11
|
+
it 'should return a Property' do
|
|
12
|
+
property.should be_kind_of(type)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'should set the load_as' do
|
|
16
|
+
property.load_as.should be(type.load_as)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'should set the model' do
|
|
20
|
+
property.model.should equal(model)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should set the options to the default' do
|
|
24
|
+
property.options.should == type.options.merge(options)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
[ :index, :unique_index, :unique, :lazy ].each do |attribute|
|
|
29
|
+
[ true, false, :title, [ :title ] ].each do |value|
|
|
30
|
+
opts = { attribute => value }
|
|
31
|
+
describe "when provided #{opts.inspect}" do
|
|
32
|
+
let(:property) { type.new(model, name, options.merge(opts)) }
|
|
33
|
+
|
|
34
|
+
it 'should return a Property' do
|
|
35
|
+
property.should be_kind_of(type)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should set the model' do
|
|
39
|
+
property.model.should equal(model)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should set the load_as' do
|
|
43
|
+
property.load_as.should be(type.load_as)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should set the options to #{opts.inspect}" do
|
|
47
|
+
property.options.should == type.options.merge(options.merge(opts))
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
[ [], nil ].each do |value|
|
|
53
|
+
describe "when provided #{(invalid_options = { attribute => value }).inspect}" do
|
|
54
|
+
it 'should raise an exception' do
|
|
55
|
+
lambda {
|
|
56
|
+
type.new(model, name, options.merge(invalid_options))
|
|
57
|
+
}.should raise_error(ArgumentError, "options[#{attribute.inspect}] must be either true, false, a Symbol or an Array of Symbols")
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe '#load' do
|
|
65
|
+
subject { property.load(value) }
|
|
66
|
+
|
|
67
|
+
before do
|
|
68
|
+
property.should_receive(:typecast).with(value).and_return(value)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it { should eql(value) }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe "#typecast" do
|
|
75
|
+
describe 'when value is nil' do
|
|
76
|
+
it 'returns value unchanged' do
|
|
77
|
+
property.typecast(nil).should be(nil)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe 'when value is a Ruby primitive' do
|
|
81
|
+
it 'returns value unchanged' do
|
|
82
|
+
property.typecast(value).should == value
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe '#valid?' do
|
|
89
|
+
describe 'when provided a valid value' do
|
|
90
|
+
it 'should return true' do
|
|
91
|
+
property.valid?(value).should be(true)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe 'when provide an invalid value' do
|
|
96
|
+
it 'should return false' do
|
|
97
|
+
property.valid?(invalid_value).should be(false)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe 'when provide a nil value when required' do
|
|
102
|
+
it 'should return false' do
|
|
103
|
+
property = type.new(model, name, options.merge(:required => true))
|
|
104
|
+
property.valid?(nil).should be(false)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe 'when provide a nil value when not required' do
|
|
109
|
+
it 'should return false' do
|
|
110
|
+
property = type.new(model, name, options.merge(:required => false))
|
|
111
|
+
property.valid?(nil).should be(true)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe '#assert_valid_value' do
|
|
117
|
+
subject do
|
|
118
|
+
property.assert_valid_value(value)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
shared_examples_for 'assert_valid_value on invalid value' do
|
|
122
|
+
it 'should raise Ardm::Property::InvalidValueError' do
|
|
123
|
+
expect { subject }.to(raise_error(Ardm::Property::InvalidValueError) do |error|
|
|
124
|
+
error.property.should == property
|
|
125
|
+
end)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe 'when provided a valid value' do
|
|
130
|
+
it 'should return true' do
|
|
131
|
+
subject.should be(true)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
describe 'when provide an invalid value' do
|
|
136
|
+
let(:value) { invalid_value }
|
|
137
|
+
|
|
138
|
+
it_should_behave_like 'assert_valid_value on invalid value'
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
describe 'when provide a nil value when required' do
|
|
142
|
+
let(:property) { type.new(model, name, options.merge(:required => true)) }
|
|
143
|
+
|
|
144
|
+
let(:value) { nil }
|
|
145
|
+
|
|
146
|
+
it_should_behave_like 'assert_valid_value on invalid value'
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe 'when provide a nil value when not required' do
|
|
150
|
+
let(:property) { type.new(model, name, options.merge(:required => false)) }
|
|
151
|
+
|
|
152
|
+
let(:value) { nil }
|
|
153
|
+
|
|
154
|
+
it 'should return true' do
|
|
155
|
+
subject.should be(true)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'pry'
|
|
2
|
+
require 'database_cleaner'
|
|
3
|
+
|
|
4
|
+
ENV['ORM'] ||= 'active_record'
|
|
5
|
+
require 'ardm/env'
|
|
6
|
+
|
|
7
|
+
Ardm.active_record do
|
|
8
|
+
ActiveRecord::Base.configurations = { "ardm" => {
|
|
9
|
+
"database" => "db/test.sqlite",
|
|
10
|
+
"adapter" => "sqlite3"
|
|
11
|
+
}}
|
|
12
|
+
ActiveRecord::Base.establish_connection 'ardm'
|
|
13
|
+
|
|
14
|
+
begin
|
|
15
|
+
$stdout = StringIO.new
|
|
16
|
+
load Pathname.new(__FILE__).dirname.expand_path.join("schema.rb")
|
|
17
|
+
ensure
|
|
18
|
+
$stdout = STDOUT
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
Ardm.data_mapper do
|
|
23
|
+
raise "TODO: DataMapper setup."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Dir["#{Pathname(__FILE__).dirname.expand_path}/shared/*.rb"].each { |file| require file }
|
|
27
|
+
|
|
28
|
+
RSpec.configure do |config|
|
|
29
|
+
config.before(:suite) do
|
|
30
|
+
DatabaseCleaner.strategy = :transaction
|
|
31
|
+
DatabaseCleaner.clean_with(:truncation)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
config.before(:each) do
|
|
35
|
+
DatabaseCleaner.start
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
config.after(:each) do
|
|
39
|
+
DatabaseCleaner.clean
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
DEPENDENCIES = {
|
|
44
|
+
'bcrypt' => 'bcrypt-ruby',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
def try_spec
|
|
48
|
+
begin
|
|
49
|
+
yield
|
|
50
|
+
rescue LoadError => error
|
|
51
|
+
match = error.message.match(/\Ano such file to load -- (.+)\z/)
|
|
52
|
+
raise error unless match && (lib = match[1])
|
|
53
|
+
|
|
54
|
+
gem_location = DEPENDENCIES[lib] || raise("Unknown lib #{lib}")
|
|
55
|
+
|
|
56
|
+
warn "[WARNING] Skipping specs using #{lib}, please do: gem install #{gem_location}"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
try_spec do
|
|
4
|
+
describe Ardm::Property::BCryptHash do
|
|
5
|
+
before do
|
|
6
|
+
@clear_password = 'Ardm R0cks!'
|
|
7
|
+
@crypted_password = BCrypt::Password.create(@clear_password)
|
|
8
|
+
|
|
9
|
+
@nonstandard_type = 1
|
|
10
|
+
|
|
11
|
+
class ::TestType
|
|
12
|
+
@a = 1
|
|
13
|
+
@b = 'Hi There'
|
|
14
|
+
end
|
|
15
|
+
@nonstandard_type2 = TestType.new
|
|
16
|
+
|
|
17
|
+
class ::User < Ardm::Record
|
|
18
|
+
property :id, Serial
|
|
19
|
+
property :password, BCryptHash
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@bcrypt_hash = User.properties[:password]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe '.dump' do
|
|
26
|
+
describe 'when argument is a string' do
|
|
27
|
+
before do
|
|
28
|
+
@input = 'Ardm'
|
|
29
|
+
@result = @bcrypt_hash.dump(@input)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'returns instance of BCrypt::Password' do
|
|
33
|
+
@result.should be_an_instance_of(BCrypt::Password)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'returns a string that is 60 characters long' do
|
|
37
|
+
@result.size.should == 60
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe 'when argument is nil' do
|
|
42
|
+
before do
|
|
43
|
+
@input = nil
|
|
44
|
+
@result = @bcrypt_hash.dump(@input)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'returns nil' do
|
|
48
|
+
@result.should be_nil
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe '.load' do
|
|
54
|
+
describe 'when argument is a string' do
|
|
55
|
+
before do
|
|
56
|
+
@input = 'Ardm'
|
|
57
|
+
@result = @bcrypt_hash.load(@crypted_password)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'returns instance of BCrypt::Password' do
|
|
61
|
+
@result.should be_an_instance_of(BCrypt::Password)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'returns a string that matches original' do
|
|
65
|
+
@result.should == @clear_password
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe 'when argument is nil' do
|
|
70
|
+
before do
|
|
71
|
+
@input = nil
|
|
72
|
+
@result = @bcrypt_hash.load(@input)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'returns nil' do
|
|
76
|
+
@result.should be_nil
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe '.typecast' do
|
|
82
|
+
describe 'when argument is a string' do
|
|
83
|
+
before do
|
|
84
|
+
@input = 'bcrypt hash'
|
|
85
|
+
@result = @bcrypt_hash.typecast(@input)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'casts argument to BCrypt::Password' do
|
|
89
|
+
@result.should be_an_instance_of(BCrypt::Password)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'casts argument to value that matches input' do
|
|
93
|
+
@result.should == @input
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe 'when argument is a blank string' do
|
|
98
|
+
before do
|
|
99
|
+
@input = ''
|
|
100
|
+
@result = @bcrypt_hash.typecast(@input)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'casts argument to BCrypt::Password' do
|
|
104
|
+
@result.should be_an_instance_of(BCrypt::Password)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'casts argument to value that matches input' do
|
|
108
|
+
@result.should == @input
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe 'when argument is integer' do
|
|
113
|
+
before do
|
|
114
|
+
@input = 2249
|
|
115
|
+
@result = @bcrypt_hash.typecast(@input)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'casts argument to BCrypt::Password' do
|
|
119
|
+
@result.should be_an_instance_of(BCrypt::Password)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'casts argument to value that matches input' do
|
|
123
|
+
@result.should == @input
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe 'when argument is hash' do
|
|
128
|
+
before do
|
|
129
|
+
@input = { :cryptic => 'obscure' }
|
|
130
|
+
@result = @bcrypt_hash.typecast(@input)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'casts argument to BCrypt::Password' do
|
|
134
|
+
@result.should be_an_instance_of(BCrypt::Password)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'casts argument to value that matches input' do
|
|
138
|
+
@result.should == @input
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
describe 'when argument is nil' do
|
|
143
|
+
before do
|
|
144
|
+
@input = nil
|
|
145
|
+
@result = @bcrypt_hash.typecast(@input)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it 'returns nil' do
|
|
149
|
+
@result.should be_nil
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
try_spec do
|
|
4
|
+
describe Ardm::Property::Csv do
|
|
5
|
+
before do
|
|
6
|
+
class ::User < Ardm::Record
|
|
7
|
+
property :id, Serial
|
|
8
|
+
property :things, Csv
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
@property = User.properties[:things]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe '.load' do
|
|
15
|
+
describe 'when argument is a comma separated string' do
|
|
16
|
+
before do
|
|
17
|
+
@input = 'uno,due,tre'
|
|
18
|
+
@result = @property.load(@input)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'parses the argument using CVS parser' do
|
|
22
|
+
@result.should == [ %w[ uno due tre ] ]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe 'when argument is an empty array' do
|
|
27
|
+
before do
|
|
28
|
+
@input = []
|
|
29
|
+
@result = @property.load(@input)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'does not change the input' do
|
|
33
|
+
@result.should == @input
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe 'when argument is an empty hash' do
|
|
38
|
+
before do
|
|
39
|
+
@input = {}
|
|
40
|
+
@result = @property.load(@input)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'returns nil' do
|
|
44
|
+
@result.should be_nil
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe 'when argument is nil' do
|
|
49
|
+
before do
|
|
50
|
+
@input = nil
|
|
51
|
+
@result = @property.load(@input)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'returns nil' do
|
|
55
|
+
@result.should be_nil
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe 'when argument is an integer' do
|
|
60
|
+
before do
|
|
61
|
+
@input = 7
|
|
62
|
+
@result = @property.load(@input)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'returns nil' do
|
|
66
|
+
@result.should be_nil
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe 'when argument is a float' do
|
|
71
|
+
before do
|
|
72
|
+
@input = 7.0
|
|
73
|
+
@result = @property.load(@input)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'returns nil' do
|
|
77
|
+
@result.should be_nil
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe 'when argument is an array' do
|
|
82
|
+
before do
|
|
83
|
+
@input = [ 1, 2, 3 ]
|
|
84
|
+
@result = @property.load(@input)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'returns input as is' do
|
|
88
|
+
@result.should eql(@input)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
describe '.dump' do
|
|
94
|
+
describe 'when value is a list of lists' do
|
|
95
|
+
before do
|
|
96
|
+
@input = [ %w[ uno due tre ], %w[ uno dos tres ] ]
|
|
97
|
+
@result = @property.dump(@input)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'dumps value to comma separated string' do
|
|
101
|
+
@result.should == "uno,due,tre\nuno,dos,tres\n"
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe 'when value is a string' do
|
|
106
|
+
before do
|
|
107
|
+
@input = 'beauty hides in the deep'
|
|
108
|
+
@result = @property.dump(@input)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'returns input as is' do
|
|
112
|
+
@result.should == @input
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe 'when value is nil' do
|
|
117
|
+
before do
|
|
118
|
+
@input = nil
|
|
119
|
+
@result = @property.dump(@input)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'returns nil' do
|
|
123
|
+
@result.should be_nil
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe 'when value is a hash' do
|
|
128
|
+
before do
|
|
129
|
+
@input = { :library => 'Ardm', :language => 'Ruby' }
|
|
130
|
+
@result = @property.dump(@input)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'returns nil' do
|
|
134
|
+
@result.should be_nil
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'ardm/property/support/dirty_minder'
|
|
3
|
+
|
|
4
|
+
describe Ardm::Property::DirtyMinder,'set!' do
|
|
5
|
+
|
|
6
|
+
let(:property_class) do
|
|
7
|
+
Class.new(Ardm::Property::Object) do
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
let(:model) do
|
|
12
|
+
property_class = self.property_class
|
|
13
|
+
Class.new(Ardm::Record) do
|
|
14
|
+
self.table_name = 'api_users'
|
|
15
|
+
|
|
16
|
+
property :id, Ardm::Property::Serial
|
|
17
|
+
property :name, property_class
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
let(:resource) { model.new }
|
|
22
|
+
|
|
23
|
+
let(:object) { model.properties[:name] }
|
|
24
|
+
|
|
25
|
+
subject { object.set!(resource,value) }
|
|
26
|
+
|
|
27
|
+
shared_examples_for 'a non hooked value' do
|
|
28
|
+
it 'should not extend value with hook' do
|
|
29
|
+
value.should_not be_kind_of(Ardm::Property::DirtyMinder::Hooker)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
shared_examples_for 'a hooked value' do
|
|
34
|
+
it 'should extend value with hook' do
|
|
35
|
+
pending "FIXME: This probably should pass" do
|
|
36
|
+
value.should be_kind_of(Ardm::Property::DirtyMinder::Hooker)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
before do
|
|
42
|
+
subject
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context 'when setting nil' do
|
|
46
|
+
let(:value) { nil }
|
|
47
|
+
it_should_behave_like 'a non hooked value'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context 'when setting a String' do
|
|
51
|
+
let(:value) { "The fred" }
|
|
52
|
+
it_should_behave_like 'a non hooked value'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'when setting an Array' do
|
|
56
|
+
let(:value) { ["The fred"] }
|
|
57
|
+
it_should_behave_like 'a hooked value'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
context 'when setting a Hash' do
|
|
61
|
+
let(:value) { {"The" => "fred"} }
|
|
62
|
+
it_should_behave_like 'a hooked value'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
try_spec do
|
|
4
|
+
describe Ardm::Property::Enum do
|
|
5
|
+
before do
|
|
6
|
+
class ::User < Ardm::Record
|
|
7
|
+
property :id, Serial
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
@property_klass = Ardm::Property::Enum
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it_should_behave_like "A property with flags"
|
|
14
|
+
|
|
15
|
+
describe '.dump' do
|
|
16
|
+
before do
|
|
17
|
+
@enum = User.property(:enum, Ardm::Property::Enum[:first, :second, :third])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should return the key of the value match from the flag map' do
|
|
21
|
+
@enum.dump(:first).should == 1
|
|
22
|
+
@enum.dump(:second).should == 2
|
|
23
|
+
@enum.dump(:third).should == 3
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe 'when there is no match' do
|
|
27
|
+
it 'should return nil' do
|
|
28
|
+
@enum.dump(:zero).should be_nil
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '.load' do
|
|
34
|
+
before do
|
|
35
|
+
@enum = User.property(:enum, Ardm::Property::Enum, :flags => [:uno, :dos, :tres])
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'returns the value of the key match from the flag map' do
|
|
39
|
+
@enum.load(1).should == :uno
|
|
40
|
+
@enum.load(2).should == :dos
|
|
41
|
+
@enum.load(3).should == :tres
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe 'when there is no key' do
|
|
45
|
+
it 'returns nil' do
|
|
46
|
+
@enum.load(-1).should be_nil
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe '.typecast' do
|
|
52
|
+
describe 'of Enum created from a symbol' do
|
|
53
|
+
before do
|
|
54
|
+
@enum = User.property(:enum, Ardm::Property::Enum, :flags => [:uno])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe 'when given a symbol' do
|
|
58
|
+
it 'uses Enum type' do
|
|
59
|
+
@enum.typecast(:uno).should == :uno
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe 'when given a string' do
|
|
64
|
+
it 'uses Enum type' do
|
|
65
|
+
@enum.typecast('uno').should == :uno
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe 'when given nil' do
|
|
70
|
+
it 'returns nil' do
|
|
71
|
+
@enum.typecast( nil).should == nil
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe 'of Enum created from integer list' do
|
|
77
|
+
before do
|
|
78
|
+
@enum = User.property(:enum, Ardm::Property::Enum, :flags => [1, 2, 3])
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe 'when given an integer' do
|
|
82
|
+
it 'uses Enum type' do
|
|
83
|
+
@enum.typecast(1).should == 1
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe 'when given a float' do
|
|
88
|
+
it 'uses Enum type' do
|
|
89
|
+
@enum.typecast(1.1).should == 1
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
describe 'when given nil' do
|
|
94
|
+
it 'returns nil' do
|
|
95
|
+
@enum.typecast( nil).should == nil
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe 'of Enum created from a string' do
|
|
101
|
+
before do
|
|
102
|
+
@enum = User.property(:enum, Ardm::Property::Enum, :flags => ['uno'])
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe 'when given a symbol' do
|
|
106
|
+
it 'uses Enum type' do
|
|
107
|
+
@enum.typecast(:uno).should == 'uno'
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
describe 'when given a string' do
|
|
112
|
+
it 'uses Enum type' do
|
|
113
|
+
@enum.typecast('uno').should == 'uno'
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe 'when given nil' do
|
|
118
|
+
it 'returns nil' do
|
|
119
|
+
@enum.typecast( nil).should == nil
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|