enumerated_attribute 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/.gitignore +16 -0
  2. data/CHANGELOG.rdoc +49 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +555 -0
  5. data/Rakefile +104 -0
  6. data/init.rb +1 -0
  7. data/lib/enumerated_attribute.rb +24 -0
  8. data/lib/enumerated_attribute/attribute.rb +78 -0
  9. data/lib/enumerated_attribute/attribute/arguments.rb +48 -0
  10. data/lib/enumerated_attribute/attribute/attribute_descriptor.rb +51 -0
  11. data/lib/enumerated_attribute/attribute/class_methods.rb +42 -0
  12. data/lib/enumerated_attribute/attribute/instance_methods.rb +96 -0
  13. data/lib/enumerated_attribute/integrations.rb +33 -0
  14. data/lib/enumerated_attribute/integrations/active_record.rb +109 -0
  15. data/lib/enumerated_attribute/integrations/datamapper.rb +6 -0
  16. data/lib/enumerated_attribute/integrations/default.rb +25 -0
  17. data/lib/enumerated_attribute/integrations/object.rb +47 -0
  18. data/lib/enumerated_attribute/method_definition_dsl.rb +142 -0
  19. data/lib/enumerated_attribute/rails_helpers.rb +97 -0
  20. data/lib/jeffp-enumerated_attribute.rb +1 -0
  21. data/spec/active_record/active_record_spec.rb +363 -0
  22. data/spec/active_record/association_test_classes.rb +40 -0
  23. data/spec/active_record/associations_spec.rb +130 -0
  24. data/spec/active_record/cfg.rb +6 -0
  25. data/spec/active_record/inheritance_classes.rb +19 -0
  26. data/spec/active_record/inheritance_spec.rb +60 -0
  27. data/spec/active_record/race_car.rb +15 -0
  28. data/spec/active_record/single_table_inheritance_spec.rb +0 -0
  29. data/spec/active_record/sti_classes.rb +10 -0
  30. data/spec/active_record/sti_spec.rb +41 -0
  31. data/spec/active_record/test_in_memory.rb +71 -0
  32. data/spec/car.rb +67 -0
  33. data/spec/cfg.rb +8 -0
  34. data/spec/inheritance_classes.rb +16 -0
  35. data/spec/inheritance_spec.rb +80 -0
  36. data/spec/new_and_method_missing_spec.rb +73 -0
  37. data/spec/plural.rb +8 -0
  38. data/spec/poro_spec.rb +397 -0
  39. data/spec/rails/README +243 -0
  40. data/spec/rails/Rakefile +10 -0
  41. data/spec/rails/app/controllers/application_controller.rb +10 -0
  42. data/spec/rails/app/controllers/form_test_controller.rb +38 -0
  43. data/spec/rails/app/helpers/application_helper.rb +3 -0
  44. data/spec/rails/app/helpers/form_test_helper.rb +2 -0
  45. data/spec/rails/app/models/user.rb +9 -0
  46. data/spec/rails/app/views/form_test/form.html.erb +1 -0
  47. data/spec/rails/app/views/form_test/form_for.html.erb +10 -0
  48. data/spec/rails/app/views/form_test/form_tag.html.erb +9 -0
  49. data/spec/rails/app/views/form_test/index.html.erb +6 -0
  50. data/spec/rails/app/views/layouts/application.html.erb +11 -0
  51. data/spec/rails/config/boot.rb +110 -0
  52. data/spec/rails/config/database.yml +22 -0
  53. data/spec/rails/config/environment.rb +45 -0
  54. data/spec/rails/config/environments/development.rb +17 -0
  55. data/spec/rails/config/environments/production.rb +28 -0
  56. data/spec/rails/config/environments/test.rb +28 -0
  57. data/spec/rails/config/initializers/backtrace_silencers.rb +7 -0
  58. data/spec/rails/config/initializers/inflections.rb +10 -0
  59. data/spec/rails/config/initializers/mime_types.rb +5 -0
  60. data/spec/rails/config/initializers/new_rails_defaults.rb +19 -0
  61. data/spec/rails/config/initializers/session_store.rb +15 -0
  62. data/spec/rails/config/locales/en.yml +5 -0
  63. data/spec/rails/config/routes.rb +43 -0
  64. data/spec/rails/db/development.sqlite3 +0 -0
  65. data/spec/rails/db/migrate/20090804230221_create_sessions.rb +16 -0
  66. data/spec/rails/db/migrate/20090804230546_create_users.rb +21 -0
  67. data/spec/rails/db/schema.rb +35 -0
  68. data/spec/rails/db/test.sqlite3 +0 -0
  69. data/spec/rails/public/404.html +30 -0
  70. data/spec/rails/public/422.html +30 -0
  71. data/spec/rails/public/500.html +30 -0
  72. data/spec/rails/public/favicon.ico +0 -0
  73. data/spec/rails/public/images/rails.png +0 -0
  74. data/spec/rails/public/index.html +275 -0
  75. data/spec/rails/public/javascripts/application.js +2 -0
  76. data/spec/rails/public/javascripts/controls.js +963 -0
  77. data/spec/rails/public/javascripts/dragdrop.js +973 -0
  78. data/spec/rails/public/javascripts/effects.js +1128 -0
  79. data/spec/rails/public/javascripts/prototype.js +4320 -0
  80. data/spec/rails/public/robots.txt +5 -0
  81. data/spec/rails/public/stylesheets/scaffold.css +54 -0
  82. data/spec/rails/script/about +4 -0
  83. data/spec/rails/script/autospec +6 -0
  84. data/spec/rails/script/console +3 -0
  85. data/spec/rails/script/dbconsole +3 -0
  86. data/spec/rails/script/destroy +3 -0
  87. data/spec/rails/script/generate +3 -0
  88. data/spec/rails/script/performance/benchmarker +3 -0
  89. data/spec/rails/script/performance/profiler +3 -0
  90. data/spec/rails/script/plugin +3 -0
  91. data/spec/rails/script/runner +3 -0
  92. data/spec/rails/script/server +3 -0
  93. data/spec/rails/script/spec +10 -0
  94. data/spec/rails/script/spec_server +9 -0
  95. data/spec/rails/spec/controllers/form_test_controller_spec.rb +41 -0
  96. data/spec/rails/spec/integrations/enum_select_spec.rb +75 -0
  97. data/spec/rails/spec/matchers.rb +12 -0
  98. data/spec/rails/spec/rcov.opts +2 -0
  99. data/spec/rails/spec/spec.opts +4 -0
  100. data/spec/rails/spec/spec_helper.rb +40 -0
  101. data/spec/rails/spec/views/form_test/form.html.erb_spec.rb +12 -0
  102. data/spec/rails/spec/views/form_test/form_for.html.erb_spec.rb +12 -0
  103. data/spec/rails/spec/views/form_test/form_tag.html.erb_spec.rb +12 -0
  104. data/spec/rcov.opts +2 -0
  105. data/spec/spec.opts +4 -0
  106. data/spec/tractor.rb +48 -0
  107. metadata +182 -0
