koujou 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +1 -0
- data/koujou.gemspec +1 -1
- data/lib/koujou.rb +1 -1
- data/lib/koujou/builder.rb +6 -0
- data/test/lib/active_record_test_connector.rb +5 -0
- data/test/lib/models/comment.rb +3 -2
- data/test/lib/models/invite.rb +9 -0
- data/test/test_builder.rb +29 -3
- metadata +4 -3
data/History.txt
CHANGED
@@ -2,3 +2,9 @@
|
|
2
2
|
|
3
3
|
* 1 major enhancement:
|
4
4
|
* Initial release
|
5
|
+
|
6
|
+
=== 0.1.3 2010-05-27
|
7
|
+
|
8
|
+
* 2 small fixes:
|
9
|
+
* fix for how Koujou deals with polymorphic associations, ensuring that it leaves polymorphic fields up to the user to populate
|
10
|
+
* fix to ignore the inheritance column and not generate data for it when working with STI models
|
data/Manifest.txt
CHANGED
data/koujou.gemspec
CHANGED
data/lib/koujou.rb
CHANGED
data/lib/koujou/builder.rb
CHANGED
@@ -119,6 +119,8 @@ module Koujou #:nodoc:
|
|
119
119
|
# We only want to create the association if the user has required the id field.
|
120
120
|
# This will build the minimum valid requirements.
|
121
121
|
next unless has_required_id_validation?(instance, a)
|
122
|
+
# Skip polymorphic associations as we don't know what to build for them
|
123
|
+
next if a.options.keys.include?(:polymorphic) && a.options[:polymorphic] == true
|
122
124
|
|
123
125
|
if a.macro == :has_one || a.macro == :belongs_to
|
124
126
|
# If there's a two way association here (user has_one profile, profile belongs_to user)
|
@@ -144,6 +146,10 @@ module Koujou #:nodoc:
|
|
144
146
|
end
|
145
147
|
|
146
148
|
def generate_and_set_data(instance, validation, sequenced)
|
149
|
+
# Don't set if it's the inheritance column
|
150
|
+
return if validation.name.to_s == instance.class.inheritance_column.to_s
|
151
|
+
# Don't set values for polymorphic association fields - if no values are supplied we'll want that to just fall through to validation errors
|
152
|
+
return if instance.class.reflect_on_all_associations.select { |a| a.options.keys.include?(:polymorphic) && a.options[:polymorphic] == true }.collect { |a| [:"#{a.name}_id", :"#{a.name}_type"] }.flatten.include?(validation.name)
|
147
153
|
data_generator = DataGenerator.new(sequenced, validation)
|
148
154
|
data_generator.required_length = get_required_length(instance, validation)
|
149
155
|
if has_inclusion_validation?(instance, validation)
|
@@ -49,6 +49,8 @@ class ActiveRecordTestConnector
|
|
49
49
|
create_table "comments", :force => true do |t|
|
50
50
|
t.text "bod"
|
51
51
|
t.integer "post_id"
|
52
|
+
t.integer "commentable_id"
|
53
|
+
t.string "commentable_type"
|
52
54
|
end
|
53
55
|
create_table "profiles", :force => true do |t|
|
54
56
|
t.integer "user_id"
|
@@ -70,6 +72,9 @@ class ActiveRecordTestConnector
|
|
70
72
|
t.integer "user_id", "year"
|
71
73
|
t.string "make", "model"
|
72
74
|
end
|
75
|
+
create_table "invites", :force => true do |t|
|
76
|
+
t.string "type"
|
77
|
+
end
|
73
78
|
end
|
74
79
|
end
|
75
80
|
|
data/test/lib/models/comment.rb
CHANGED
data/test/test_builder.rb
CHANGED
@@ -71,7 +71,8 @@ class TestBuilder < Test::Unit::TestCase
|
|
71
71
|
|
72
72
|
should 'allow me to override the model attributes' do
|
73
73
|
comment = 'your post is epic fail'
|
74
|
-
|
74
|
+
p = Post.koujou
|
75
|
+
c = Comment.koujou_create(:bod => comment, :commentable_id => p.id, :commentable_type => p.class.name)
|
75
76
|
assert_equal comment, c.bod
|
76
77
|
end
|
77
78
|
|
@@ -80,7 +81,6 @@ class TestBuilder < Test::Unit::TestCase
|
|
80
81
|
# The first digit should not be an integer.
|
81
82
|
assert_equal 0, u.first_name[0,1].to_i
|
82
83
|
end
|
83
|
-
|
84
84
|
end
|
85
85
|
|
86
86
|
context 'on sending the koujou_build message' do
|
@@ -147,7 +147,33 @@ class TestBuilder < Test::Unit::TestCase
|
|
147
147
|
end
|
148
148
|
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
|
+
context "using polymorphic associations" do
|
152
|
+
should "leave the association alone and not validate if no values supplied" do
|
153
|
+
ex = assert_raise ActiveRecord::RecordInvalid do
|
154
|
+
c = Comment.koujou(true, :bod => "test body")
|
155
|
+
end
|
156
|
+
assert_equal "Validation failed: Commentable can't be blank, Commentable type can't be blank", ex.message
|
157
|
+
end
|
158
|
+
|
159
|
+
should "work when supplying the polymorphic fields" do
|
160
|
+
p = Post.koujou
|
161
|
+
c = Comment.koujou(true, :bod => "test body", :commentable_type => p.class.name, :commentable_id => p.id)
|
162
|
+
assert_equal p.id, c.commentable.id
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "using STI" do
|
167
|
+
should "not be setting the type field to something random" do
|
168
|
+
@event_invite = EventInvite.koujou
|
169
|
+
assert_equal 1, EventInvite.all.length
|
170
|
+
assert_equal "EventInvite", @event_invite.reload.type
|
171
|
+
@group_invite = GroupInvite.koujou
|
172
|
+
assert_equal 1, GroupInvite.all.length
|
173
|
+
assert_equal "GroupInvite", @group_invite.reload.type
|
174
|
+
assert_equal 2, Invite.all.length
|
175
|
+
end
|
176
|
+
end
|
151
177
|
|
152
178
|
end
|
153
179
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Leung
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-27 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- test/lib/active_record_test_connector.rb
|
84
84
|
- test/lib/models/car.rb
|
85
85
|
- test/lib/models/comment.rb
|
86
|
+
- test/lib/models/invite.rb
|
86
87
|
- test/lib/models/message.rb
|
87
88
|
- test/lib/models/photo.rb
|
88
89
|
- test/lib/models/post.rb
|