This file contains 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
From bd48a4b5b39a8fe6ede3570eac3d97b47af1fb84 Mon Sep 17 00:00:00 2001 | |
From: Vishnu Iyengar <[email protected]> | |
Date: Thu, 4 Feb 2010 18:14:19 +0530 | |
Subject: [PATCH] workaround with numeric validator to work with jruby | |
--- | |
.../dm-validations/validators/numeric_validator.rb | 4 ++++ | |
1 files changed, 4 insertions(+), 0 deletions(-) | |
diff --git a/dm-validations/lib/dm-validations/validators/numeric_validator.rb b/dm-validations/lib/dm-validations/validators/numeric_validator.rb |
This file contains 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
require File.expand_path('../../spec_helper', __FILE__) | |
describe "DataMapper Collections" do | |
class SuperHero | |
include DataMapper::Resource | |
property :id, Serial | |
property :status, Enum[:dead, :alive, :limbo], :required => true | |
end | |
SuperHero.auto_migrate! | |
This file contains 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
payment.get(5) | |
payment.status = "success" if payment.status = "pending" |
This file contains 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
Payment.all(:id => id, :status => "pending").update!(:status => "success") | |
# UPDATE "payments" SET "preauth_time" = '2010-03-13T13:02:45+05:30' WHERE ("id" = 1 AND "preauth_time" IS NULL) |
This file contains 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 Collection | |
def update!(attributes) | |
... | |
model = self.model | |
dirty_attributes = model.new(attributes).dirty_attributes | |
if dirty_attributes.empty? | |
true | |
elsif dirty_attributes.any? { |property, value| !property.valid?(value) } | |
false | |
else |
This file contains 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
module DataMapper | |
class Collection | |
def update!(attributes = {}) | |
assert_update_clean_only(:update!) | |
model = self.model | |
model_inst = model.new(attributes) | |
dirty_attributes = model_inst.dirty_attributes | |
if dirty_attributes.empty? |
This file contains 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
From 37e5373cf03468b4c9c6579ea82a0fcda4c4a3ca Mon Sep 17 00:00:00 2001 | |
From: Vishnu Iyengar <[email protected]> | |
Date: Sun, 21 Mar 2010 10:24:51 +0530 | |
Subject: [PATCH] updating collection#update! and resource _update to validate attributes similarly | |
--- | |
lib/dm-core/collection.rb | 6 +++--- | |
lib/dm-core/resource.rb | 34 ++++++++++++++++++++++------------ | |
2 files changed, 25 insertions(+), 15 deletions(-) |
This file contains 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
require 'json/pure' | |
require 'active_support' | |
JSON.dump(JSON.load('{"a":"b"}')) | |
NoMethodError: undefined method `except' for #<JSON::Pure::Generator::State:0x7d6b5518> | |
from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/json_pure-1.2.3/lib/json/pure/generator.rb:223:in `[]' | |
from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/json/encoders/hash.rb:45:in `as_json' | |
from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/json/encoders/hash.rb:34:in `to_json' | |
from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/json_pure-1.2.3/lib/json/common.rb:188:in `generate' |
This file contains 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
>> require 'json/pure' | |
=> true | |
>> require 'active_support' | |
=> true | |
>> JSON.dump(JSON.load('{"a":"b"}')) | |
NoMethodError: undefined method `except' for #<JSON::Pure::Generator::State:0x10232ebe8> | |
from /Library/Ruby/Gems/1.8/gems/json_pure-1.2.3/lib/json/pure/generator.rb:223:in `__send__' | |
from /Library/Ruby/Gems/1.8/gems/json_pure-1.2.3/lib/json/pure/generator.rb:223:in `[]' | |
from /Users/path/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/json/encoders/hash.rb:45:in `as_json' | |
from /Users/path/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/json/encoders/hash.rb:34:in `to_json' |
This file contains 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
describe "payment" do | |
prepend_before {@bypass_transactions = true} | |
it 'should hah' do | |
end | |
Spec::Runner.configure do |config| | |
config.before(:suite) do | |
DataMapper.auto_migrate! | |
end | |
config.after(:each) do |
OlderNewer