@@ -0,0 +1 @@
1
+ require 'enumerated_attribute'
@@ -0,0 +1,363 @@
1
+ require 'test_in_memory'
2
+ require 'active_record'
3
+ require 'enumerated_attribute'
4
+ require 'race_car'
5
+
6
+ describe "RaceCar" do
7
+
8
+ it "should have default labels for :gear attribute" do
9
+ labels_hash = {:reverse=>'Reverse', :neutral=>'Neutral', :first=>'First', :second=>'Second', :over_drive=>'Over drive'}
10
+ labels = ['Reverse', 'Neutral', 'First', 'Second', 'Over drive']
11
+ select_options = [['Reverse', 'reverse'], ['Neutral', 'neutral'], ['First', 'first'], ['Second', 'second'], ['Over drive', 'over_drive']]
12
+ r=RaceCar.new
13
+ r.gears.labels.should == labels
14
+ labels_hash.each do |k,v|
15
+ r.gears.label(k).should == v
16
+ end
17
+ r.gears.hash.should == labels_hash
18
+ r.gears.select_options.should == select_options
19
+ end
20
+
21
+ it "should retrieve :gear enums through enums method" do
22
+ r=RaceCar.new
23
+ r.enums(:gear).should == r.gears
24
+ end
25
+
26
+ it "should return a Symbol type from reader methods" do
27
+ r=RaceCar.new
28
+ r.gear.should be_an_instance_of(Symbol)
29
+ end
30
+
31
+ it "should increment and decrement :gear attribute correctly" do
32
+ r=RaceCar.new
33
+ r.gear = :neutral
34
+ r.gear_next.should == :first
35
+ r.gear_next.should == :second
36
+ r.gear_next.should == :over_drive
37
+ r.gear_next.should == :reverse
38
+ r.gear_next.should == :neutral
39
+ r.gear.should == :neutral
40
+ r.gear_previous.should == :reverse
41
+ r.gear_previous.should == :over_drive
42
+ r.gear_previous.should == :second
43
+ r.gear_previous
44
+ r.gear.should == :first
45
+ end
46
+
47
+ it "should have dynamic predicate methods for :gear attribute" do
48
+ r=RaceCar.new
49
+ r.gear = :second
50
+ r.gear_is_in_second?.should be_true
51
+ r.gear_not_in_second?.should be_false
52
+ r.gear_is_nil?.should be_false
53
+ r.gear_is_not_nil?.should be_true
54
+ end
55
+
56
+ it "should have working dynamic predicate methods on retrieved objects" do
57
+ r=RaceCar.new
58
+ r.gear = :second
59
+ r.save!
60
+
61
+ s=RaceCar.find r.id
62
+ s.should_not be_nil
63
+ s.gear_is_in_second?.should be_true
64
+ s.gear_is_not_in_second?.should be_false
65
+ s.gear_is_nil?.should be_false
66
+ s.gear_is_not_nil?.should be_true
67
+ end
68
+
69
+ it "should find record by enumerated column :gear attributes" do
70
+ r=RaceCar.new
71
+ r.gear = :second
72
+ r.name = 'special'
73
+ r.save!
74
+
75
+ s=RaceCar.find_by_gear_and_name(:second, 'special')
76
+ s.should_not be_nil
77
+ s.id.should == r.id
78
+ end
79
+
80
+ it "should initialize according to enumerated attribute definitions" do
81
+ r = RaceCar.new
82
+ r.gear.should == :neutral
83
+ r.choke.should == :none
84
+ end
85
+
86
+ it "should create new instance using block" do
87
+ r = RaceCar.new do |r|
88
+ r.gear = :first
89
+ r.choke = :medium
90
+ r.lights = 'on'
91
+ end
92
+ r.gear.should == :first
93
+ r.lights.should == 'on'
94
+ r.choke.should == :medium
95
+ end
96
+
97
+ it "should initialize using parameter hash with symbol keys" do
98
+ r=RaceCar.new(:name=>'FastFurious', :gear=>:second, :lights=>'on', :choke=>:medium)
99
+ r.gear.should == :second
100
+ r.lights.should == 'on'
101
+ r.choke.should == :medium
102
+ end
103
+
104
+ it "should initialize using parameter hash with string keys" do
105
+ r=RaceCar.new({'name'=>'FastFurious', 'gear'=>'second', 'lights'=>'on', 'choke'=>'medium'})
106
+ r.gear.should == :second
107
+ r.lights.should == 'on'
108
+ r.choke.should == :medium
109
+ end
110
+
111
+
112
+ it "should convert non-column enumerated attributes from string to symbols" do
113
+ r=RaceCar.new
114
+ r.choke = 'medium'
115
+ r.choke.should == :medium
116
+ r.save!
117
+ end
118
+
119
+ it "should convert enumerated column attributes from string to symbols" do
120
+ r=RaceCar.new
121
+ r.gear = 'second'
122
+ r.gear.should == :second
123
+ r.save!
124
+
125
+ s=RaceCar.find r.id
126
+ s.gear.should == :second
127
+ end
128
+
129
+ it "should not convert non-enumerated column attributes from string to symbols" do
130
+ r=RaceCar.new
131
+ r.lights = 'off'
132
+ r.lights.should == 'off'
133
+ r.save!
134
+
135
+ s=RaceCar.find r.id
136
+ s.lights.should == 'off'
137
+ end
138
+
139
+ it "should raise InvalidEnumeration when parametrically initialized with :gear=>:drive" do
140
+ r=RaceCar.new
141
+ lambda{ r.gear= :drive}.should raise_error(EnumeratedAttribute::InvalidEnumeration)
142
+ end
143
+
144
+ it "should raise InvalidEnumeration when parametrically initialized with :choke=>:all" do
145
+ r=RaceCar.new
146
+ lambda{ r.choke= :all}.should raise_error(EnumeratedAttribute::InvalidEnumeration)
147
+ end
148
+
149
+ it "should return non-column enumerated attributes from [] method" do
150
+ r = RaceCar.new
151
+ r[:choke].should == :none
152
+ end
153
+
154
+ it "should return enumerated column attributes from [] method" do
155
+ r=RaceCar.new
156
+ r.gear = :neutral
157
+ r[:gear].should == :neutral
158
+ end
159
+
160
+ it "should set non-column enumerated attributes with []= method" do
161
+ r=RaceCar.new
162
+ r[:choke] = :medium
163
+ r.choke.should == :medium
164
+ end
165
+
166
+ it "should set enumerated column attriubtes with []= method" do
167
+ r=RaceCar.new
168
+ r[:gear] = :second
169
+ r.gear.should == :second
170
+ end
171
+
172
+ it "should raise InvalidEnumeration when setting enumerated column attribute with []= method" do
173
+ r=RaceCar.new
174
+ lambda{ r[:gear]= :drive }.should raise_error(EnumeratedAttribute::InvalidEnumeration)
175
+ end
176
+
177
+ it "should set and retrieve string for non-enumerated column attributes with []=" do
178
+ r=RaceCar.new
179
+ r[:lights] = 'on'
180
+ r.lights.should == 'on'
181
+ r[:lights].should == 'on'
182
+ end
183
+
184
+ it "should set and retrieve symbol for non-enumerated column attributes with []=" do
185
+ r=RaceCar.new
186
+ r[:lights] = :on
187
+ r.lights.should == :on
188
+ r[:lights].should == :on
189
+ end
190
+
191
+ it "should raise InvalidEnumeration for invalid enum passed to attributes=" do
192
+ r=RaceCar.new
193
+ lambda { r.attributes = {:lights=>'off', :gear =>:drive} }.should raise_error(EnumeratedAttribute::InvalidEnumeration)
194
+ end
195
+
196
+ =begin
197
+ #do not write symbols to enumerated column attributes using write_attribute
198
+ #do not user read_attribute to read an enumerated column attribute
199
+ it "should write enumeration with write_attribute" do
200
+ r=RaceCar.new
201
+ r.write_attribute(:gear, :first)
202
+ r.gear.should == :first
203
+ r.save!
204
+
205
+ s=RaceCar.find r.id
206
+ s.gear.should == :first
207
+ s.write_attribute(:gear, :second)
208
+ s.save!
209
+
210
+ t=RaceCar.find s.id
211
+ t.gear.should == :second
212
+ end
213
+
214
+ it "should raise error when setting enumerated column attribute to invalid enum using write_attribute" do
215
+ r=RaceCar.new
216
+ lambda { r.write_attribute(:gear, :yo) }.should raise_error
217
+ end
218
+ =end
219
+
220
+ it "should retrieve symbols for enumerations from ActiveRecord :attributes method" do
221
+ r=RaceCar.new
222
+ r.gear = :second
223
+ r.choke = :medium
224
+ r.lights = 'on'
225
+ r.save!
226
+
227
+ s = RaceCar.find(r.id)
228
+ s.attributes['gear'].should == :second
229
+ s.attributes['lights'].should == 'on'
230
+ end
231
+
232
+ it "should update_attribute for enumerated column attribute" do
233
+ r=RaceCar.new
234
+ r.gear = :first
235
+ r.save!
236
+ r.update_attribute(:gear, :second)
237
+ r.gear.should == :second
238
+
239
+ s=RaceCar.find r.id
240
+ s.gear.should == :second
241
+ end
242
+
243
+ it "should update_attribute for non-enumerated column attribute" do
244
+ r=RaceCar.new
245
+ r.lights = 'on'
246
+ r.save!
247
+ r.update_attribute(:lights, 'off')
248
+ r.lights.should == 'off'
249
+
250
+ s=RaceCar.find r.id
251
+ s.lights.should == 'off'
252
+ end
253
+
254
+ it "should update_attributes for both non- and enumerated column attributes" do
255
+ r=RaceCar.new
256
+ r.gear = :first
257
+ r.lights = 'off'
258
+ r.save!
259
+ r.update_attributes({:gear=>:second, :lights=>'on'})
260
+ s=RaceCar.find r.id
261
+ s.gear.should == :second
262
+ s.lights.should == 'on'
263
+ s.update_attributes({:gear=>'over_drive', :lights=>'off'})
264
+ t=RaceCar.find s.id
265
+ t.gear.should == :over_drive
266
+ t.lights.should == 'off'
267
+ end
268
+
269
+ it "should provide symbol values for enumerated column attributes from the :attributes method" do
270
+ r=RaceCar.new
271
+ r.lights = 'on'
272
+ r.save!
273
+
274
+ s=RaceCar.find r.id
275
+ s.attributes['gear'].should == :neutral
276
+ end
277
+
278
+ it "should provide normal values for non-enumerated column attributes from the :attributes method" do
279
+ r=RaceCar.new
280
+ r.lights = 'on'
281
+ r.save!
282
+
283
+ s=RaceCar.find r.id
284
+ s.attributes['lights'].should == 'on'
285
+ end
286
+
287
+ it "should raise InvalidEnumeration when setting invalid enumertion value with :attributes= method" do
288
+ r=RaceCar.new
289
+ lambda { r.attributes = {:gear=>:yo, :lights=>'on'} }.should raise_error(EnumeratedAttribute::InvalidEnumeration)
290
+ end
291
+
292
+ it "should not set init value for enumerated column attribute saved as nil" do
293
+ r=RaceCar.new
294
+ r.gear = nil
295
+ r.lights = 'on'
296
+ r.save!
297
+
298
+ s=RaceCar.find r.id
299
+ s.gear.should == nil
300
+ s.lights.should == 'on'
301
+ end
302
+
303
+ it "should not set init value for enumerated column attributes saved as value" do
304
+ r=RaceCar.new
305
+ r.gear = :second
306
+ r.lights = 'all'
307
+ r.save!
308
+
309
+ s=RaceCar.find r.id
310
+ s.gear.should == :second
311
+ s.lights.should == 'all'
312
+ end
313
+
314
+ it "should save and retrieve its name" do
315
+ r = RaceCar.new
316
+ r.name= 'Green Meanie'
317
+ r.save!
318
+
319
+ s = RaceCar.find r.id
320
+ s.should_not be_nil
321
+ s.name.should == 'Green Meanie'
322
+ end
323
+
324
+ it "should save and retrieve symbols for enumerated column attribute" do
325
+ r = RaceCar.new
326
+ r.gear = :over_drive
327
+ r.save!
328
+
329
+ s = RaceCar.find r.id
330
+ #s.should_not be_nil
331
+ s.gear.should == :over_drive
332
+ end
333
+
334
+ it "should not save values for non-column enumerated attributes" do
335
+ r=RaceCar.new
336
+ r.choke = :medium
337
+ r.save!
338
+
339
+ s=RaceCar.find r.id
340
+ s.choke.should == :none
341
+ end
342
+
343
+ it "should save string and retrieve string for non-enumerated column attributes" do
344
+ r =RaceCar.new
345
+ r.lights = 'on'
346
+ r.save!
347
+
348
+ s = RaceCar.find r.id
349
+ s.lights.should == 'on'
350
+ s[:lights].should == 'on'
351
+ end
352
+
353
+ it "should save symbol and retrieve string for non-enumerated column attributes" do
354
+ r =RaceCar.new
355
+ r.lights = :off
356
+ r.save!
357
+
358
+ s = RaceCar.find r.id
359
+ s.lights.should == "--- :off\n"
360
+ s[:lights].should == "--- :off\n"
361
+ end
362
+
363
+ end
@@ -0,0 +1,40 @@
1
+
2
+ class Company < ActiveRecord::Base
3
+ has_one :license
4
+ has_many :employees
5
+ has_many :contract_workers
6
+ has_many :contractors, :through=>:contract_workers
7
+ enum_attr :status, %w(s_corp c_corp llc), :nil=>true
8
+ end
9
+ class Employee < ActiveRecord::Base
10
+ belongs_to :company
11
+ enum_attr :status, %w(full_time part_time suspended), :nil=>true
12
+ end
13
+ class License < ActiveRecord::Base
14
+ belongs_to :company
15
+ enum_attr :status, %w(^current expired)
16
+ end
17
+ class Contractor < ActiveRecord::Base
18
+ has_many :contract_workers
19
+ has_many :companies, :through=>:contract_workers
20
+ enum_attr :status, %w(^available unavailable)
21
+ end
22
+ class ContractWorker < ActiveRecord::Base
23
+ belongs_to :company
24
+ belongs_to :contractor
25
+ enum_attr :status, %w(unfresh ^unfresh) #i don't know what to put here
26
+ end
27
+
28
+ #polymorphic
29
+ class Comment < ActiveRecord::Base
30
+ belongs_to :document, :polymorphic=>true
31
+ enum_attr :status, %w(^unflagged flagged)
32
+ end
33
+ class Article < ActiveRecord::Base
34
+ has_one :comment, :as=>:document
35
+ enum_attr :status, %w(^unreviewed accepted)
36
+ end
37
+ class Image < ActiveRecord::Base
38
+ has_one :comment, :as=>:document
39
+ enum_attr :status, %w(^unreviewed accepted)
40
+ end
@@ -0,0 +1,130 @@
1
+ require 'test_in_memory'
2
+ require 'enumerated_attribute'
3
+ require 'active_record'
4
+ require 'association_test_classes'
5
+
6
+ module TestVariables
7
+ def company_name; 'Company A'; end
8
+ end
9
+
10
+ describe "Polymorphic associations" do
11
+ include TestVariables
12
+
13
+ it "should retrieve enum'ed attribute for articles and images of a comment" do
14
+ c1 = Comment.new(:comment=>'i like it')
15
+ c1.document = Article.create!(:name=>'Birds of a Feather', :status=>:accepted)
16
+ c1.save!
17
+ c1.status.should == :unflagged
18
+
19
+ c2 = Comment.new(:comment=>'i hate it', :status => :flagged)
20
+ c2.document = Image.create!(:name=>'Martian Landscape', :status=>:unreviewed)
21
+ c2.save!
22
+ c2.status.should == :flagged
23
+
24
+ Comment.find(c1.id).document.status.should == :accepted
25
+ Comment.find(c2.id).document.status.should == :unreviewed
26
+
27
+ end
28
+
29
+ it "should retrieve enum'ed attribute for comments on articles and images" do
30
+ a = Article.create!(:name=>'Swimming with Whales', :status=>:accepted)
31
+ a.create_comment(:comment=>'i like it', :status=>:unflagged)
32
+ a.save!
33
+
34
+ i = Image.create!(:name=>'Mountain Climbing', :status=>:unreviewed)
35
+ i.comment = Comment.create!(:comment=>'i do not like it', :status=>:flagged)
36
+ i.save!
37
+
38
+ Image.find(i.id).comment.status.should == :flagged
39
+ Article.find(a.id).comment.status.should == :unflagged
40
+
41
+ end
42
+
43
+ end
44
+
45
+ describe "Basic Associations" do
46
+ include TestVariables
47
+
48
+ it "should retrieve enum'ed status for its license" do
49
+ c = Company.new(:status=>:llc, :name=>company_name)
50
+ c.save!
51
+ c.create_license(:status=>:current)
52
+
53
+ r = Company.find(c.id)
54
+ lic = r.license
55
+ r.status.should == :llc
56
+ lic.status.should == :current
57
+ end
58
+
59
+ it "should retrieve enum'ed status for multiple employees" do
60
+ c=Company.new(:status=>:llc, :name=>company_name)
61
+ c.save!
62
+ c.employees.create!(:status=>:full_time, :name=>'edward')
63
+ c.employees.create!(:status=>:suspended, :name=>'tina')
64
+
65
+ r=Company.find(c.id)
66
+ r.employees.find_by_name('edward').status.should == :full_time
67
+ r.employees.find_by_name('tina').status.should == :suspended
68
+ Employee.delete_all
69
+ end
70
+
71
+ it "should retrieve enum'ed status for multiple contractors" do
72
+ c=Company.new(:status=>:llc, :name=>company_name)
73
+ c.save!
74
+ c1 = Contractor.new(:status=>:available, :name=>'john')
75
+ c2 = Contractor.new(:status=>:unavailable, :name=>'sally')
76
+ c.contractors << c1
77
+ c.contractors << c2
78
+
79
+ r=Company.find(c.id)
80
+ r.contractors.find_by_name('sally').status.should == :unavailable
81
+ r.contractors.find_by_name('john').status.should == :available
82
+ Contractor.delete_all
83
+ ContractWorker.delete_all
84
+ end
85
+ end
86
+
87
+ describe "License" do
88
+ include TestVariables
89
+ it "should retrieve the status for the company" do
90
+ Company.delete_all
91
+ License.delete_all
92
+ lic = License.create!(:status=>:expired)
93
+ lic.company = Company.create!(:name=>company_name, :status=>:llc)
94
+ lic.save!
95
+
96
+ License.find(lic.id).company.status.should == :llc
97
+ end
98
+ end
99
+
100
+ describe "Contractor" do
101
+ include TestVariables
102
+ it "should retrieve enum'ed status from multiple companies" do
103
+ Company.delete_all
104
+ Contractor.delete_all
105
+ ContractWorker.delete_all
106
+ c = Contractor.create!(:name=>'jack', :status=>:available)
107
+
108
+ c1 = Company.create!(:name=>company_name, :status=>:s_corp)
109
+ c2 = Company.create!(:name=>'other company', :status=>:llc)
110
+ c.companies << c1 << c2
111
+
112
+ j = Contractor.find(c.id)
113
+ j.companies.find_by_name('other company').status.should == :llc
114
+ j.companies.find_by_name(company_name).status.should == :s_corp
115
+ end
116
+ end
117
+
118
+ describe "Employee" do
119
+ include TestVariables
120
+ it "should retrieve enum'ed status from the company" do
121
+ Company.delete_all
122
+ Employee.delete_all
123
+ e = Employee.create!(:name=>'juanita', :status=>:part_time)
124
+ e.company = Company.create!(:name=>company_name, :status=>:c_corp)
125
+ e.save!
126
+
127
+ emp = Employee.find(e.id)
128
+ emp.company.status.should == :c_corp
129
+ end
130
+ end