empty_eye 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/CHANGELOG.md +43 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +109 -0
- data/Rakefile +17 -0
- data/empty_eye.gemspec +32 -0
- data/lib/empty_eye/active_record/base.rb +133 -0
- data/lib/empty_eye/active_record/connection_adapter.rb +46 -0
- data/lib/empty_eye/active_record/schema_dumper.rb +18 -0
- data/lib/empty_eye/associations/builder/shard_has_one.rb +20 -0
- data/lib/empty_eye/associations/shard_association_scope.rb +79 -0
- data/lib/empty_eye/associations/shard_has_one_association.rb +35 -0
- data/lib/empty_eye/errors.rb +5 -0
- data/lib/empty_eye/persistence.rb +50 -0
- data/lib/empty_eye/primary_view_extension.rb +137 -0
- data/lib/empty_eye/relation.rb +85 -0
- data/lib/empty_eye/shard.rb +130 -0
- data/lib/empty_eye/shard_association_reflection.rb +28 -0
- data/lib/empty_eye/version.rb +9 -0
- data/lib/empty_eye/view_extension.rb +115 -0
- data/lib/empty_eye/view_extension_collection.rb +222 -0
- data/lib/empty_eye.rb +30 -0
- data/spec/configuration_spec.rb +35 -0
- data/spec/mti_crud_spec.rb +130 -0
- data/spec/mti_to_sti_to_mti_crud_spec.rb +160 -0
- data/spec/spec_helper.rb +120 -0
- data/spec/sti_to_mti_crud_spec.rb +138 -0
- data/spec/validation_spec.rb +84 -0
- metadata +160 -0
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
|
5
|
+
describe ActiveRecord::Base do
|
6
|
+
before(:each) do
|
7
|
+
exec_sql "truncate restaurants"
|
8
|
+
exec_sql "truncate businesses"
|
9
|
+
|
10
|
+
@restaurant = MexicanRestaurant.create(
|
11
|
+
:kids_area => false, :wifi => true, :food_genre => "mexican", # restaurant attributes
|
12
|
+
:address => "1904 Easy Kaley Orlando, FL 32806", :name => 'Chicos', :phone => '123456789' #business attributes
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "create" do
|
17
|
+
it "should create a sti to mti class correctly" do
|
18
|
+
@restaurant.kids_area.should eq(false)
|
19
|
+
@restaurant.wifi.should eq(true)
|
20
|
+
@restaurant.food_genre.should eq("mexican")
|
21
|
+
@restaurant.address.should eq("1904 Easy Kaley Orlando, FL 32806")
|
22
|
+
@restaurant.name.should eq("Chicos")
|
23
|
+
@restaurant.phone.should eq("123456789")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should create sti to mti associations correctly" do
|
27
|
+
@restaurant.business.class.should eq(Business)
|
28
|
+
|
29
|
+
@restaurant.business.address.should eq("1904 Easy Kaley Orlando, FL 32806")
|
30
|
+
@restaurant.business.name.should eq("Chicos")
|
31
|
+
@restaurant.business.phone.should eq("123456789")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "read" do
|
36
|
+
it "should find a sti to mti class correctly" do
|
37
|
+
@found_restaurant = MexicanRestaurant.find_by_id(@restaurant.id)
|
38
|
+
@restaurant.should eq(@found_restaurant)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should type cast a sti to mti class correctly" do
|
42
|
+
@found_restaurant = Restaurant.find_by_id(@restaurant.id)
|
43
|
+
@restaurant.class.should eq(@restaurant.class)
|
44
|
+
lambda { @found_restaurant.address }.should raise_error(ActiveModel::MissingAttributeError)
|
45
|
+
lambda { @found_restaurant.name }.should raise_error(ActiveModel::MissingAttributeError)
|
46
|
+
lambda { @found_restaurant.phone }.should raise_error(ActiveModel::MissingAttributeError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "update" do
|
51
|
+
it "should update a sti to mti class correctly with update_attributes" do
|
52
|
+
@restaurant.phone.should eq("123456789")
|
53
|
+
@restaurant.update_attributes(:phone => '987654321') #attribute from business
|
54
|
+
@restaurant.reload
|
55
|
+
@restaurant.phone.should eq("987654321")
|
56
|
+
@restaurant.business.phone.should eq("987654321")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should update a sti to mti class correctly with assignment" do
|
60
|
+
@restaurant.phone.should eq("123456789")
|
61
|
+
@restaurant.phone = '987654321' #attribute from business
|
62
|
+
@restaurant.save
|
63
|
+
@restaurant.reload
|
64
|
+
@restaurant.phone.should eq("987654321")
|
65
|
+
@restaurant.business.phone.should eq("987654321")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should update a sti to mti class correctly with Class.update" do
|
69
|
+
MexicanRestaurant.update(@restaurant.id, :name => 'Betos')
|
70
|
+
@restaurant.reload
|
71
|
+
@restaurant.name.should eq('Betos')
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should update a mti class correctly with Class.update_all" do
|
75
|
+
rtn = MexicanRestaurant.update_all(:name => 'Betos')
|
76
|
+
@restaurant.reload
|
77
|
+
rtn.should eq(1)
|
78
|
+
@restaurant.name.should eq('Betos')
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should not update a sti to mti class incorrectly with Class.update_all" do
|
82
|
+
rtn = MexicanRestaurant.update_all({:name => 'Betos'}, ["id = ?", @restaurant.id + 1]) #choose the wrong one
|
83
|
+
@restaurant.reload
|
84
|
+
rtn.should eq(0)
|
85
|
+
@restaurant.name.should eq('Chicos')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "delete" do
|
90
|
+
it "should destroy a sti to mti class correctly" do
|
91
|
+
@business = @restaurant.business
|
92
|
+
@restaurant.destroy
|
93
|
+
@restaurant.destroyed?.should eq(true)
|
94
|
+
MexicanRestaurant.find_by_id(@restaurant.id).should eq(nil)
|
95
|
+
Business.find_by_id(@business.id).should eq(nil)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should destroy_all sti to mti class correctly" do
|
99
|
+
MexicanRestaurant.count.should eq(1)
|
100
|
+
Business.count.should eq(1)
|
101
|
+
MexicanRestaurant.destroy_all
|
102
|
+
MexicanRestaurant.count.should eq(0)
|
103
|
+
Business.count.should eq(0)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should not destroy_all sti to mti class incorrectly" do
|
107
|
+
MexicanRestaurant.count.should eq(1)
|
108
|
+
Business.count.should eq(1)
|
109
|
+
MexicanRestaurant.destroy_all(:id => @restaurant.id + 1) #choose the wrong one
|
110
|
+
MexicanRestaurant.count.should eq(1)
|
111
|
+
Business.count.should eq(1)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should delete a sti to mti class correctly" do
|
115
|
+
@restaurant.delete
|
116
|
+
@restaurant.destroyed?.should eq(true)
|
117
|
+
MexicanRestaurant.find_by_id(@restaurant.id).should eq(nil)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should delete_all sti to mti class correctly" do
|
121
|
+
MexicanRestaurant.count.should eq(1)
|
122
|
+
Business.count.should eq(1)
|
123
|
+
rtn = MexicanRestaurant.delete_all
|
124
|
+
rtn.should eq(1)
|
125
|
+
MexicanRestaurant.count.should eq(0)
|
126
|
+
Business.count.should eq(0)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should not delete_all sti to mti class incorrectly" do
|
130
|
+
MexicanRestaurant.count.should eq(1)
|
131
|
+
Business.count.should eq(1)
|
132
|
+
rtn = MexicanRestaurant.delete_all(:id => @restaurant.id + 1) #choose the wrong one
|
133
|
+
rtn.should eq(0)
|
134
|
+
MexicanRestaurant.count.should eq(1)
|
135
|
+
Business.count.should eq(1)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
|
5
|
+
describe ActiveRecord::Base do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
exec_sql "truncate mechanics_core"
|
9
|
+
exec_sql "truncate garages"
|
10
|
+
|
11
|
+
@mechanic = Mechanic.new(
|
12
|
+
:name => 'Grady',
|
13
|
+
:privately_owned => true,
|
14
|
+
:max_wait_days => 5,
|
15
|
+
:specialty => 'foreign',
|
16
|
+
:email => 'gradyg@gmail.com'
|
17
|
+
)
|
18
|
+
@mechanic.valid?.should eq(true)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "simple validation" do
|
22
|
+
|
23
|
+
it "should be invalid when mti core class validation fails" do
|
24
|
+
@mechanic.name = nil
|
25
|
+
@mechanic.valid?.should eq(false)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "database validation" do
|
30
|
+
it "should save when mti core class database validation succeeds" do
|
31
|
+
@mechanic.new_record?.should eq(true)
|
32
|
+
@mechanic.save.should eq(true)
|
33
|
+
@mechanic.new_record?.should eq(false)
|
34
|
+
Mechanic.first.should eq(@mechanic)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be invalid when mti core class validation fails" do
|
38
|
+
dupe = @mechanic.clone
|
39
|
+
dupe.valid?.should eq(true)
|
40
|
+
@mechanic.save
|
41
|
+
dupe.valid?.should eq(false)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "mti validation" do
|
46
|
+
it "should be invalid when inherited validates_presence_of privately_owned validation fails" do
|
47
|
+
@mechanic.privately_owned = nil
|
48
|
+
@mechanic.valid?.should eq(false)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be invalid when inherited validates_numericality_of max_wait_days validation fails" do
|
52
|
+
@mechanic.max_wait_days = nil
|
53
|
+
@mechanic.valid?.should eq(false)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be invalid when inherited validates_length_of email validation fails" do
|
57
|
+
@mechanic.email = "r@r.cc"
|
58
|
+
@mechanic.valid?.should eq(false)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should be invalid when inherited validates_format_of email validation fails" do
|
62
|
+
@mechanic.email = "bad email"
|
63
|
+
@mechanic.valid?.should eq(false)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be invalid when inherited validates_uniqueness_of email validation fails" do
|
67
|
+
dupe = @mechanic.clone
|
68
|
+
dupe.valid?.should eq(true)
|
69
|
+
dupe.name = 'Some other name'
|
70
|
+
@mechanic.save
|
71
|
+
dupe.valid?.should eq(false)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should be invalid when inherited validates_inclusion_of specialty validation fails" do
|
75
|
+
@mechanic.specialty = "bad email"
|
76
|
+
@mechanic.valid?.should eq(false)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should be invalid when inherited validates_exclusion_of specialty validation fails" do
|
80
|
+
@mechanic.specialty = "something_crazy"
|
81
|
+
@mechanic.valid?.should eq(false)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: empty_eye
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- thegboat
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-03-10 23:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activerecord
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
version: 2.3.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: arel
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
- 0
|
50
|
+
version: 3.0.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: mysql2
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
description: Active Record MTI gem powered by database views
|
82
|
+
email:
|
83
|
+
- gradygriffin@gmail.com
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files: []
|
89
|
+
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- CHANGELOG.md
|
93
|
+
- Gemfile
|
94
|
+
- MIT-LICENSE
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- empty_eye.gemspec
|
98
|
+
- lib/empty_eye.rb
|
99
|
+
- lib/empty_eye/active_record/base.rb
|
100
|
+
- lib/empty_eye/active_record/connection_adapter.rb
|
101
|
+
- lib/empty_eye/active_record/schema_dumper.rb
|
102
|
+
- lib/empty_eye/associations/builder/shard_has_one.rb
|
103
|
+
- lib/empty_eye/associations/shard_association_scope.rb
|
104
|
+
- lib/empty_eye/associations/shard_has_one_association.rb
|
105
|
+
- lib/empty_eye/errors.rb
|
106
|
+
- lib/empty_eye/persistence.rb
|
107
|
+
- lib/empty_eye/primary_view_extension.rb
|
108
|
+
- lib/empty_eye/relation.rb
|
109
|
+
- lib/empty_eye/shard.rb
|
110
|
+
- lib/empty_eye/shard_association_reflection.rb
|
111
|
+
- lib/empty_eye/version.rb
|
112
|
+
- lib/empty_eye/view_extension.rb
|
113
|
+
- lib/empty_eye/view_extension_collection.rb
|
114
|
+
- spec/configuration_spec.rb
|
115
|
+
- spec/mti_crud_spec.rb
|
116
|
+
- spec/mti_to_sti_to_mti_crud_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/sti_to_mti_crud_spec.rb
|
119
|
+
- spec/validation_spec.rb
|
120
|
+
has_rdoc: true
|
121
|
+
homepage: ""
|
122
|
+
licenses: []
|
123
|
+
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
hash: 3
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
version: "0"
|
147
|
+
requirements: []
|
148
|
+
|
149
|
+
rubyforge_project: empty_eye
|
150
|
+
rubygems_version: 1.5.3
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: Active Record MTI gem
|
154
|
+
test_files:
|
155
|
+
- spec/configuration_spec.rb
|
156
|
+
- spec/mti_crud_spec.rb
|
157
|
+
- spec/mti_to_sti_to_mti_crud_spec.rb
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
- spec/sti_to_mti_crud_spec.rb
|
160
|
+
- spec/validation_spec.rb
|