This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class << self; self; end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> Product.properties[:created_at].type | |
=> DateTime | |
>> Product.properties[:deleted_at].type | |
=> DataMapper::Types::ParanoidDateTime | |
>> Product.properties[:type].type | |
=> #<Class:0x5cf2ec> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# auto_validate.rb | |
require "dm-types" # not sure of that... | |
if property.type.ancestors.include?(Types::Enum) | |
validates_within property.name, options_with_message({:set => property.type.flag_map.values}, property, :within) | |
end | |
# auto -validate_spec | |
describe 'for Enum properties' do | |
require 'dm-types' # not sure if it is ok to require dm-types here | |
before :all do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if defined?(Validate) | |
module Validate | |
module AutoValidate | |
alias :orig_auto_generate_validations, :auto_generate_validations | |
def auto_generate_validations(property) | |
orig_auto_generate_validations(property) | |
return unless property.options[:auto_validation] | |
if property.type.ancestors.include?(Types::Enum) | |
validates_within property.name, options_with_message({:set => property.type.flag_map.values}, property, :within) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> Company.new(:trade_id => 1).trade | |
Sun, 03 Aug 2008 14:57:20 GMT ~ debug ~ SELECT "id", "name" FROM "trades" WHERE "id" IS NULL ORDER BY "id" | |
Sun, 03 Aug 2008 14:57:20 GMT ~ debug ~ SELECT "id", "name" FROM "trades" WHERE "id" IS NULL ORDER BY "id" | |
Sun, 03 Aug 2008 14:57:20 GMT ~ debug ~ SELECT "id", "name" FROM "trades" WHERE "id" IS NULL ORDER BY "id" | |
Sun, 03 Aug 2008 14:57:20 GMT ~ debug ~ SELECT "id", "name" FROM "trades" WHERE "id" IS NULL ORDER BY "id" | |
Sun, 03 Aug 2008 14:57:20 GMT ~ debug ~ SELECT "id", "name" FROM "trades" WHERE "id" IS NULL ORDER BY "id" | |
Sun, 03 Aug 2008 14:57:20 GMT ~ debug ~ SELECT "id", "name" FROM "trades" WHERE "id" IS NULL ORDER BY "id" | |
Sun, 03 Aug 2008 14:57:20 GMT ~ debug ~ SELECT "id", "name" FROM "trades" WHERE "id" IS NULL ORDER BY "id" | |
Sun, 03 Aug 2008 14:57:20 GMT ~ debug ~ SELECT "id", "name" FROM "trades" WHERE "id" IS NULL ORDER BY "id" | |
Sun, 03 Aug 2008 14:57:20 GMT ~ debug ~ SELECT "id", "name" FROM "trades" WHERE "id" IS NULL ORDER BY "id" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "should have machine when created using machine_id" do | |
pending | |
m = Machine.create(:name => 'machineX') | |
a = Area.new(:machine_id => m.id) | |
a.machine.should == m | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before(:each) do | |
Opinion.auto_migrate! | |
@luke_skywalker = mock('luke') | |
@luke_skywalker.stub!(:new_record?).and_return(false) | |
@luke_skywalker.stub!(:attribute_loaded?).with(:id).and_return(true) | |
@death_star = mock('death_star') | |
@death_star.stub!(:new_record?).and_return(false) | |
@death_star.stub!(:attribute_loaded?).with(:id).and_return(true) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def append_before(*args, &block) | |
scope, options = scope_and_options(*args) | |
parts = before_parts_from_scope(scope) | |
parts << proc { DataObjects::Postgres.logger.level = :off } | |
parts << block | |
parts << proc { DataObjects::Postgres.logger.level = :debug } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "should have same object_id" do | |
t = Team.create(:name => 'blah') | |
p = Player.create(:name => 'foo baz', :team => t) | |
t.players.first.object_id.should == p.object_id # fails | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> c.products.opinions | |
Tue, 05 Aug 2008 06:26:08 GMT ~ debug ~ SELECT "id", "type", "name", "category_id", "created_at", "updated_at", "owner_id" FROM "products" WHERE "deleted_at" IS NULL AND "owner_id" IN (1) ORDER BY "id" | |
Tue, 05 Aug 2008 06:26:08 GMT ~ debug ~ SELECT "opinions"."id", "opinions"."rank", "opinions"."status", "opinions"."verification_hash", "opinions"."created_at", "opinions"."updated_at", "opinions"."purchased_at", "opinions"."satisfaction", "opinions"."accordance", "opinions"."author_id" FROM "opinions" INNER JOIN "products" ON "products"."id" = "opinions"."product_id" WHERE "opinions"."deleted_at" IS NULL AND "products"."deleted_at" IS NULL AND "products"."owner_id" = 1 ORDER BY "opinions"."id" | |
Tue, 05 Aug 2008 06:26:08 GMT ~ debug ~ SELECT "opinions"."product_id", "opinions"."id" FROM "opinions" INNER JOIN "products" ON "products"."id" = "opinions"."product_id" WHERE "opinions"."deleted_at" IS NULL AND "products"."deleted_at" IS NULL AND "products"."owner_id" = 1 AND "opinions"."id" I |
OlderNewer