Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minor changes to allow for full Ruby 1.9 compatibility

  • Loading branch information...
commit 332883a9a025a5d6d0c5f61ef0f363d6b244d1b6 1 parent 7b64f01
@jeremyevans authored
View
2  CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Minor changes to allow for full Ruby 1.9 compatibility (jeremyevans)
+
* Make Database#disconnect work for the ADO adapter (spicyj)
* Don't raise an exception in the ADO adapter if the dataset contains no records (nusco)
View
2  Rakefile
@@ -130,7 +130,7 @@ end
%w'postgres sqlite mysql informix oracle ado'.each do |adapter|
desc "Run #{adapter} specs without coverage"
Spec::Rake::SpecTask.new("spec_#{adapter}") do |t|
- t.spec_files = "spec/adapters/#{adapter}_spec.rb"
+ t.spec_files = ["spec/adapters/#{adapter}_spec.rb"]
t.spec_opts = spec_opts.call
end
end
View
6 lib/sequel_core/adapters/sqlite.rb
@@ -92,7 +92,7 @@ def auto_vacuum
end
def auto_vacuum=(value)
- value = AUTO_VACUUM.index(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
+ value = AUTO_VACUUM.key(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
pragma_set(:auto_vacuum, value)
end
@@ -103,7 +103,7 @@ def synchronous
end
def synchronous=(value)
- value = SYNCHRONOUS.index(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
+ value = SYNCHRONOUS.key(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
pragma_set(:synchronous, value)
end
@@ -114,7 +114,7 @@ def temp_store
end
def temp_store=(value)
- value = TEMP_STORE.index(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
+ value = TEMP_STORE.key(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
pragma_set(:temp_store, value)
end
View
6 lib/sequel_core/core_ext.rb
@@ -1,3 +1,9 @@
+if RUBY_VERSION < '1.9.0'
+ class Hash
+ alias key index
+ end
+end
+
class Array
# True if the array is not empty and all of its elements are
# arrays of size 2. This is used to determine if the array
View
11 lib/sequel_core/sql.rb
@@ -762,6 +762,15 @@ def to_s(ds)
end
end
+ if RUBY_VERSION >= '1.9.0'
+ class VirtualRow < BasicObject
+ end
+ else
+ class VirtualRow
+ (instance_methods - %w"__id__ __send__ instance_eval == equal?").each{|m| undef_method(m)}
+ end
+ end
+
# An instance of this class is yielded to the block supplied to filter.
# Useful if another library also defines the operator methods that
# Sequel defines for symbols.
@@ -773,8 +782,6 @@ def to_s(ds)
# ds.filter{|r| r.table__column + 1 < 2} # SELECT * FROM t WHERE ((table.column + 1) < 2)
# ds.filter{|r| r.is_active(1, 'arg2')} # SELECT * FROM t WHERE is_active(1, 'arg2')
class VirtualRow
- (instance_methods - %w"__id__ __send__").each{|m| undef_method(m)}
-
# Can return Identifiers, QualifiedIdentifiers, or Functions:
#
# * Function - returned if any arguments are supplied, using the method name
View
4 lib/sequel_model/association_reflection.rb
@@ -70,14 +70,14 @@ def dataset_need_primary_key?
# Name symbol for default join table
def default_join_table
- ([self[:class_name].demodulize, self[:model].name.demodulize]. \
+ ([self[:class_name].demodulize, self[:model].name.to_s.demodulize]. \
map{|i| i.pluralize.underscore}.sort.join('_')).to_sym
end
# Default foreign key name symbol for key in associated table that points to
# current table's primary key.
def default_left_key
- :"#{self[:model].name.demodulize.underscore}_id"
+ :"#{self[:model].name.to_s.demodulize.underscore}_id"
end
# Default foreign key name symbol for foreign key in current model's table that points to
View
10 lib/sequel_model/base.rb
@@ -195,7 +195,7 @@ def self.find_or_create(cond)
# from the parent class.
def self.inherited(subclass)
sup_class = subclass.superclass
- ivs = subclass.instance_variables
+ ivs = subclass.instance_variables.collect{|x| x.to_s}
INHERITED_INSTANCE_VARIABLES.each do |iv, dup|
next if ivs.include?(iv.to_s)
sup_class_value = sup_class.instance_variable_get(iv)
@@ -205,9 +205,9 @@ def self.inherited(subclass)
unless ivs.include?("@dataset")
begin
if sup_class == Model
- subclass.set_dataset(Model.db[subclass.implicit_table_name]) unless subclass.name.empty?
+ subclass.set_dataset(Model.db[subclass.implicit_table_name]) unless subclass.name.blank?
elsif ds = sup_class.instance_variable_get(:@dataset)
- subclass.set_dataset(sup_class.sti_key ? sup_class.sti_dataset.filter(sup_class.sti_key=>subclass.name) : ds.clone)
+ subclass.set_dataset(sup_class.sti_key ? sup_class.sti_dataset.filter(sup_class.sti_key=>subclass.name.to_s) : ds.clone)
end
rescue
nil
@@ -380,7 +380,7 @@ def self.set_sti_key(key)
@sti_key = key
@sti_dataset = dataset
dataset.set_model(key, Hash.new{|h,k| h[k] = (k.constantize rescue m)})
- before_create(:set_sti_key){send("#{key}=", model.name)}
+ before_create(:set_sti_key){send("#{key}=", model.name.to_s)}
end
# Returns the columns as a list of frozen strings instead
@@ -427,7 +427,7 @@ def self.unrestrict_primary_key
# Create the column accessors
def self.def_column_accessor(*columns) # :nodoc:
columns.each do |column|
- im = instance_methods
+ im = instance_methods.collect{|x| x.to_s}
meth = "#{column}="
define_method(column){self[column]} unless im.include?(column.to_s)
unless im.include?(meth)
View
2  lib/sequel_model/plugins.rb
@@ -34,7 +34,7 @@ def self.is(plugin, *args)
end
if m.const_defined?("DatasetMethods")
dataset.meta_def(:"#{plugin}_opts") {args.first}
- dataset.metaclass.send(:include, m::DatasetMethods)
+ dataset.extend(m::DatasetMethods)
def_dataset_method(*m::DatasetMethods.instance_methods)
end
end
View
2  lib/sequel_model/record.rb
@@ -510,7 +510,7 @@ def setter_methods(only, except)
if only
only.map{|x| "#{x}="}
else
- meths = methods.grep(/=\z/) - RESTRICTED_SETTER_METHODS
+ meths = methods.collect{|x| x.to_s}.grep(/=\z/) - RESTRICTED_SETTER_METHODS
meths -= Array(primary_key).map{|x| "#{x}="} if primary_key && model.restrict_primary_key?
meths -= except.map{|x| "#{x}="} if except
meths
View
28 spec/integration/eager_loader_test.rb
@@ -2,7 +2,7 @@
describe "Eagerly loading a tree structure" do
before do
- class Node < Sequel::Model
+ class ::Node < Sequel::Model
set_schema do
primary_key :id
foreign_key :parent_id, :nodes
@@ -137,7 +137,7 @@ class Node < Sequel::Model
describe "Association Extensions" do
before do
- module FindOrCreate
+ module ::FindOrCreate
def find_or_create(vals)
# Exploits the fact that Sequel filters are ruby objects that
# can be introspected.
@@ -146,7 +146,7 @@ def find_or_create(vals)
@opts[:models][nil].create(vals.merge(:author_id=>author_id))
end
end
- class Author < Sequel::Model
+ class ::Author < Sequel::Model
set_schema do
primary_key :id
end
@@ -160,7 +160,7 @@ class Author < Sequel::Model
ds
end)
end
- class Authorship < Sequel::Model
+ class ::Authorship < Sequel::Model
set_schema do
primary_key :id
foreign_key :author_id, :authors
@@ -212,7 +212,7 @@ class Authorship < Sequel::Model
describe "has_many :through has_many and has_one :through belongs_to" do
before do
- class Firm < Sequel::Model
+ class ::Firm < Sequel::Model
set_schema do
primary_key :id
end
@@ -237,7 +237,7 @@ class Firm < Sequel::Model
end)
end
- class Client < Sequel::Model
+ class ::Client < Sequel::Model
set_schema do
primary_key :id
foreign_key :firm_id, :firms
@@ -247,7 +247,7 @@ class Client < Sequel::Model
one_to_many :invoices
end
- class Invoice < Sequel::Model
+ class ::Invoice < Sequel::Model
set_schema do
primary_key :id
foreign_key :client_id, :clients
@@ -375,7 +375,7 @@ class Invoice < Sequel::Model
describe "Polymorphic Associations" do
before do
- class Asset < Sequel::Model
+ class ::Asset < Sequel::Model
set_schema do
primary_key :id
integer :attachable_id
@@ -411,7 +411,7 @@ def _attachable=(attachable)
end
end
- class Post < Sequel::Model
+ class ::Post < Sequel::Model
set_schema do
primary_key :id
end
@@ -438,7 +438,7 @@ def _remove_all_assets
end
end
- class Note < Sequel::Model
+ class ::Note < Sequel::Model
set_schema do
primary_key :id
end
@@ -550,7 +550,7 @@ def _remove_all_assets
describe "many_to_one/one_to_many not referencing primary key" do
before do
- class Client < Sequel::Model
+ class ::Client < Sequel::Model
set_schema do
primary_key :id
text :name
@@ -585,7 +585,7 @@ def _remove_all_invoices
end
end
- class Invoice < Sequel::Model
+ class ::Invoice < Sequel::Model
set_schema do
primary_key :id
text :client_name
@@ -671,7 +671,7 @@ def _client=(client)
@client2.invoices.should == []
sqls_should_be("SELECT * FROM invoices WHERE (client_name = 'Y')")
@client2.add_invoice(@invoice1)
- sqls_should_be("UPDATE invoices SET client_name = 'Y', id = 1 WHERE (id = 1)")
+ sqls_should_be(/UPDATE invoices SET (client_name = 'Y'|id = 1), (client_name = 'Y'|id = 1) WHERE \(id = 1\)/)
@client2.invoices.should == [@invoice1]
@invoice1.client_name.should == 'Y'
@invoice1.client = nil
@@ -684,7 +684,7 @@ def _client=(client)
sqls_should_be("SELECT * FROM invoices WHERE (client_name = 'X')")
invs.should == [@invoice1, @invoice2]
@client1.remove_invoice(@invoice1)
- sqls_should_be("UPDATE invoices SET client_name = NULL, id = 1 WHERE (id = 1)")
+ sqls_should_be(/UPDATE invoices SET (client_name = NULL|id = 1), (client_name = NULL|id = 1) WHERE \(id = 1\)/)
@client1.invoices.should == [@invoice2]
@invoice1.client_name.should == nil
@invoice1.client.should == nil
View
6 spec/sequel_core/database_spec.rb
@@ -645,11 +645,11 @@ def disconnect
context "A broken adapter (lib is there but the class is not)" do
setup do
@fn = File.join(File.dirname(__FILE__), '../../lib/sequel_core/adapters/blah.rb')
- FileUtils.touch(@fn)
+ File.open(@fn,'a'){}
end
teardown do
- FileUtils.rm(@fn)
+ File.delete(@fn)
end
specify "should raise an error" do
@@ -916,7 +916,7 @@ class EEE < Sequel::Database
end
teardown do
- FileUtils.rm(@fn)
+ File.delete(@fn)
end
specify "should accept hashes loaded from YAML files" do
View
8 spec/sequel_core/migration_spec.rb
@@ -146,10 +146,10 @@ def down
Object.send(:remove_const, "CreateUsers") if Object.const_defined?("CreateUsers")
Object.send(:remove_const, "CreateAttributes") if Object.const_defined?("CreateAttributes")
- FileUtils.rm('001_create_sessions.rb')
- FileUtils.rm('002_create_nodes.rb')
- FileUtils.rm('003_create_users.rb')
- FileUtils.rm('005_create_attributes.rb')
+ File.delete('001_create_sessions.rb')
+ File.delete('002_create_nodes.rb')
+ File.delete('003_create_users.rb')
+ File.delete('005_create_attributes.rb')
end
specify "should return the list of files for a specified version range" do
View
12 spec/sequel_model/association_reflection_spec.rb
@@ -3,7 +3,7 @@
describe Sequel::Model::Associations::AssociationReflection, "#associated_class" do
before do
@c = Class.new(Sequel::Model)
- class ParParent < Sequel::Model; end
+ class ::ParParent < Sequel::Model; end
end
it "should use the :class value if present" do
@@ -21,7 +21,7 @@ class ParParent < Sequel::Model; end
describe Sequel::Model::Associations::AssociationReflection, "#associated_primary_key" do
before do
@c = Class.new(Sequel::Model)
- class ParParent < Sequel::Model; end
+ class ::ParParent < Sequel::Model; end
end
it "should use the :right_primary_key value if present" do
@@ -46,9 +46,9 @@ class ParParent < Sequel::Model; end
end
it "should figure out the reciprocal if the :reciprocal value is not present" do
- class ParParent < Sequel::Model; end
- class ParParentTwo < Sequel::Model; end
- class ParParentThree < Sequel::Model; end
+ class ::ParParent < Sequel::Model; end
+ class ::ParParentTwo < Sequel::Model; end
+ class ::ParParentThree < Sequel::Model; end
ParParent.many_to_one :par_parent_two
ParParentTwo.one_to_many :par_parents
ParParent.many_to_many :par_parent_threes
@@ -68,7 +68,7 @@ class ParParentThree < Sequel::Model; end
describe Sequel::Model::Associations::AssociationReflection, "#select" do
before do
@c = Class.new(Sequel::Model)
- class ParParent < Sequel::Model; end
+ class ::ParParent < Sequel::Model; end
end
it "should use the :select value if present" do
View
41 spec/sequel_model/associations_spec.rb
@@ -4,7 +4,7 @@
it "should use explicit class if given a class, symbol, or string" do
MODEL_DB.reset
klass = Class.new(Sequel::Model(:nodes))
- class ParParent < Sequel::Model
+ class ::ParParent < Sequel::Model
end
klass.associate :many_to_one, :par_parent0, :class=>ParParent
@@ -48,6 +48,7 @@ def blar
MODEL_DB.reset
@c2 = Class.new(Sequel::Model(:nodes)) do
+ unrestrict_primary_key
columns :id, :parent_id, :par_parent_id, :blah
end
@@ -66,7 +67,7 @@ def blar
end
it "should use implicit class if omitted" do
- class ParParent < Sequel::Model
+ class ::ParParent < Sequel::Model
end
@c2.many_to_one :par_parent
@@ -79,7 +80,7 @@ class ParParent < Sequel::Model
end
it "should use class inside module if given as a string" do
- module Par
+ module ::Par
class Parent < Sequel::Model
end
end
@@ -284,8 +285,8 @@ def ds.fetch_rows(sql, &block)
it "should not create the setter method if :read_only option is used" do
@c2.many_to_one :parent, :class => @c2, :read_only=>true
- @c2.instance_methods.should(include('parent'))
- @c2.instance_methods.should_not(include('parent='))
+ @c2.instance_methods.collect{|x| x.to_s}.should(include('parent'))
+ @c2.instance_methods.collect{|x| x.to_s}.should_not(include('parent='))
end
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
it "should make the change to the foreign_key value inside a _association= method" do
@c2.many_to_one :parent, :class => @c2
- @c2.private_instance_methods.sort.should(include("_parent="))
+ @c2.private_instance_methods.collect{|x| x.to_s}.sort.should(include("_parent="))
p = @c2.new
c = @c2.load(:id=>123)
def p._parent=(x)
@@ -422,10 +423,12 @@ def ar(x)
MODEL_DB.reset
@c1 = Class.new(Sequel::Model(:attributes)) do
+ unrestrict_primary_key
columns :id, :node_id
end
@c2 = Class.new(Sequel::Model(:nodes)) do
+ unrestrict_primary_key
attr_accessor :xxx
def self.name; 'Node'; end
@@ -459,7 +462,7 @@ def fetch_rows(sql)
end
it "should use implicit class if omitted" do
- class HistoricalValue < Sequel::Model
+ class ::HistoricalValue < Sequel::Model
end
@c2.one_to_many :historical_values
@@ -472,7 +475,7 @@ class HistoricalValue < Sequel::Model
end
it "should use class inside a module if given as a string" do
- module Historical
+ module ::Historical
class Value < Sequel::Model
end
end
@@ -716,7 +719,7 @@ def a.valid?; false; end
it "should not create the add_, remove_, or remove_all_ methods if :read_only option is used" do
@c2.one_to_many :attributes, :class => @c1, :read_only=>true
- im = @c2.instance_methods
+ im = @c2.instance_methods.collect{|x| x.to_s}
im.should(include('attributes'))
im.should(include('attributes_dataset'))
im.should_not(include('add_attribute'))
@@ -827,7 +830,7 @@ def attrib.save!; self end
it "should not add a getter method if the :one_to_one option is true and :read_only option is true" do
@c2.one_to_many :attributes, :class => @c1, :one_to_one=>true, :read_only=>true
- im = @c2.instance_methods
+ im = @c2.instance_methods.collect{|x| x.to_s}
im.should(include('attribute'))
im.should_not(include('attribute='))
end
@@ -870,7 +873,7 @@ def d.fetch_rows(s); yield({:id=>3}) end
it "should make non getter and setter methods private if :one_to_one option is used" do
@c2.one_to_many :attributes, :class => @c1, :one_to_one=>true do |ds| end
- meths = @c2.private_instance_methods(false)
+ meths = @c2.private_instance_methods(false).collect{|x| x.to_s}
meths.should(include("attributes"))
meths.should(include("add_attribute"))
meths.should(include("attributes_dataset"))
@@ -878,7 +881,7 @@ def d.fetch_rows(s); yield({:id=>3}) end
it "should call an _add_ method internally to add attributes" do
@c2.one_to_many :attributes, :class => @c1
- @c2.private_instance_methods.sort.should(include("_add_attribute"))
+ @c2.private_instance_methods.collect{|x| x.to_s}.sort.should(include("_add_attribute"))
p = @c2.load(:id=>10)
c = @c1.load(:id=>123)
def p._add_attribute(x)
@@ -891,7 +894,7 @@ def p._add_attribute(x)
it "should call a _remove_ method internally to remove attributes" do
@c2.one_to_many :attributes, :class => @c1
- @c2.private_instance_methods.sort.should(include("_remove_attribute"))
+ @c2.private_instance_methods.collect{|x| x.to_s}.sort.should(include("_remove_attribute"))
p = @c2.load(:id=>10)
c = @c1.load(:id=>123)
def p._remove_attribute(x)
@@ -990,12 +993,14 @@ def @dataset.fetch_rows(sql)
MODEL_DB.reset
@c1 = Class.new(Sequel::Model(:attributes)) do
+ unrestrict_primary_key
def self.name; 'Attribute'; end
def self.to_s; 'Attribute'; end
columns :id
end
@c2 = Class.new(Sequel::Model(:nodes)) do
+ unrestrict_primary_key
attr_accessor :xxx
def self.name; 'Node'; end
@@ -1024,7 +1029,7 @@ def fetch_rows(sql)
end
it "should use implicit class if omitted" do
- class Tag < Sequel::Model
+ class ::Tag < Sequel::Model
end
@c2.many_to_many :tags
@@ -1036,7 +1041,7 @@ class Tag < Sequel::Model
end
it "should use class inside module if given as a string" do
- module Historical
+ module ::Historical
class Tag < Sequel::Model
end
end
@@ -1287,7 +1292,7 @@ class Tag < Sequel::Model
it "should not create the add_, remove_, or remove_all_ methods if :read_only option is used" do
@c2.many_to_many :attributes, :class => @c1, :read_only=>true
- im = @c2.instance_methods
+ im = @c2.instance_methods.collect{|x| x.to_s}
im.should(include('attributes'))
im.should(include('attributes_dataset'))
im.should_not(include('add_attribute'))
@@ -1353,7 +1358,7 @@ def d.fetch_rows(s); end
it "should call an _add_ method internally to add attributes" do
@c2.many_to_many :attributes, :class => @c1
- @c2.private_instance_methods.sort.should(include("_add_attribute"))
+ @c2.private_instance_methods.collect{|x| x.to_s}.sort.should(include("_add_attribute"))
p = @c2.load(:id=>10)
c = @c1.load(:id=>123)
def p._add_attribute(x)
@@ -1366,7 +1371,7 @@ def p._add_attribute(x)
it "should call a _remove_ method internally to remove attributes" do
@c2.many_to_many :attributes, :class => @c1
- @c2.private_instance_methods.sort.should(include("_remove_attribute"))
+ @c2.private_instance_methods.collect{|x| x.to_s}.sort.should(include("_remove_attribute"))
p = @c2.load(:id=>10)
c = @c1.load(:id=>123)
def p._remove_attribute(x)
View
3  spec/sequel_model/base_spec.rb
@@ -79,10 +79,11 @@
@c.create(:abc => 1)
@c.create(:abc => "hello")
+ x = [Marshal.dump("hello")].pack('m')
MODEL_DB.sqls.should == [ \
"INSERT INTO items (abc) VALUES ('BAhpBg==\n')", \
- "INSERT INTO items (abc) VALUES ('BAgiCmhlbGxv\n')", \
+ "INSERT INTO items (abc) VALUES ('#{x}')", \
]
end
View
24 spec/sequel_model/eager_loading_spec.rb
@@ -4,7 +4,7 @@
before(:each) do
MODEL_DB.reset
- class EagerAlbum < Sequel::Model(:albums)
+ class ::EagerAlbum < Sequel::Model(:albums)
columns :id, :band_id
many_to_one :band, :class=>'EagerBand', :key=>:band_id
one_to_many :tracks, :class=>'EagerTrack', :key=>:album_id
@@ -17,7 +17,7 @@ class EagerAlbum < Sequel::Model(:albums)
many_to_many :genre_names, :class=>'EagerGenre', :left_key=>:album_id, :right_key=>:genre_id, :join_table=>:ag, :select=>[:id]
end
- class EagerBand < Sequel::Model(:bands)
+ class ::EagerBand < Sequel::Model(:bands)
columns :id
one_to_many :albums, :class=>'EagerAlbum', :key=>:band_id, :eager=>:tracks
one_to_many :graph_albums, :class=>'EagerAlbum', :key=>:band_id, :eager_graph=>:tracks
@@ -32,17 +32,17 @@ class EagerBand < Sequel::Model(:bands)
one_to_many :top_10_albums, :class=>'EagerAlbum', :key=>:band_id, :limit=>10
end
- class EagerTrack < Sequel::Model(:tracks)
+ class ::EagerTrack < Sequel::Model(:tracks)
columns :id, :album_id
many_to_one :album, :class=>'EagerAlbum', :key=>:album_id
end
- class EagerGenre < Sequel::Model(:genres)
+ class ::EagerGenre < Sequel::Model(:genres)
columns :id
many_to_many :albums, :class=>'EagerAlbum', :left_key=>:genre_id, :right_key=>:album_id, :join_table=>:ag
end
- class EagerBandMember < Sequel::Model(:members)
+ class ::EagerBandMember < Sequel::Model(:members)
columns :id
many_to_many :bands, :class=>'EagerBand', :left_key=>:member_id, :right_key=>:band_id, :join_table=>:bm, :order =>:id
end
@@ -459,13 +459,13 @@ def fetch_rows(sql)
describe Sequel::Model, "#eager_graph" do
after(:all) do
- class MockDataset
+ class ::MockDataset
alias clone orig_clone
end
end
before(:all) do
- class MockDataset
+ class ::MockDataset
alias orig_clone clone
def clone(opts = {})
c = super()
@@ -475,7 +475,7 @@ def clone(opts = {})
end
end
- class GraphAlbum < Sequel::Model(:albums)
+ class ::GraphAlbum < Sequel::Model(:albums)
dataset.opts[:from] = [:albums]
columns :id, :band_id
many_to_one :band, :class=>'GraphBand', :key=>:band_id
@@ -484,7 +484,7 @@ class GraphAlbum < Sequel::Model(:albums)
many_to_one :previous_album, :class=>'GraphAlbum'
end
- class GraphBand < Sequel::Model(:bands)
+ class ::GraphBand < Sequel::Model(:bands)
dataset.opts[:from] = [:bands]
columns :id, :vocalist_id
many_to_one :vocalist, :class=>'GraphBandMember', :key=>:vocalist_id
@@ -493,19 +493,19 @@ class GraphBand < Sequel::Model(:bands)
many_to_many :genres, :class=>'GraphGenre', :left_key=>:band_id, :right_key=>:genre_id, :join_table=>:bg
end
- class GraphTrack < Sequel::Model(:tracks)
+ class ::GraphTrack < Sequel::Model(:tracks)
dataset.opts[:from] = [:tracks]
columns :id, :album_id
many_to_one :album, :class=>'GraphAlbum', :key=>:album_id
end
- class GraphGenre < Sequel::Model(:genres)
+ class ::GraphGenre < Sequel::Model(:genres)
dataset.opts[:from] = [:genres]
columns :id
many_to_many :albums, :class=>'GraphAlbum', :left_key=>:genre_id, :right_key=>:album_id, :join_table=>:ag
end
- class GraphBandMember < Sequel::Model(:members)
+ class ::GraphBandMember < Sequel::Model(:members)
dataset.opts[:from] = [:members]
columns :id
many_to_many :bands, :class=>'GraphBand', :left_key=>:member_id, :right_key=>:band_id, :join_table=>:bm
View
8 spec/sequel_model/hooks_spec.rb
@@ -349,24 +349,24 @@ def save!(*columns)
specify "should be called around validation" do
@c.before_validation{MODEL_DB << "BLAH before"}
- m = @c.new(:id => 2233)
+ m = @c.load(:id => 2233)
m.should be_valid
MODEL_DB.sqls.should == ['BLAH before', 'BLAH after']
MODEL_DB.sqls.clear
- m = @c.new(:id => 22)
+ m = @c.load(:id => 22)
m.should_not be_valid
MODEL_DB.sqls.should == ['BLAH before', 'BLAH after']
end
specify "should be called when calling save" do
@c.before_validation{MODEL_DB << "BLAH before"}
- m = @c.new(:id => 2233)
+ m = @c.load(:id => 2233)
m.save.should == m
MODEL_DB.sqls.should == ['BLAH before', 'BLAH after', 'CREATE BLAH']
MODEL_DB.sqls.clear
- m = @c.new(:id => 22)
+ m = @c.load(:id => 22)
m.raise_on_save_failure = false
m.save.should == nil
MODEL_DB.sqls.should == ['BLAH before', 'BLAH after']
View
22 spec/sequel_model/model_spec.rb
@@ -2,7 +2,7 @@
describe Sequel::Model do
it "should have class method aliased as model" do
- Sequel::Model.instance_methods.should include("model")
+ Sequel::Model.instance_methods.collect{|x| x.to_s}.should include("model")
model_a = Class.new(Sequel::Model(:items))
model_a.new.model.should be(model_a)
@@ -93,14 +93,14 @@
describe Sequel::Model, "#sti_key" do
before do
- class StiTest < Sequel::Model
+ class ::StiTest < Sequel::Model
def kind=(x); self[:kind] = x; end
def refresh; end
set_sti_key :kind
end
- class StiTestSub1 < StiTest
+ class ::StiTestSub1 < StiTest
end
- class StiTestSub2 < StiTest
+ class ::StiTestSub2 < StiTest
end
@ds = StiTest.dataset
MODEL_DB.reset
@@ -445,15 +445,15 @@ def @dataset.def_mutation_method(*names); end
it "should be created on set_dataset unless lazy loading schema" do
%w'x y x= y='.each do |x|
- @c.instance_methods.include?(x).should == false
+ @c.instance_methods.collect{|y| y.to_s}.should_not include(x)
end
@c.set_dataset(@dataset)
%w'x y x= y='.each do |x|
- @c.instance_methods.include?(x).should == true
+ @c.instance_methods.collect{|y| y.to_s}.should include(x)
end
o = @c.new
%w'x y x= y='.each do |x|
- o.methods.include?(x).should == true
+ o.methods.collect{|y| y.to_s}.should include(x)
end
o.x.should be_nil
@@ -464,18 +464,18 @@ def @dataset.def_mutation_method(*names); end
it "should be created on first initialization if lazy loading schema" do
Sequel::Model.lazy_load_schema = true
%w'x y x= y='.each do |x|
- @c.instance_methods.include?(x).should == false
+ @c.instance_methods.collect{|y| y.to_s}.should_not include(x)
end
@c.set_dataset(@dataset)
%w'x y x= y='.each do |x|
- @c.instance_methods.include?(x).should == false
+ @c.instance_methods.collect{|y| y.to_s}.should_not include(x)
end
o = @c.new
%w'x y x= y='.each do |x|
- @c.instance_methods.include?(x).should == true
+ @c.instance_methods.collect{|y| y.to_s}.should include(x)
end
%w'x y x= y='.each do |x|
- o.methods.include?(x).should == true
+ o.methods.collect{|y| y.to_s}.should include(x)
end
o.x.should be_nil
View
12 spec/sequel_model/record_spec.rb
@@ -33,7 +33,7 @@
end
it "should mark saved columns as not changed" do
- o = @c.new(:id => 3, :x => 1, :y => nil)
+ o = @c.load(:id => 3, :x => 1, :y => nil)
o[:y] = 4
o.changed_columns.should == [:y]
o.save(:x)
@@ -50,6 +50,7 @@
MODEL_DB.reset
@c = Class.new(Sequel::Model(:items)) do
+ unrestrict_primary_key
columns :id, :x, :y
end
end
@@ -110,6 +111,7 @@
MODEL_DB.reset
@c = Class.new(Sequel::Model(:items)) do
+ unrestrict_primary_key
columns :id, :x, :y
end
end
@@ -141,6 +143,7 @@
MODEL_DB.reset
@c = Class.new(Sequel::Model(:items)) do
+ unrestrict_primary_key
columns :id, :x, :y
end
end
@@ -176,6 +179,7 @@
MODEL_DB.reset
@c = Class.new(Sequel::Model(:items)) do
+ unrestrict_primary_key
end
end
@@ -722,6 +726,7 @@
before(:each) do
MODEL_DB.reset
@c = Class.new(Sequel::Model(:items)) do
+ unrestrict_primary_key
columns :x
end
end
@@ -740,7 +745,7 @@
it "should accept a block and run it" do
o1, o2, o3 = nil, nil, nil
- o = @c.create {|o3| o1 = o3; o2 = :blah; o3.x = 333}
+ o = @c.create {|o4| o1 = o4; o3 = o4; o2 = :blah; o3.x = 333}
o.class.should == @c
o1.should === o
o3.should === o
@@ -760,7 +765,8 @@
setup do
MODEL_DB.reset
@c = Class.new(Sequel::Model(:items)) do
- columns :x
+ unrestrict_primary_key
+ columns :id, :x
end
end
View
34 spec/sequel_model/validations_spec.rb
@@ -527,28 +527,28 @@ def dont_skip; true; end
describe Sequel::Model, "Validations" do
before(:all) do
- class Person < Sequel::Model
+ class ::Person < Sequel::Model
columns :id,:name,:first_name,:last_name,:middle_name,:initials,:age, :terms
end
- class Smurf < Person
+ class ::Smurf < Person
end
- class Cow < Sequel::Model
+ class ::Cow < Sequel::Model
columns :id, :name, :got_milk
end
- class User < Sequel::Model
+ class ::User < Sequel::Model
columns :id, :username, :password
end
- class Address < Sequel::Model
+ class ::Address < Sequel::Model
columns :id, :zip_code
end
end
it "should validate the acceptance of a column" do
- class Cow < Sequel::Model
+ class ::Cow < Sequel::Model
validations.clear
validates_acceptance_of :got_milk, :accept => 'blah', :allow_nil => false
end
@@ -562,7 +562,7 @@ class Cow < Sequel::Model
end
it "should validate the confirmation of a column" do
- class User < Sequel::Model
+ class ::User < Sequel::Model
def password_confirmation
"test"
end
@@ -580,7 +580,7 @@ def password_confirmation
end
it "should validate format of column" do
- class Person < Sequel::Model
+ class ::Person < Sequel::Model
validates_format_of :first_name, :with => /^[a-zA-Z]+$/
end
@@ -595,7 +595,7 @@ class Person < Sequel::Model
# end
it "should validate length of column" do
- class Person < Sequel::Model
+ class ::Person < Sequel::Model
validations.clear
validates_length_of :first_name, :maximum => 30
validates_length_of :last_name, :minimum => 30
@@ -627,7 +627,7 @@ class Person < Sequel::Model
end
it "should validate numericality of column" do
- class Person < Sequel::Model
+ class ::Person < Sequel::Model
validations.clear
validates_numericality_of :age
end
@@ -641,7 +641,7 @@ class Person < Sequel::Model
end
it "should validate the presence of a column" do
- class Cow < Sequel::Model
+ class ::Cow < Sequel::Model
validations.clear
validates_presence_of :name
end
@@ -655,7 +655,7 @@ class Cow < Sequel::Model
end
it "should validate the uniqueness of a column" do
- class User < Sequel::Model
+ class ::User < Sequel::Model
validations.clear
validates do
uniqueness_of :username
@@ -699,7 +699,7 @@ def fetch_rows(sql)
end
it "should have a validates block that contains multiple validations" do
- class Person < Sequel::Model
+ class ::Person < Sequel::Model
validations.clear
validates do
format_of :first_name, :with => /^[a-zA-Z]+$/
@@ -718,7 +718,7 @@ class Person < Sequel::Model
it "should allow 'longhand' validations direcly within the model." do
lambda {
- class Person < Sequel::Model
+ class ::Person < Sequel::Model
validations.clear
validates_length_of :first_name, :maximum => 30
end
@@ -727,7 +727,7 @@ class Person < Sequel::Model
end
it "should define a has_validations? method which returns true if the model has validations, false otherwise" do
- class Person < Sequel::Model
+ class ::Person < Sequel::Model
validations.clear
validates do
format_of :first_name, :with => /\w+/
@@ -735,7 +735,7 @@ class Person < Sequel::Model
end
end
- class Smurf < Person
+ class ::Smurf < Person
validations.clear
end
@@ -744,7 +744,7 @@ class Smurf < Person
end
it "should validate correctly instances initialized with string keys" do
- class Can < Sequel::Model
+ class ::Can < Sequel::Model
columns :id, :name
validates_length_of :name, :minimum => 4
Please sign in to comment.
Something went wrong with that request. Please try again.