schematic 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ module Schematic
|
|
5
5
|
def generate(builder)
|
6
6
|
for_validator ActiveRecord::Validations::UniquenessValidator do |validator|
|
7
7
|
unique_name = validator.attributes.first.to_s.dasherize
|
8
|
-
additional_fields = (validator.options[:scope] || []).map(&:to_s).map(&:dasherize)
|
8
|
+
additional_fields = (Array.wrap(validator.options[:scope]) || []).map(&:to_s).map(&:dasherize)
|
9
9
|
|
10
10
|
names = Schematic::Generator::Names.new(@klass)
|
11
11
|
builder.xs :unique, "name" => "#{unique_name}-must-be-unique" do |unique|
|
data/lib/schematic/version.rb
CHANGED
@@ -54,29 +54,51 @@ describe Schematic::Generator::Uniqueness do
|
|
54
54
|
|
55
55
|
context "for a model with a column with uniqueness with scope" do
|
56
56
|
subject { sanitize_xml(TestModel.to_xsd) }
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
|
58
|
+
shared_examples_for "single field in scope" do
|
59
|
+
it "should validate against it's own XSD" do
|
60
|
+
first_instance = TestModel.new(:some_field => "first", :other_field => "unique")
|
61
|
+
another_instance = TestModel.new(:some_field => "first", :other_field => "alsounique")
|
62
|
+
duplicate_instance = TestModel.new(:some_field => "first", :other_field => "unique")
|
63
|
+
xml = [first_instance, duplicate_instance, another_instance].to_xml
|
64
|
+
lambda {
|
65
|
+
validate_xml_against_xsd(xml, subject)
|
66
|
+
}.should raise_error
|
67
|
+
xml = [first_instance, another_instance].to_xml
|
68
|
+
lambda {
|
69
|
+
validate_xml_against_xsd(xml, subject)
|
70
|
+
}.should_not raise_error
|
61
71
|
end
|
72
|
+
end
|
62
73
|
|
63
|
-
|
64
|
-
|
74
|
+
context "when the scope is a symbol" do
|
75
|
+
with_model :test_model do
|
76
|
+
table :id => false do |t|
|
77
|
+
t.string "some_field"
|
78
|
+
t.string "other_field"
|
79
|
+
end
|
80
|
+
|
81
|
+
model do
|
82
|
+
validates :some_field, :uniqueness => { :scope => :other_field }
|
83
|
+
end
|
65
84
|
end
|
85
|
+
|
86
|
+
it_behaves_like "single field in scope"
|
66
87
|
end
|
67
88
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
89
|
+
context "when the scope is an array" do
|
90
|
+
with_model :test_model do
|
91
|
+
table :id => false do |t|
|
92
|
+
t.string "some_field"
|
93
|
+
t.string "other_field"
|
94
|
+
end
|
95
|
+
|
96
|
+
model do
|
97
|
+
validates :some_field, :uniqueness => { :scope => [:other_field] }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it_behaves_like "single field in scope"
|
80
102
|
end
|
81
103
|
end
|
82
104
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schematic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152959400 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152959400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: builder
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152958280 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152958280
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec-rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152957200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.1'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152957200
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: with_model
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152955660 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.2.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152955660
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: nokogiri
|
60
|
-
requirement: &
|
60
|
+
requirement: &2152954800 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2152954800
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
|
-
requirement: &
|
71
|
+
requirement: &2152953920 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2152953920
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: autotest
|
82
|
-
requirement: &
|
82
|
+
requirement: &2152952540 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2152952540
|
91
91
|
description: Automatic XSD generation from ActiveRecord models
|
92
92
|
email:
|
93
93
|
- casecommons-dev@googlegroups.com
|
@@ -153,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: '0'
|
154
154
|
segments:
|
155
155
|
- 0
|
156
|
-
hash: -
|
156
|
+
hash: -3956753853577588500
|
157
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
158
|
none: false
|
159
159
|
requirements:
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
segments:
|
164
164
|
- 0
|
165
|
-
hash: -
|
165
|
+
hash: -3956753853577588500
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project: schematic
|
168
168
|
rubygems_version: 1.8.10
|