mleung-koujou 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -63,7 +63,6 @@ module Koujou #:nodoc:
63
63
  # or if this is a validates_presence_of :some_id. The ids will be set
64
64
  # when we create the association.
65
65
  next if overridden_attribute?(attributes, v.name)
66
- # has_required_id_validation?(instance, v.name)
67
66
 
68
67
  generate_and_set_data(instance, v, false)
69
68
  end
@@ -121,7 +120,7 @@ module Koujou #:nodoc:
121
120
  instance.class.reflect_on_all_associations.each do |a|
122
121
  # We only want to create the association if the user has required the id field.
123
122
  # This will build the minimum valid requirements.
124
- next unless has_required_id_validation?(instance, a.name)
123
+ next unless has_required_id_validation?(instance, a)
125
124
 
126
125
  if a.macro == :has_one || a.macro == :belongs_to
127
126
  # If there's a two way association here (user has_one profile, profile belongs_to user)
@@ -198,7 +197,8 @@ module Koujou #:nodoc:
198
197
  options[:in]
199
198
  end
200
199
 
201
- def has_required_id_validation?(instance, name)
200
+ def has_required_id_validation?(instance, association)
201
+ name = association.options.has_key?(:class_name) ? association.options[:class_name].downcase : association.name
202
202
  !instance.class.required_validations.select{|v| v.name.to_s == "#{name}_id" }.empty?
203
203
  end
204
204
 
@@ -7,6 +7,8 @@ module Koujou #:nodoc:
7
7
  @sequenced = sequenced
8
8
  # Validation is actually a ActiveRecord::Reflection::MacroReflection
9
9
  @validation = validation
10
+ @required_length = nil
11
+ @inclusion_values = nil
10
12
  end
11
13
 
12
14
  def generate_data_for_column_type
@@ -60,10 +60,6 @@ module Koujou # :nodoc:
60
60
  reflected_validations.each do |validation_type|
61
61
  next if base.respond_to?("#{validation_type}_with_reflection")
62
62
  ignore_subvalidations = false
63
- if validation_type.kind_of?(Hash)
64
- ignore_subvalidations = validation_type[:ignore_subvalidations]
65
- validation_type = validation_type[:method]
66
- end
67
63
  base.class_eval <<-"end_eval"
68
64
  class << self
69
65
  def #{validation_type}_with_reflection(*attr_names)
@@ -118,7 +114,7 @@ module Koujou # :nodoc:
118
114
 
119
115
  def custom_validations
120
116
  # We don't want to get anything like: validate_associated_records_for_posts.
121
- reflect_on_all_validations.select{|v| v.macro == :validate && !v.macro.to_s.match("_associated_") }
117
+ reflect_on_all_validations.select{|v| v.macro == :validate && v.name.to_s.match("_associated_").nil? }
122
118
  end
123
119
 
124
120
  private
@@ -35,6 +35,7 @@ class ActiveRecordTestConnector
35
35
  ActiveRecord::Schema.define do
36
36
  create_table "users", :force => true do |t|
37
37
  t.string "name", "email", "first_name", "last_name", "hashed_password"
38
+ t.text "about"
38
39
  t.integer "age"
39
40
  t.float "salary"
40
41
  t.datetime "hired_on"
@@ -106,9 +106,12 @@ class TestBuilder < Test::Unit::TestCase
106
106
  end
107
107
 
108
108
  should 'find custom validations' do
109
- User.reflect_on_all_validations.each do |v|
110
- puts v.inspect if v.macro == :validate
111
- end
109
+ assert_equal 2, User.custom_validations.size
110
+ end
111
+
112
+ should 'car should have an owner association to user via class_name' do
113
+ c = Car.koujou
114
+ assert_not_nil c.owner
112
115
  end
113
116
 
114
117
  end
@@ -35,6 +35,12 @@ class TestDataGenerator < Test::Unit::TestCase
35
35
  assert_match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, email)
36
36
  end
37
37
 
38
+ should 'genreate valid text field values' do
39
+ @validation.expects(:name).twice.returns('about')
40
+ body = Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
41
+ assert_not_nil body
42
+ end
43
+
38
44
  should 'generate a valid datetime' do
39
45
  @validation.expects(:name).twice.returns('hired_on')
40
46
  dt = Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mleung-koujou
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Leung
@@ -69,6 +69,7 @@ files:
69
69
  - test/test_sequence.rb
70
70
  has_rdoc: true
71
71
  homepage: http://github.com/mleung/koujou
72
+ licenses:
72
73
  post_install_message: PostInstall.txt
73
74
  rdoc_options:
74
75
  - --main
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  requirements: []
91
92
 
92
93
  rubyforge_project: koujou
93
- rubygems_version: 1.2.0
94
+ rubygems_version: 1.3.5
94
95
  signing_key:
95
96
  specification_version: 3
96
97
  summary: Koujou is a fixture replacement that requires no effort to use