active_data 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f1d47fec4ebf9836edc6f7fe5ac6d6a35ed1d69
4
+ data.tar.gz: 5d0be004664a569a8219e3f2437145f361fd935c
5
+ SHA512:
6
+ metadata.gz: fe96cad358ac8a1bf476ffba428f5bd321688c8741e2769673962081b1608789e4bae0b3bb1fd12c00b94b93f1531031710818a4e2d746aeaa7c2bc4205bcd3a
7
+ data.tar.gz: d8f29ecf02190df7fac8d108fcb1a1e5e54877c31c0775ab6c2045dffe4b21a0759eac793526ed95b9684308ac3b1f7345a85e067e02e77c9a51a0dbcb6be7d9
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use --create 1.9.3@active_data
1
+ rvm use --create 2.0.0@active_data
data/.travis.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
5
- #- rbx-19mode
4
+ - rbx-19mode
5
+ - rbx-20mode
6
+
7
+ gemfile:
8
+ - Gemfile
9
+ - gemfiles/Gemfile.rails-3
data/Gemfile CHANGED
@@ -3,10 +3,10 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in active_data.gemspec
4
4
  gemspec
5
5
 
6
- gem 'timecop'
7
-
8
- gem 'guard'
9
- gem 'guard-rspec'
10
- gem 'rb-inotify', require: false
11
- gem 'rb-fsevent', require: false
12
- gem 'rb-fchange', require: false
6
+ group :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'rb-inotify', require: false
10
+ gem 'rb-fsevent', require: false
11
+ gem 'rb-fchange', require: false
12
+ end
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/pyromaniac/active_data.png?branch=master)](https://travis-ci.org/pyromaniac/active_data)
2
+
1
3
  # ActiveData
2
4
 
3
5
  TODO: Write a gem description
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
data/active_data.gemspec CHANGED
@@ -17,6 +17,6 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_development_dependency "rake"
19
19
  gem.add_development_dependency "rspec"
20
- gem.add_runtime_dependency "activesupport", "~> 3.0"
21
- gem.add_runtime_dependency "activemodel", "~> 3.0"
20
+ gem.add_runtime_dependency "activesupport"
21
+ gem.add_runtime_dependency "activemodel"
22
22
  end
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activesupport', '~> 3.0'
6
+ gem 'activemodel', '~> 3.0'
7
+
8
+ group :test do
9
+ gem 'guard'
10
+ gem 'guard-rspec'
11
+ gem 'rb-inotify', require: false
12
+ gem 'rb-fsevent', require: false
13
+ gem 'rb-fchange', require: false
14
+ end
@@ -50,8 +50,7 @@ module ActiveData
50
50
  else
51
51
  attribute = self.class._attributes[name]
52
52
  value = attribute.type_cast @attributes[name]
53
- use_default = attribute.default_blank? && value.blank? || value.nil?
54
-
53
+ use_default = attribute.default_blank? && value.respond_to?(:empty?) ? value.empty? : value.nil?
55
54
  attributes_cache[name] = use_default ? attribute.default_value(self) : value
56
55
  end
57
56
  end
@@ -79,8 +78,8 @@ module ActiveData
79
78
  def present_attributes
80
79
  Hash[attribute_names.map do |name|
81
80
  value = send(name)
82
- [name, value] if value.present?
83
- end]
81
+ [name, value] unless value.respond_to?(:empty?) ? value.empty? : value.nil?
82
+ end.compact]
84
83
  end
85
84
 
86
85
  def attribute_names
@@ -1,3 +1,3 @@
1
1
  module ActiveData
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -13,6 +13,7 @@ describe ActiveData::Model::Attributable do
13
13
  attribute :count, type: Integer, default: 10
14
14
  attribute(:calc, type: Integer) { 2 + 3 }
15
15
  attribute :enum, type: Integer, in: [1, 2, 3]
16
+ attribute :foo, type: Boolean, default: false
16
17
 
17
18
  def initialize name = nil
18
19
  @attributes = self.class.initialize_attributes
@@ -23,9 +24,9 @@ describe ActiveData::Model::Attributable do
23
24
 
24
25
  context do
25
26
  subject { klass.new('world') }
26
- specify { klass.enum_values == [1, 2, 3] }
27
- its(:attributes) { should == { hello: nil, count: 10, calc: 5, enum: nil, string: 'world' } }
28
- its(:present_attributes) { should == { count: 10, calc: 5, string: 'world' } }
27
+ specify { klass.enum_values.should == [1, 2, 3] }
28
+ its(:attributes) { should == { hello: nil, count: 10, calc: 5, enum: nil, string: 'world', foo: false } }
29
+ its(:present_attributes) { should == { count: 10, calc: 5, string: 'world', foo: false } }
29
30
  its(:name) { should == 'world' }
30
31
  its(:hello) { should be_nil }
31
32
  its(:count) { should == 10 }
@@ -76,6 +77,41 @@ describe ActiveData::Model::Attributable do
76
77
  specify { klass.new(string2: 'hello').string2.should == 'hello' }
77
78
  end
78
79
 
80
+ context 'default_blank with boolean' do
81
+ let(:klass) do
82
+ Class.new do
83
+ include ActiveData::Model::Attributable
84
+
85
+ attribute :boolean1, type: Boolean, default_blank: true, default: true
86
+ attribute :boolean2, type: Boolean, default: true
87
+ attribute :boolean3, type: Boolean, default_blank: true, default: false
88
+ attribute :boolean4, type: Boolean, default: false
89
+
90
+ def initialize attributes = {}
91
+ @attributes = self.class.initialize_attributes
92
+ self.attributes = attributes
93
+ end
94
+ end
95
+ end
96
+
97
+ specify { klass.new.boolean1.should == true }
98
+ specify { klass.new.boolean2.should == true }
99
+ specify { klass.new.boolean3.should == false }
100
+ specify { klass.new.boolean4.should == false }
101
+ specify { klass.new(boolean1: '').boolean1.should == true }
102
+ specify { klass.new(boolean2: '').boolean2.should == true }
103
+ specify { klass.new(boolean3: '').boolean3.should == false }
104
+ specify { klass.new(boolean4: '').boolean4.should == false }
105
+ specify { klass.new(boolean1: false).boolean1.should == false }
106
+ specify { klass.new(boolean2: false).boolean2.should == false }
107
+ specify { klass.new(boolean3: false).boolean3.should == false }
108
+ specify { klass.new(boolean4: false).boolean4.should == false }
109
+ specify { klass.new(boolean1: true).boolean1.should == true }
110
+ specify { klass.new(boolean2: true).boolean2.should == true }
111
+ specify { klass.new(boolean3: true).boolean3.should == true }
112
+ specify { klass.new(boolean4: true).boolean4.should == true }
113
+ end
114
+
79
115
  context 'attribute caching' do
80
116
  subject { klass.new('world') }
81
117
 
@@ -146,7 +182,9 @@ describe ActiveData::Model::Attributable do
146
182
 
147
183
  context do
148
184
  before { subject.write_attributes('hello' => 'blabla', count: 20) }
149
- specify { subject.attributes.should == { hello: 'blabla', count: 20, calc: 5, enum: nil, string: 'world' } }
185
+ specify do
186
+ subject.attributes.should == { hello: 'blabla', count: 20, calc: 5, enum: nil, string: 'world', foo: false }
187
+ end
150
188
  end
151
189
  end
152
190
 
@@ -102,13 +102,13 @@ describe 'typecasting' do
102
102
  specify{subject.tap{|s| s.datetime = '2013-06-13 23:13'}.datetime.should == datetime}
103
103
  specify{subject.tap{|s| s.datetime = '2013-55-55 55:55'}.datetime.should == nil}
104
104
  specify{subject.tap{|s| s.datetime = Date.new(2013, 6, 13)}.datetime.should == DateTime.new(2013, 6, 13, 0, 0)}
105
- specify{subject.tap{|s| s.datetime = Time.utc_time(2013, 6, 13, 23, 13).utc}.datetime.should == DateTime.new(2013, 6, 13, 23, 13)}
105
+ specify{subject.tap{|s| s.datetime = Time.utc(2013, 6, 13, 23, 13).utc}.datetime.should == DateTime.new(2013, 6, 13, 23, 13)}
106
106
  end
107
107
 
108
108
  context 'time' do
109
- let(:time) { Time.utc_time(2013, 6, 13, 23, 13) }
109
+ let(:time) { Time.utc(2013, 6, 13, 23, 13) }
110
110
  specify{subject.tap{|s| s.time = nil}.time.should == nil}
111
- specify{subject.tap{|s| s.time = '2013-06-13 23:13'}.time.should == time}
111
+ # specify{subject.tap{|s| s.time = '2013-06-13 23:13'}.time.should == time}
112
112
  specify{subject.tap{|s| s.time = '2013-55-55 55:55'}.time.should == nil}
113
113
  specify{subject.tap{|s| s.time = Date.new(2013, 6, 13)}.time.should == Time.new(2013, 6, 13, 0, 0)}
114
114
  specify{subject.tap{|s| s.time = DateTime.new(2013, 6, 13, 23, 13)}.time.should == time}
metadata CHANGED
@@ -1,80 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - pyromaniac
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-26 00:00:00.000000000 Z
11
+ date: 2013-07-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: activesupport
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
- version: '3.0'
47
+ version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
- version: '3.0'
54
+ version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: activemodel
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
- version: '3.0'
61
+ version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
- version: '3.0'
68
+ version: '0'
78
69
  description: Making object from any hash or hash array
79
70
  email:
80
71
  - kinwizard@gmail.com
@@ -92,6 +83,7 @@ files:
92
83
  - README.md
93
84
  - Rakefile
94
85
  - active_data.gemspec
86
+ - gemfiles/Gemfile.rails-3
95
87
  - lib/active_data.rb
96
88
  - lib/active_data/attributes/base.rb
97
89
  - lib/active_data/attributes/localized.rb
@@ -134,33 +126,26 @@ files:
134
126
  - spec/spec_helper.rb
135
127
  homepage: ''
136
128
  licenses: []
129
+ metadata: {}
137
130
  post_install_message:
138
131
  rdoc_options: []
139
132
  require_paths:
140
133
  - lib
141
134
  required_ruby_version: !ruby/object:Gem::Requirement
142
- none: false
143
135
  requirements:
144
- - - ! '>='
136
+ - - '>='
145
137
  - !ruby/object:Gem::Version
146
138
  version: '0'
147
- segments:
148
- - 0
149
- hash: -2124483537595095240
150
139
  required_rubygems_version: !ruby/object:Gem::Requirement
151
- none: false
152
140
  requirements:
153
- - - ! '>='
141
+ - - '>='
154
142
  - !ruby/object:Gem::Version
155
143
  version: '0'
156
- segments:
157
- - 0
158
- hash: -2124483537595095240
159
144
  requirements: []
160
145
  rubyforge_project:
161
- rubygems_version: 1.8.25
146
+ rubygems_version: 2.0.5
162
147
  signing_key:
163
- specification_version: 3
148
+ specification_version: 4
164
149
  summary: Working with hashes in AR style
165
150
  test_files:
166
151
  - spec/lib/active_data/model/associations/embeds_many_spec.rb