polymorphic_model 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/polymorphic_model.rb +6 -2
- data/polymorphic_model.gemspec +2 -2
- data/spec/polymorphic_model_spec.rb +14 -7
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/polymorphic_model.rb
CHANGED
@@ -16,8 +16,12 @@ module PolymorphicModel
|
|
16
16
|
|
17
17
|
def validates_type
|
18
18
|
validates_each @_polymorphic_column, {:on => :save} do |record, attr_name, value|
|
19
|
-
unless
|
20
|
-
|
19
|
+
unless value.nil? || value == ""
|
20
|
+
unless self.types.include?(value.to_sym)
|
21
|
+
record.errors.add_to_base("is undefined type (#{value.to_s}), correct types are: [#{self.types.map(&:to_s).join(', ')}]")
|
22
|
+
end
|
23
|
+
else
|
24
|
+
record.errors.add_to_base("is not any type, correct types are: [#{self.types.map(&:to_s).join(', ')}]")
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
data/polymorphic_model.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{polymorphic_model}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Artur Roszczyk"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-24}
|
13
13
|
s.description = %q{Alternative for ActiveRecord's Single Table Inheritance}
|
14
14
|
s.email = %q{artur.roszczyk@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,8 +35,8 @@ describe "When normal collection types are defined" do
|
|
35
35
|
define_type :internal
|
36
36
|
define_type :external
|
37
37
|
end
|
38
|
-
2.times { @external = Job.create(:job_type => "external") }
|
39
|
-
3.times { @internal = Job.create(:job_type => "internal") }
|
38
|
+
2.times { @external = Job.create!(:job_type => "external") }
|
39
|
+
3.times { @internal = Job.create!(:job_type => "internal") }
|
40
40
|
end
|
41
41
|
|
42
42
|
describe "check methods" do
|
@@ -56,9 +56,17 @@ describe "When normal collection types are defined" do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should allow only defined types" do
|
59
|
-
Job.new(:job_type => "other")
|
59
|
+
@job = Job.new(:job_type => "other")
|
60
|
+
@job.should_not be_valid
|
60
61
|
end
|
61
|
-
|
62
|
+
|
63
|
+
it "should require any type" do
|
64
|
+
@job = Job.new
|
65
|
+
@job.should_not be_valid
|
66
|
+
@job.job_type = ""
|
67
|
+
@job.should_not be_valid
|
68
|
+
end
|
69
|
+
|
62
70
|
it "should provide list of defined types" do
|
63
71
|
Job.types.should include(:internal, :external)
|
64
72
|
end
|
@@ -108,11 +116,10 @@ describe "When singleton type is defined" do
|
|
108
116
|
before do
|
109
117
|
Job.destroy_all
|
110
118
|
end
|
111
|
-
|
112
|
-
Job.basic.should_not be_instance_of(Job)
|
113
|
-
end
|
119
|
+
|
114
120
|
it "should return empty scope" do
|
115
121
|
Job.basic.class.should == ActiveRecord::NamedScope::Scope
|
122
|
+
Job.basic.should be_empty
|
116
123
|
end
|
117
124
|
end
|
118
125
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polymorphic_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Roszczyk
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-24 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|