Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Minor changes to allow for full Ruby 1.9 compatibility

  • Loading branch information...
commit 332883a9a025a5d6d0c5f61ef0f363d6b244d1b6 1 parent 7b64f01
Jeremy Evans authored July 24, 2008
2  CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 === HEAD
2 2
 
  3
+* Minor changes to allow for full Ruby 1.9 compatibility (jeremyevans)
  4
+
3 5
 * Make Database#disconnect work for the ADO adapter (spicyj)
4 6
 
5 7
 * Don't raise an exception in the ADO adapter if the dataset contains no records (nusco)
2  Rakefile
@@ -130,7 +130,7 @@ end
130 130
 %w'postgres sqlite mysql informix oracle ado'.each do |adapter|
131 131
   desc "Run #{adapter} specs without coverage"
132 132
   Spec::Rake::SpecTask.new("spec_#{adapter}") do |t|
133  
-    t.spec_files = "spec/adapters/#{adapter}_spec.rb"
  133
+    t.spec_files = ["spec/adapters/#{adapter}_spec.rb"]
134 134
     t.spec_opts  = spec_opts.call
135 135
   end
136 136
 end
6  lib/sequel_core/adapters/sqlite.rb
@@ -92,7 +92,7 @@ def auto_vacuum
92 92
       end
93 93
       
94 94
       def auto_vacuum=(value)
