sample_models 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.3
1
+ 1.2.4
@@ -175,11 +175,17 @@ module SampleModels
175
175
  class ValidatesUniquenessOfValueStream < ValueStream
176
176
  def satisfying_value
177
177
  value = input.satisfying_value if input
178
- if !@model.unique?(@field, value)
179
- my_input = input || ValidatesPresenceOfValueStream.new(@model, @field, nil, @input)
180
- until @model.unique?(@field, value)
181
- my_input.increment
182
- value = my_input.satisfying_value
178
+ unless @config[:allow_nil] && value.nil?
179
+ unless @config[:allow_blank] && value.blank?
180
+ if !@model.unique?(@field, value)
181
+ my_input = input || ValidatesPresenceOfValueStream.new(
182
+ @model, @field, nil, @input
183
+ )
184
+ until @model.unique?(@field, value)
185
+ my_input.increment
186
+ value = my_input.satisfying_value
187
+ end
188
+ end
183
189
  end
184
190
  end
185
191
  value
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sample_models}
8
- s.version = "1.2.3"
8
+ s.version = "1.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Francis Hwang"]
12
- s.date = %q{2011-06-11}
12
+ s.date = %q{2011-07-16}
13
13
  s.description = %q{
14
14
  A library for making it extremely fast for Rails developers to set up and save ActiveRecord instances when writing test cases. It aims to:
15
15
 
@@ -69,6 +69,9 @@ def initialize_db
69
69
  episode.date 'original_air_date'
70
70
  end
71
71
 
72
+ create_table 'external_users', :force => true do |external_user|
73
+ end
74
+
72
75
  create_table 'networks', :force => true do |network|
73
76
  network.string 'name'
74
77
  end
@@ -88,7 +91,7 @@ def initialize_db
88
91
  end
89
92
 
90
93
  create_table 'users', :force => true do |user|
91
- user.integer 'favorite_blog_post_id'
94
+ user.integer 'favorite_blog_post_id', 'external_user_id'
92
95
  user.string 'email', 'gender', 'homepage', 'login', 'password'
93
96
  end
94
97
 
@@ -171,6 +174,9 @@ class Episode < ActiveRecord::Base
171
174
  validates_presence_of :show_id, :original_air_date
172
175
  end
173
176
 
177
+ class ExternalUser < ActiveRecord::Base
178
+ end
179
+
174
180
  class Network < ActiveRecord::Base
175
181
  end
176
182
 
@@ -193,10 +199,12 @@ end
193
199
  class User < ActiveRecord::Base
194
200
  belongs_to :favorite_blog_post,
195
201
  :class_name => 'BlogPost', :foreign_key => 'favorite_blog_post_id'
202
+ belongs_to :external_user
196
203
 
197
204
  validates_email_format_of :email
198
205
  validates_inclusion_of :gender, :in => %w(f m)
199
206
  validates_uniqueness_of :email, :login, :case_sensitive => false
207
+ validates_uniqueness_of :external_user_id, :allow_nil => true
200
208
  end
201
209
 
202
210
  class User2 < ActiveRecord::Base
@@ -261,6 +269,10 @@ SampleModels.configure Subscription do |sub|
261
269
  sub.subscribable.default_class BlogPost
262
270
  end
263
271
 
272
+ SampleModels.configure User do |user|
273
+ user.external_user_id.default nil
274
+ end
275
+
264
276
  SampleModels.configure Video do |video|
265
277
  video.before_save do |v, sample_attrs|
266
278
  if v.episode && v.episode.show != v.show
@@ -576,3 +576,11 @@ describe 'Model which validates the presence and uniqueness of a string field' d
576
576
  end
577
577
  end
578
578
 
579
+ describe 'Model that validates uniqueness with an allow-nil constraint' do
580
+ it 'should let you configure the default to be nil' do
581
+ User.sample
582
+ user = User.create_sample
583
+ assert_nil user.external_user
584
+ assert_nil user.external_user_id
585
+ end
586
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sample_models
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 3
10
- version: 1.2.3
9
+ - 4
10
+ version: 1.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Francis Hwang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-11 00:00:00 -04:00
18
+ date: 2011-07-16 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency