diff --git a/lib/octopus/scope_proxy.rb b/lib/octopus/scope_proxy.rb index 6a2fcafa..0a674b6c 100644 --- a/lib/octopus/scope_proxy.rb +++ b/lib/octopus/scope_proxy.rb @@ -37,6 +37,10 @@ def method_missing(method, *args, &block) result end + def as_json(options = nil) + method_missing(:as_json, options) + end + # Delegates to method_missing (instead of @klass) so that User.using(:blah).where(:name => "Mike") # gets run in the correct shard context when #== is evaluated. def ==(*args) diff --git a/spec/octopus/model_spec.rb b/spec/octopus/model_spec.rb index fbac4e63..f96f82d6 100644 --- a/spec/octopus/model_spec.rb +++ b/spec/octopus/model_spec.rb @@ -414,6 +414,17 @@ User.using(:brazil).find_by_name("Joaquim").should_not be_nil end + it "as_json" do + ActiveRecord::Base.include_root_in_json = false + + Octopus.using(:brazil) do + User.create!(:name => "User1") + end + + user = User.using(:brazil).where(:name => "User1").first + user.as_json(:except => [:created_at, :updated_at, :id]).should eq({"admin"=>nil, "name"=>"User1", "number"=>nil}) + end + it "transaction" do u = User.create!(:name => "Thiago")