95  
-        value = AUTO_VACUUM.index(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
  95
+        value = AUTO_VACUUM.key(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
96 96
         pragma_set(:auto_vacuum, value)
97 97
       end
98 98
       
@@ -103,7 +103,7 @@ def synchronous
103 103
       end
104 104
       
105 105
       def synchronous=(value)
106  
-        value = SYNCHRONOUS.index(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
  106
+        value = SYNCHRONOUS.key(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
107 107
         pragma_set(:synchronous, value)
108 108
       end
109 109
       
@@ -114,7 +114,7 @@ def temp_store
114 114
       end
115 115
       
116 116
       def temp_store=(value)
117  
-        value = TEMP_STORE.index(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
  117
+        value = TEMP_STORE.key(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
118 118
         pragma_set(:temp_store, value)
119 119
       end
120 120
       
6  lib/sequel_core/core_ext.rb
... ...
@@ -1,3 +1,9 @@
  1
+if RUBY_VERSION < '1.9.0'
  2
+  class Hash
  3
+    alias key index
  4
+  end
  5
+end
  6
+
1 7
 class Array
2 8
   # True if the array is not empty and all of its elements are
3 9
   # arrays of size 2.  This is used to determine if the array
11  lib/sequel_core/sql.rb
@@ -762,6 +762,15 @@ def to_s(ds)
762 762
       end
763 763
     end
764 764
 
  765
+    if RUBY_VERSION >= '1.9.0'
  766
+      class VirtualRow < BasicObject
  767
+      end
  768
+    else
  769
+      class VirtualRow
  770
+        (instance_methods - %w"__id__ __send__ instance_eval == equal?").each{|m| undef_method(m)}
  771
+      end
  772
+    end
  773
+
765 774
     # An instance of this class is yielded to the block supplied to filter.
766 775
     # Useful if another library also defines the operator methods that
767 776
     # Sequel defines for symbols.
@@ -773,8 +782,6 @@ def to_s(ds)
773 782
     #   ds.filter{|r| r.table__column + 1 < 2} # SELECT * FROM t WHERE ((table.column + 1) < 2)
774 783
     #   ds.filter{|r| r.is_active(1, 'arg2')} # SELECT * FROM t WHERE is_active(1, 'arg2')
775 784
     class VirtualRow
776  
-      (instance_methods - %w"__id__ __send__").each{|m| undef_method(m)}
777  
-
778 785
       # Can return Identifiers, QualifiedIdentifiers, or Functions:
779 786
       #
780 787
       # * Function - returned if any arguments are supplied, using the method name
4  lib/sequel_model/association_reflection.rb
@@ -70,14 +70,14 @@ def dataset_need_primary_key?
70 70
 
71 71
         # Name symbol for default join table
72 72
         def default_join_table
73  
-          ([self[:class_name].demodulize, self[:model].name.demodulize]. \
  73
+          ([self[:class_name].demodulize, self[:model].name.to_s.demodulize]. \
74 74
             map{|i| i.pluralize.underscore}.sort.join('_')).to_sym
75 75
         end
76 76
       
77 77
         # Default foreign key name symbol for key in associated table that points to
78 78
         # current table's primary key.
79 79
         def default_left_key
80  
-          :"#{self[:model].name.demodulize.underscore}_id"
  80
+          :"#{self[:model].name.to_s.demodulize.underscore}_id"
81 81
         end
82 82
 
83 83
         # Default foreign key name symbol for foreign key in current model's table that points to
10  lib/sequel_model/base.rb
@@ -195,7 +195,7 @@ def self.find_or_create(cond)
195 195
     # from the parent class.
196 196
     def self.inherited(subclass)
197 197
       sup_class = subclass.superclass
198  
-      ivs = subclass.instance_variables
  198
+      ivs = subclass.instance_variables.collect{|x| x.to_s}
199 199
       INHERITED_INSTANCE_VARIABLES.each do |iv, dup|
200 200
         next if ivs.include?(iv.to_s)
201 201
         sup_class_value = sup_class.instance_variable_get(iv)
@@ -205,9 +205,9 @@ def self.inherited(subclass)
205 205
       unless ivs.include?("@dataset")
206 206
         begin
207 207
           if sup_class == Model
208  
-            subclass.set_dataset(Model.db[subclass.implicit_table_name]) unless subclass.name.empty?
  208
+            subclass.set_dataset(Model.db[subclass.implicit_table_name]) unless subclass.name.blank?
209 209
           elsif ds = sup_class.instance_variable_get(:@dataset)
210  
-            subclass.set_dataset(sup_class.sti_key ? sup_class.sti_dataset.filter(sup_class.sti_key=>subclass.name) : ds.clone)
  210
+            subclass.set_dataset(sup_class.sti_key ? sup_class.sti_dataset.filter(sup_class.sti_key=>subclass.name.to_s) : ds.clone)
211 211
           end
212 212
         rescue
213 213
           nil
@@ -380,7 +380,7 @@ def self.set_sti_key(key)
380 380
       @sti_key = key
381 381
       @sti_dataset = dataset
382 382
       dataset.set_model(key, Hash.new{|h,k| h[k] = (k.constantize rescue m)})
383  
-      before_create(:set_sti_key){send("#{key}=", model.name)}
  383
+      before_create(:set_sti_key){send("#{key}=", model.name.to_s)}
384 384
     end
385 385
 
386 386
     # Returns the columns as a list of frozen strings instead
@@ -427,7 +427,7 @@ def self.unrestrict_primary_key
427 427
     # Create the column accessors
428 428
     def self.def_column_accessor(*columns) # :nodoc:
429 429
       columns.each do |column|
430  
-        im = instance_methods
  430
+        im = instance_methods.collect{|x| x.to_s}
431 431
         meth = "#{column}="
432 432
          define_method(column){self[column]} unless im.include?(column.to_s)
433 433
         unless im.include?(meth)
2  lib/sequel_model/plugins.rb
@@ -34,7 +34,7 @@ def self.is(plugin, *args)
34 34
       end
35 35
       if m.const_defined?("DatasetMethods")
36 36
         dataset.meta_def(:"#{plugin}_opts") {args.first}
37  
-        dataset.metaclass.send(:include, m::DatasetMethods)
  37
+        dataset.extend(m::DatasetMethods)
38 38
         def_dataset_method(*m::DatasetMethods.instance_methods)
39 39
       end
40 40
     end
2  lib/sequel_model/record.rb
@@ -510,7 +510,7 @@ def setter_methods(only, except)
510 510
       if only
511 511
         only.map{|x| "#{x}="}
512 512
       else
513  
-        meths = methods.grep(/=\z/) - RESTRICTED_SETTER_METHODS
  513
+        meths = methods.collect{|x| x.to_s}.grep(/=\z/) - RESTRICTED_SETTER_METHODS
514 514
         meths -= Array(primary_key).map{|x| "#{x}="} if primary_key && model.restrict_primary_key?
515 515
         meths -= except.map{|x| "#{x}="} if except
516 516
         meths
28  spec/integration/eager_loader_test.rb
@@ -2,7 +2,7 @@
2 2
 
3 3
 describe "Eagerly loading a tree structure" do
4 4
   before do
5  
-    class Node < Sequel::Model
  5
+    class ::Node < Sequel::Model
6 6
       set_schema do
7 7
         primary_key :id
8 8
         foreign_key :parent_id, :nodes
@@ -137,7 +137,7 @@ class Node < Sequel::Model
137 137
 
138 138
 describe "Association Extensions" do
139 139
   before do
140  
-    module FindOrCreate
  140
+    module ::FindOrCreate
141 141
       def find_or_create(vals)
142 142
         # Exploits the fact that Sequel filters are ruby objects that
143 143
         # can be introspected.
@@ -146,7 +146,7 @@ def find_or_create(vals)
146 146
           @opts[:models][nil].create(vals.merge(:author_id=>author_id))
147 147
       end 
148 148
     end
149  
-    class Author < Sequel::Model
  149
+    class ::Author < Sequel::Model
150 150
       set_schema do
151 151
         primary_key :id
152 152
       end
@@ -160,7 +160,7 @@ class Author < Sequel::Model
160 160
         ds  
161 161
       end)
162 162
     end
163  
-    class Authorship < Sequel::Model
  163
+    class ::Authorship < Sequel::Model
164 164
       set_schema do
165 165
         primary_key :id
166 166
         foreign_key :author_id, :authors
@@ -212,7 +212,7 @@ class Authorship < Sequel::Model
212 212
 
213 213
 describe "has_many :through has_many and has_one :through belongs_to" do
214 214
   before do
215  
-    class Firm < Sequel::Model
  215
+    class ::Firm < Sequel::Model
216 216
       set_schema do
217 217
         primary_key :id
218 218
       end
@@ -237,7 +237,7 @@ class Firm < Sequel::Model
237 237
         end)
238 238
     end
239 239
 
240  
-    class Client < Sequel::Model
  240
+    class ::Client < Sequel::Model
241 241
       set_schema do
242 242
         primary_key :id
243 243
         foreign_key :firm_id, :firms
@@ -247,7 +247,7 @@ class Client < Sequel::Model
247 247
       one_to_many :invoices
248 248
     end
249 249
 
250  
-    class Invoice < Sequel::Model
  250
+    class ::Invoice < Sequel::Model
251 251
       set_schema do
252 252
         primary_key :id
253 253
         foreign_key :client_id, :clients
@@ -375,7 +375,7 @@ class Invoice < Sequel::Model
375 375
 
376 376
 describe "Polymorphic Associations" do
377 377
   before do
378  
-    class Asset < Sequel::Model
  378
+    class ::Asset < Sequel::Model
379 379
       set_schema do
380 380
         primary_key :id
381 381
         integer :attachable_id
@@ -411,7 +411,7 @@ def _attachable=(attachable)
411 411
       end 
412 412
     end 
413 413
   
414  
-    class Post < Sequel::Model
  414
+    class ::Post < Sequel::Model
415 415
       set_schema do
416 416
         primary_key :id
417 417
       end
@@ -438,7 +438,7 @@ def _remove_all_assets
438 438
       end
439 439
     end 
440 440
   
441  
-    class Note < Sequel::Model
  441
+    class ::Note < Sequel::Model
442 442
       set_schema do
443 443
         primary_key :id
444 444
       end
@@ -550,7 +550,7 @@ def _remove_all_assets
550 550
 
551 551
 describe "many_to_one/one_to_many not referencing primary key" do
552 552
   before do
553  
-    class Client < Sequel::Model
  553
+    class ::Client < Sequel::Model
554 554
       set_schema do
555 555
         primary_key :id
556 556
         text :name
@@ -585,7 +585,7 @@ def _remove_all_invoices
585 585
       end
586 586
     end 
587 587
   
588  
-    class Invoice < Sequel::Model
  588
+    class ::Invoice < Sequel::Model
589 589
       set_schema do
590 590
         primary_key :id
591 591
         text :client_name
@@ -671,7 +671,7 @@ def _client=(client)
671 671
     @client2.invoices.should == []
672 672
     sqls_should_be("SELECT * FROM invoices WHERE (client_name = 'Y')")
673 673
     @client2.add_invoice(@invoice1)
674  
-    sqls_should_be("UPDATE invoices SET client_name = 'Y', id = 1 WHERE (id = 1)")
  674
+    sqls_should_be(/UPDATE invoices SET (client_name = 'Y'|id = 1), (client_name = 'Y'|id = 1) WHERE \(id = 1\)/)
675 675
     @client2.invoices.should == [@invoice1]
676 676
     @invoice1.client_name.should == 'Y'
677 677
     @invoice1.client = nil
@@ -684,7 +684,7 @@ def _client=(client)
684 684
     sqls_should_be("SELECT * FROM invoices WHERE (client_name = 'X')")
685 685
     invs.should == [@invoice1, @invoice2]
686 686
     @client1.remove_invoice(@invoice1)
687  
-    sqls_should_be("UPDATE invoices SET client_name = NULL, id = 1 WHERE (id = 1)")
  687
+    sqls_should_be(/UPDATE invoices SET (client_name = NULL|id = 1), (client_name = NULL|id = 1) WHERE \(id = 1\)/)
688 688
     @client1.invoices.should == [@invoice2]
689 689
     @invoice1.client_name.should == nil
690 690
     @invoice1.client.should == nil
6  spec/sequel_core/database_spec.rb
@@ -645,11 +645,11 @@ def disconnect
645 645
 context "A broken adapter (lib is there but the class is not)" do
646 646
   setup do
647 647
     @fn = File.join(File.dirname(__FILE__), '../../lib/sequel_core/adapters/blah.rb')
648  
-    FileUtils.touch(@fn)
  648
+    File.open(@fn,'a'){}
649 649
   end
650 650
   
651 651
   teardown do
652  
-    FileUtils.rm(@fn)
  652
+    File.delete(@fn)
653 653
   end
654 654
   
655 655
   specify "should raise an error" do
@@ -916,7 +916,7 @@ class EEE < Sequel::Database
916 916
   end
917 917
   
918 918
   teardown do
919  
-    FileUtils.rm(@fn)
  919
+    File.delete(@fn)
920 920
   end
921 921
   
922 922
   specify "should accept hashes loaded from YAML files" do
8  spec/sequel_core/migration_spec.rb
@@ -146,10 +146,10 @@ def down
146 146
     Object.send(:remove_const, "CreateUsers") if Object.const_defined?("CreateUsers")
147 147
     Object.send(:remove_const, "CreateAttributes") if Object.const_defined?("CreateAttributes")
148 148
 
149  
-    FileUtils.rm('001_create_sessions.rb')
150  
-    FileUtils.rm('002_create_nodes.rb')
151  
-    FileUtils.rm('003_create_users.rb')
152  
-    FileUtils.rm('005_create_attributes.rb')
  149
+    File.delete('001_create_sessions.rb')
  150
+    File.delete('002_create_nodes.rb')
  151
+    File.delete('003_create_users.rb')
  152
+    File.delete('005_create_attributes.rb')
153 153
   end
154 154
   
155 155
   specify "should return the list of files for a specified version range" do
12  spec/sequel_model/association_reflection_spec.rb
@@ -3,7 +3,7 @@
3 3
 describe Sequel::Model::Associations::AssociationReflection, "#associated_class" do
4 4
   before do
5 5
     @c = Class.new(Sequel::Model)
6  
-    class ParParent < Sequel::Model; end
  6
+    class ::ParParent < Sequel::Model; end
7 7
   end
8 8
 
9 9
   it "should use the :class value if present" do
@@ -21,7 +21,7 @@ class ParParent < Sequel::Model; end
21 21
 describe Sequel::Model::Associations::AssociationReflection, "#associated_primary_key" do
22 22
   before do
23 23
     @c = Class.new(Sequel::Model)
24  
-    class ParParent < Sequel::Model; end
  24
+    class ::ParParent < Sequel::Model; end
25 25
   end
26 26
 
27 27
   it "should use the :right_primary_key value if present" do
@@ -46,9 +46,9 @@ class ParParent < Sequel::Model; end
46 46
   end
47 47
 
48 48
   it "should figure out the reciprocal if the :reciprocal value is not present" do
49  
-    class ParParent < Sequel::Model; end
50  
-    class ParParentTwo < Sequel::Model; end
51  
-    class ParParentThree < Sequel::Model; end
  49
+    class ::ParParent < Sequel::Model; end
  50
+    class ::ParParentTwo < Sequel::Model; end
  51
+    class ::ParParentThree < Sequel::Model; end
52 52
     ParParent.many_to_one :par_parent_two
53 53
     ParParentTwo.one_to_many :par_parents
54 54
     ParParent.many_to_many :par_parent_threes
@@ -68,7 +68,7 @@ class ParParentThree < Sequel::Model; end
68 68
 describe Sequel::Model::Associations::AssociationReflection, "#select" do
69 69
   before do
70 70
     @c = Class.new(Sequel::Model)
71  
-    class ParParent < Sequel::Model; end
  71
+    class ::ParParent < Sequel::Model; end
72 72
   end
73 73
 
74 74
   it "should use the :select value if present" do
41  spec/sequel_model/associations_spec.rb
@@ -4,7 +4,7 @@
4 4
   it "should use explicit class if given a class, symbol, or string" do
5 5
     MODEL_DB.reset
6 6
     klass = Class.new(Sequel::Model(:nodes))
7  
-    class ParParent < Sequel::Model
  7
+    class ::ParParent < Sequel::Model
8 8
     end
9 9
     
10 10
     klass.associate :many_to_one, :par_parent0, :class=>ParParent
@@ -48,6 +48,7 @@ def blar
48 48
     MODEL_DB.reset
49 49
 
50 50
     @c2 = Class.new(Sequel::Model(:nodes)) do
  51
+      unrestrict_primary_key
51 52
       columns :id, :parent_id, :par_parent_id, :blah
52 53
     end
53 54
 
@@ -66,7 +67,7 @@ def blar
66 67
   end
67 68
   
68 69
   it "should use implicit class if omitted" do
69  
-    class ParParent < Sequel::Model
  70
+    class ::ParParent < Sequel::Model
70 71
     end
71 72
     
72 73
     @c2.many_to_one :par_parent
@@ -79,7 +80,7 @@ class ParParent < Sequel::Model
79 80
   end
80 81
 
81 82
   it "should use class inside module if given as a string" do
82  
-    module Par 
  83
+    module ::Par 
83 84
       class Parent < Sequel::Model
84 85
       end
85 86
     end
@@ -284,8 +285,8 @@ def ds.fetch_rows(sql, &block)
284 285
 
285 286
   it "should not create the setter method if :read_only option is used" do
286 287
     @c2.many_to_one :parent, :class => @c2, :read_only=>true
287  
-    @c2.instance_methods.should(include('parent'))
288  
-    @c2.instance_methods.should_not(include('parent='))
  288
+    @c2.instance_methods.collect{|x| x.to_s}.should(include('parent'))
  289
+    @c2.instance_methods.collect{|x| x.to_s}.should_not(include('parent='))
289 290
   end
290 291
 
291 292
   it "should raise an error if trying to set a model object that doesn't have a valid primary key" do
@@ -311,7 +312,7 @@ def ds.fetch_rows(sql, &block); MODEL_DB.sqls << sql; yield({:id=>234}) end
311 312
 
312 313
   it "should make the change to the foreign_key value inside a _association= method" do
313 314
     @c2.many_to_one :parent, :class => @c2
314  
-    @c2.private_instance_methods.sort.should(include("_parent="))
  315
+    @c2.private_instance_methods.collect{|x| x.to_s}.sort.should(include("_parent="))
315 316
     p = @c2.new
316 317
     c = @c2.load(:id=>123)
317 318
     def p._parent=(x)
@@ -422,10 +423,12 @@ def ar(x)
422 423
     MODEL_DB.reset
423 424
 
424 425
     @c1 = Class.new(Sequel::Model(:attributes)) do
  426
+      unrestrict_primary_key
425 427
       columns :id, :node_id
426 428
     end
427 429
 
428 430
     @c2 = Class.new(Sequel::Model(:nodes)) do
  431
+      unrestrict_primary_key
429 432
       attr_accessor :xxx
430 433
       
431 434
       def self.name; 'Node'; end
@@ -459,7 +462,7 @@ def fetch_rows(sql)
459 462
   end
460 463
   
461 464
   it "should use implicit class if omitted" do
462  
-    class HistoricalValue < Sequel::Model
  465
+    class ::HistoricalValue < Sequel::Model
463 466
     end
464 467
     
465 468
     @c2.one_to_many :historical_values
@@ -472,7 +475,7 @@ class HistoricalValue < Sequel::Model
472 475
   end
473 476
   
474 477
   it "should use class inside a module if given as a string" do
475  
-    module Historical
  478
+    module ::Historical
476 479
       class Value < Sequel::Model
477 480
       end
478 481
     end
@@ -716,7 +719,7 @@ def a.valid?; false; end
716 719
 
717 720
   it "should not create the add_, remove_, or remove_all_ methods if :read_only option is used" do
718 721
     @c2.one_to_many :attributes, :class => @c1, :read_only=>true
719  
-    im = @c2.instance_methods
  722
+    im = @c2.instance_methods.collect{|x| x.to_s}
720 723
     im.should(include('attributes'))
721 724
     im.should(include('attributes_dataset'))
722 725
     im.should_not(include('add_attribute'))
@@ -827,7 +830,7 @@ def attrib.save!; self end
827 830
 
828 831
   it "should not add a getter method if the :one_to_one option is true and :read_only option is true" do
829 832
     @c2.one_to_many :attributes, :class => @c1, :one_to_one=>true, :read_only=>true
830  
-    im = @c2.instance_methods
  833
+    im = @c2.instance_methods.collect{|x| x.to_s}
831 834
     im.should(include('attribute'))
832 835
     im.should_not(include('attribute='))
833 836
   end
@@ -870,7 +873,7 @@ def d.fetch_rows(s); yield({:id=>3}) end
870 873
 
871 874
   it "should make non getter and setter methods private if :one_to_one option is used" do 
872 875
     @c2.one_to_many :attributes, :class => @c1, :one_to_one=>true do |ds| end
873  
-    meths = @c2.private_instance_methods(false)
  876
+    meths = @c2.private_instance_methods(false).collect{|x| x.to_s}
874 877
     meths.should(include("attributes"))
875 878
     meths.should(include("add_attribute"))
876 879
     meths.should(include("attributes_dataset"))
@@ -878,7 +881,7 @@ def d.fetch_rows(s); yield({:id=>3}) end
878 881
 
879 882
   it "should call an _add_ method internally to add attributes" do
880 883
     @c2.one_to_many :attributes, :class => @c1
881  
-    @c2.private_instance_methods.sort.should(include("_add_attribute"))
  884
+    @c2.private_instance_methods.collect{|x| x.to_s}.sort.should(include("_add_attribute"))
882 885
     p = @c2.load(:id=>10)
883 886
     c = @c1.load(:id=>123)
884 887
     def p._add_attribute(x)
@@ -891,7 +894,7 @@ def p._add_attribute(x)
891 894
 
892 895
   it "should call a _remove_ method internally to remove attributes" do
893 896
     @c2.one_to_many :attributes, :class => @c1
894  
-    @c2.private_instance_methods.sort.should(include("_remove_attribute"))
  897
+    @c2.private_instance_methods.collect{|x| x.to_s}.sort.should(include("_remove_attribute"))
895 898
     p = @c2.load(:id=>10)
896 899
     c = @c1.load(:id=>123)
897 900
     def p._remove_attribute(x)
@@ -990,12 +993,14 @@ def @dataset.fetch_rows(sql)
990 993
     MODEL_DB.reset
991 994
 
992 995
     @c1 = Class.new(Sequel::Model(:attributes)) do
  996
+      unrestrict_primary_key
993 997
       def self.name; 'Attribute'; end
994 998
       def self.to_s; 'Attribute'; end
995 999
       columns :id
996 1000
     end
997 1001
 
998 1002
     @c2 = Class.new(Sequel::Model(:nodes)) do
  1003
+      unrestrict_primary_key
999 1004
       attr_accessor :xxx
1000 1005
       
1001 1006
       def self.name; 'Node'; end
@@ -1024,7 +1029,7 @@ def fetch_rows(sql)
1024 1029
   end
1025 1030
   
1026 1031
   it "should use implicit class if omitted" do
1027  
-    class Tag < Sequel::Model
  1032
+    class ::Tag < Sequel::Model
1028 1033
     end
1029 1034
     
1030 1035
     @c2.many_to_many :tags
@@ -1036,7 +1041,7 @@ class Tag < Sequel::Model
1036 1041
   end
1037 1042
   
1038 1043
   it "should use class inside module if given as a string" do
1039  
-    module Historical
  1044
+    module ::Historical
1040 1045
       class Tag < Sequel::Model
1041 1046
       end
1042 1047
     end
@@ -1287,7 +1292,7 @@ class Tag < Sequel::Model
1287 1292
 
1288 1293
   it "should not create the add_, remove_, or remove_all_ methods if :read_only option is used" do
1289 1294
     @c2.many_to_many :attributes, :class => @c1, :read_only=>true
1290  
-    im = @c2.instance_methods
  1295
+    im = @c2.instance_methods.collect{|x| x.to_s}
1291 1296
     im.should(include('attributes'))
1292 1297
     im.should(include('attributes_dataset'))
1293 1298
     im.should_not(include('add_attribute'))
@@ -1353,7 +1358,7 @@ def d.fetch_rows(s); end
1353 1358
 
1354 1359
   it "should call an _add_ method internally to add attributes" do
1355 1360
     @c2.many_to_many :attributes, :class => @c1
1356  
-    @c2.private_instance_methods.sort.should(include("_add_attribute"))
  1361
+    @c2.private_instance_methods.collect{|x| x.to_s}.sort.should(include("_add_attribute"))
1357 1362
     p = @c2.load(:id=>10)
1358 1363
     c = @c1.load(:id=>123)
1359 1364
     def p._add_attribute(x)
@@ -1366,7 +1371,7 @@ def p._add_attribute(x)
1366 1371
 
1367 1372
   it "should call a _remove_ method internally to remove attributes" do
1368 1373
     @c2.many_to_many :attributes, :class => @c1
1369  
-    @c2.private_instance_methods.sort.should(include("_remove_attribute"))
  1374
+    @c2.private_instance_methods.collect{|x| x.to_s}.sort.should(include("_remove_attribute"))
1370 1375
     p = @c2.load(:id=>10)
1371 1376
     c = @c1.load(:id=>123)
1372 1377
     def p._remove_attribute(x)
3  spec/sequel_model/base_spec.rb
@@ -79,10 +79,11 @@
79 79
 
80 80
     @c.create(:abc => 1)
81 81
     @c.create(:abc => "hello")
  82
+    x = [Marshal.dump("hello")].pack('m')
82 83
 
83 84
     MODEL_DB.sqls.should == [ \
84 85
       "INSERT INTO items (abc) VALUES ('BAhpBg==\n')", \
85  
-      "INSERT INTO items (abc) VALUES ('BAgiCmhlbGxv\n')", \
  86
+      "INSERT INTO items (abc) VALUES ('#{x}')", \
86 87
     ]
87 88
   end
88 89
 
24  spec/sequel_model/eager_loading_spec.rb
@@ -4,7 +4,7 @@
4 4
   before(:each) do
5 5
     MODEL_DB.reset
6 6
     
7  
-    class EagerAlbum < Sequel::Model(:albums)
  7
+    class ::EagerAlbum < Sequel::Model(:albums)
8 8
       columns :id, :band_id
9 9
       many_to_one :band, :class=>'EagerBand', :key=>:band_id
10 10
       one_to_many :tracks, :class=>'EagerTrack', :key=>:album_id
@@ -17,7 +17,7 @@ class EagerAlbum < Sequel::Model(:albums)
17 17
       many_to_many :genre_names, :class=>'EagerGenre', :left_key=>:album_id, :right_key=>:genre_id, :join_table=>:ag, :select=>[:id]
18 18
     end
19 19
 
20  
-    class EagerBand < Sequel::Model(:bands)
  20
+    class ::EagerBand < Sequel::Model(:bands)
21 21
       columns :id
22 22
       one_to_many :albums, :class=>'EagerAlbum', :key=>:band_id, :eager=>:tracks
23 23
       one_to_many :graph_albums, :class=>'EagerAlbum', :key=>:band_id, :eager_graph=>:tracks
@@ -32,17 +32,17 @@ class EagerBand < Sequel::Model(:bands)
32 32
       one_to_many :top_10_albums, :class=>'EagerAlbum', :key=>:band_id, :limit=>10
33 33
     end
34 34
     
35  
-    class EagerTrack < Sequel::Model(:tracks)
  35
+    class ::EagerTrack < Sequel::Model(:tracks)
36 36
       columns :id, :album_id
37 37
       many_to_one :album, :class=>'EagerAlbum', :key=>:album_id
38 38
     end
39 39
     
40  
-    class EagerGenre < Sequel::Model(:genres)
  40
+    class ::EagerGenre < Sequel::Model(:genres)
41 41
       columns :id
42 42
       many_to_many :albums, :class=>'EagerAlbum', :left_key=>:genre_id, :right_key=>:album_id, :join_table=>:ag
43 43
     end
44 44
     
45  
-    class EagerBandMember < Sequel::Model(:members)
  45
+    class ::EagerBandMember < Sequel::Model(:members)
46 46
       columns :id
47 47
       many_to_many :bands, :class=>'EagerBand', :left_key=>:member_id, :right_key=>:band_id, :join_table=>:bm, :order =>:id
48 48
     end
@@ -459,13 +459,13 @@ def fetch_rows(sql)
459 459
 
460 460
 describe Sequel::Model, "#eager_graph" do
461 461
   after(:all) do
462  
-    class MockDataset
  462
+    class ::MockDataset
463 463
       alias clone orig_clone
464 464
     end
465 465
   end
466 466
 
467 467
   before(:all) do
468  
-    class MockDataset
  468
+    class ::MockDataset
469 469
       alias orig_clone clone
470 470
       def clone(opts = {})
471 471
         c = super()
@@ -475,7 +475,7 @@ def clone(opts = {})
475 475
       end
476 476
     end
477 477
 
478  
-    class GraphAlbum < Sequel::Model(:albums)
  478
+    class ::GraphAlbum < Sequel::Model(:albums)
479 479
       dataset.opts[:from] = [:albums]
480 480
       columns :id, :band_id
481 481
       many_to_one :band, :class=>'GraphBand', :key=>:band_id
@@ -484,7 +484,7 @@ class GraphAlbum < Sequel::Model(:albums)
484 484
       many_to_one :previous_album, :class=>'GraphAlbum'
485 485
     end
486 486
 
487  
-    class GraphBand < Sequel::Model(:bands)
  487
+    class ::GraphBand < Sequel::Model(:bands)
488 488
       dataset.opts[:from] = [:bands]
489 489
       columns :id, :vocalist_id
490 490
       many_to_one :vocalist, :class=>'GraphBandMember', :key=>:vocalist_id
@@ -493,19 +493,19 @@ class GraphBand < Sequel::Model(:bands)
493 493
       many_to_many :genres, :class=>'GraphGenre', :left_key=>:band_id, :right_key=>:genre_id, :join_table=>:bg
494 494
     end
495 495
     
496  
-    class GraphTrack < Sequel::Model(:tracks)
  496
+    class ::GraphTrack < Sequel::Model(:tracks)
497 497
       dataset.opts[:from] = [:tracks]
498 498
       columns :id, :album_id
499 499
       many_to_one :album, :class=>'GraphAlbum', :key=>:album_id
500 500
     end
501 501
     
502  
-    class GraphGenre < Sequel::Model(:genres)
  502
+    class ::GraphGenre < Sequel::Model(:genres)
503 503
       dataset.opts[:from] = [:genres]
504 504
       columns :id
505 505
       many_to_many :albums, :class=>'GraphAlbum', :left_key=>:genre_id, :right_key=>:album_id, :join_table=>:ag
506 506
     end
507 507
     
508  
-    class GraphBandMember < Sequel::Model(:members)
  508
+    class ::GraphBandMember < Sequel::Model(:members)
509 509
       dataset.opts[:from] = [:members]
510 510
       columns :id
511 511
       many_to_many :bands, :class=>'GraphBand', :left_key=>:member_id, :right_key=>:band_id, :join_table=>:bm
8  spec/sequel_model/hooks_spec.rb
@@ -349,24 +349,24 @@ def save!(*columns)
349 349
   
350 350
   specify "should be called around validation" do
351 351
     @c.before_validation{MODEL_DB << "BLAH before"}
352  
-    m = @c.new(:id => 2233)
  352
+    m = @c.load(:id => 2233)
353 353
     m.should be_valid
354 354
     MODEL_DB.sqls.should == ['BLAH before', 'BLAH after']
355 355
 
356 356
     MODEL_DB.sqls.clear
357  
-    m = @c.new(:id => 22)
  357
+    m = @c.load(:id => 22)
358 358
     m.should_not be_valid
359 359
     MODEL_DB.sqls.should == ['BLAH before', 'BLAH after']
360 360
   end
361 361
 
362 362
   specify "should be called when calling save" do
363 363
     @c.before_validation{MODEL_DB << "BLAH before"}
364  
-    m = @c.new(:id => 2233)
  364
+    m = @c.load(:id => 2233)
365 365
     m.save.should == m
366 366
     MODEL_DB.sqls.should == ['BLAH before', 'BLAH after', 'CREATE BLAH']
367 367
 
368 368
     MODEL_DB.sqls.clear
369  
-    m = @c.new(:id => 22)
  369
+    m = @c.load(:id => 22)
370 370
     m.raise_on_save_failure = false
371 371
     m.save.should == nil
372 372
     MODEL_DB.sqls.should == ['BLAH before', 'BLAH after']
22  spec/sequel_model/model_spec.rb
@@ -2,7 +2,7 @@
2 2
 
3 3
 describe Sequel::Model do
4 4
   it "should have class method aliased as model" do
5  
-    Sequel::Model.instance_methods.should include("model")
  5
+    Sequel::Model.instance_methods.collect{|x| x.to_s}.should include("model")
6 6
 
7 7
     model_a = Class.new(Sequel::Model(:items))
8 8
     model_a.new.model.should be(model_a)
@@ -93,14 +93,14 @@
93 93
 
94 94
 describe Sequel::Model, "#sti_key" do
95 95
   before do
96  
-    class StiTest < Sequel::Model
  96
+    class ::StiTest < Sequel::Model
97 97
       def kind=(x); self[:kind] = x; end
98 98
       def refresh; end
99 99
       set_sti_key :kind
100 100
     end
101  
-    class StiTestSub1 < StiTest
  101
+    class ::StiTestSub1 < StiTest
102 102
     end
103  
-    class StiTestSub2 < StiTest
  103
+    class ::StiTestSub2 < StiTest
104 104
     end
105 105
     @ds = StiTest.dataset
106 106
     MODEL_DB.reset
@@ -445,15 +445,15 @@ def @dataset.def_mutation_method(*names);  end
445 445
 
446 446
   it "should be created on set_dataset unless lazy loading schema" do
447 447
     %w'x y x= y='.each do |x|
448  
-      @c.instance_methods.include?(x).should == false
  448
+      @c.instance_methods.collect{|y| y.to_s}.should_not include(x)
449 449
     end
450 450
     @c.set_dataset(@dataset)
451 451
     %w'x y x= y='.each do |x|
452  
-      @c.instance_methods.include?(x).should == true
  452
+      @c.instance_methods.collect{|y| y.to_s}.should include(x)
453 453
     end
454 454
     o = @c.new
455 455
     %w'x y x= y='.each do |x|
456  
-      o.methods.include?(x).should == true
  456
+      o.methods.collect{|y| y.to_s}.should include(x)
457 457
     end
458 458
 
459 459
     o.x.should be_nil
@@ -464,18 +464,18 @@ def @dataset.def_mutation_method(*names);  end
464 464
   it "should be created on first initialization if lazy loading schema" do
465 465
     Sequel::Model.lazy_load_schema = true
466 466
     %w'x y x= y='.each do |x|
467  
-      @c.instance_methods.include?(x).should == false
  467
+      @c.instance_methods.collect{|y| y.to_s}.should_not include(x)
468 468
     end
469 469
     @c.set_dataset(@dataset)
470 470
     %w'x y x= y='.each do |x|
471  
-      @c.instance_methods.include?(x).should == false 
  471
+      @c.instance_methods.collect{|y| y.to_s}.should_not include(x)
472 472
     end
473 473
     o = @c.new
474 474
     %w'x y x= y='.each do |x|
475  
-      @c.instance_methods.include?(x).should == true
  475
+      @c.instance_methods.collect{|y| y.to_s}.should include(x)
476 476
     end
477 477
     %w'x y x= y='.each do |x|
478  
-      o.methods.include?(x).should == true
  478
+      o.methods.collect{|y| y.to_s}.should include(x)
479 479
     end
480 480
 
481 481
     o.x.should be_nil
12  spec/sequel_model/record_spec.rb
@@ -33,7 +33,7 @@
33 33
   end
34 34
   
35 35
   it "should mark saved columns as not changed" do
36  
-    o = @c.new(:id => 3, :x => 1, :y => nil)
  36
+    o = @c.load(:id => 3, :x => 1, :y => nil)
37 37
     o[:y] = 4
38 38
     o.changed_columns.should == [:y]
39 39
     o.save(:x)
@@ -50,6 +50,7 @@
50 50
     MODEL_DB.reset
51 51
 
52 52
     @c = Class.new(Sequel::Model(:items)) do
  53
+      unrestrict_primary_key
53 54
       columns :id, :x, :y
54 55
     end
55 56
   end
@@ -110,6 +111,7 @@
110 111
     MODEL_DB.reset
111 112
 
112 113
     @c = Class.new(Sequel::Model(:items)) do
  114
+      unrestrict_primary_key
113 115
       columns :id, :x, :y
114 116
     end
115 117
   end
@@ -141,6 +143,7 @@
141 143
     MODEL_DB.reset
142 144
 
143 145
     @c = Class.new(Sequel::Model(:items)) do
  146
+      unrestrict_primary_key
144 147
       columns :id, :x, :y
145 148
     end
146 149
   end
@@ -176,6 +179,7 @@
176 179
     MODEL_DB.reset
177 180
 
178 181
     @c = Class.new(Sequel::Model(:items)) do
  182
+      unrestrict_primary_key
179 183
     end
180 184
   end
181 185
   
@@ -722,6 +726,7 @@
722 726
   before(:each) do
723 727
     MODEL_DB.reset
724 728
     @c = Class.new(Sequel::Model(:items)) do
  729
+      unrestrict_primary_key
725 730
       columns :x
726 731
     end
727 732
   end
@@ -740,7 +745,7 @@
740 745
 
741 746
   it "should accept a block and run it" do
742 747
     o1, o2, o3 =  nil, nil, nil
743  
-    o = @c.create {|o3| o1 = o3; o2 = :blah; o3.x = 333}
  748
+    o = @c.create {|o4| o1 = o4; o3 = o4; o2 = :blah; o3.x = 333}
744 749
     o.class.should == @c
745 750
     o1.should === o
746 751
     o3.should === o
@@ -760,7 +765,8 @@
760 765
   setup do
761 766
     MODEL_DB.reset
762 767
     @c = Class.new(Sequel::Model(:items)) do
763  
-      columns :x
  768
+      unrestrict_primary_key
  769
+      columns :id, :x
764 770
     end
765 771
   end
766 772
 
34  spec/sequel_model/validations_spec.rb
@@ -527,28 +527,28 @@ def dont_skip; true; end
527 527
 describe Sequel::Model, "Validations" do
528 528
 
529 529
   before(:all) do
530  
-    class Person < Sequel::Model
  530
+    class ::Person < Sequel::Model
531 531
       columns :id,:name,:first_name,:last_name,:middle_name,:initials,:age, :terms
532 532
     end
533 533
 
534  
-    class Smurf < Person
  534
+    class ::Smurf < Person
535 535
     end
536 536
     
537  
-    class Cow < Sequel::Model
  537
+    class ::Cow < Sequel::Model
538 538
       columns :id, :name, :got_milk
539 539
     end
540 540
 
541  
-    class User < Sequel::Model
  541
+    class ::User < Sequel::Model
542 542
       columns :id, :username, :password
543 543
     end
544 544
     
545  
-    class Address < Sequel::Model
  545
+    class ::Address < Sequel::Model
546 546
       columns :id, :zip_code
547 547
     end
548 548
   end
549 549
   
550 550
   it "should validate the acceptance of a column" do
551  
-    class Cow < Sequel::Model
  551
+    class ::Cow < Sequel::Model
552 552
       validations.clear
553 553
       validates_acceptance_of :got_milk, :accept => 'blah', :allow_nil => false
554 554
     end
@@ -562,7 +562,7 @@ class Cow < Sequel::Model
562 562
   end
563 563
   
564 564
   it "should validate the confirmation of a column" do
565  
-    class User < Sequel::Model
  565
+    class ::User < Sequel::Model
566 566
       def password_confirmation
567 567
         "test"
568 568
       end
@@ -580,7 +580,7 @@ def password_confirmation
580 580
   end
581 581
   
582 582
   it "should validate format of column" do
583  
-    class Person < Sequel::Model
  583
+    class ::Person < Sequel::Model
584 584
       validates_format_of :first_name, :with => /^[a-zA-Z]+$/
585 585
     end
586 586
 
@@ -595,7 +595,7 @@ class Person < Sequel::Model
595 595
   # end
596 596
 
597 597
   it "should validate length of column" do
598  
-    class Person < Sequel::Model
  598
+    class ::Person < Sequel::Model
599 599
       validations.clear
600 600
       validates_length_of :first_name, :maximum => 30
601 601
       validates_length_of :last_name, :minimum => 30
@@ -627,7 +627,7 @@ class Person < Sequel::Model
627 627
   end
628 628
   
629 629
   it "should validate numericality of column" do
630  
-    class Person < Sequel::Model
  630
+    class ::Person < Sequel::Model
631 631
       validations.clear
632 632
       validates_numericality_of :age
633 633
     end
@@ -641,7 +641,7 @@ class Person < Sequel::Model
641 641
   end
642 642
   
643 643
   it "should validate the presence of a column" do
644  
-    class Cow < Sequel::Model
  644
+    class ::Cow < Sequel::Model
645 645
       validations.clear
646 646
       validates_presence_of :name
647 647
     end
@@ -655,7 +655,7 @@ class Cow < Sequel::Model
655 655
   end
656 656
  
657 657
   it "should validate the uniqueness of a column" do
658  
-    class User < Sequel::Model
  658
+    class ::User < Sequel::Model
659 659
       validations.clear
660 660
       validates do
661 661
         uniqueness_of :username
@@ -699,7 +699,7 @@ def fetch_rows(sql)
699 699
   end
700 700
   
701 701
   it "should have a validates block that contains multiple validations" do
702  
-    class Person < Sequel::Model
  702
+    class ::Person < Sequel::Model
703 703
       validations.clear
704 704
       validates do
705 705
         format_of :first_name, :with => /^[a-zA-Z]+$/
@@ -718,7 +718,7 @@ class Person < Sequel::Model
718 718
 
719 719
   it "should allow 'longhand' validations direcly within the model." do
720 720
     lambda {
721  
-      class Person < Sequel::Model
  721
+      class ::Person < Sequel::Model
722 722
         validations.clear
723 723
         validates_length_of :first_name, :maximum => 30
724 724
       end
@@ -727,7 +727,7 @@ class Person < Sequel::Model
727 727
   end
728 728
 
729 729
   it "should define a has_validations? method which returns true if the model has validations, false otherwise" do
730  
-    class Person < Sequel::Model
  730
+    class ::Person < Sequel::Model
731 731
       validations.clear
732 732
       validates do
733 733
         format_of :first_name, :with => /\w+/
@@ -735,7 +735,7 @@ class Person < Sequel::Model
735 735
       end
736 736
     end
737 737
 
738  
-    class Smurf < Person
  738
+    class ::Smurf < Person
739 739
       validations.clear
740 740
     end
741 741
 
@@ -744,7 +744,7 @@ class Smurf < Person
744 744
   end
745 745
 
746 746
   it "should validate correctly instances initialized with string keys" do
747  
-    class Can < Sequel::Model
  747
+    class ::Can < Sequel::Model
748 748
       columns :id, :name
749 749
       
750 750
       validates_length_of :name, :minimum => 4

0 notes on commit 332883a

Please sign in to comment.
Something went wrong with that request. Please try again.