Skip to content

Commit

Permalink
Fixing as_json method for ScopeProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagopradi committed Oct 15, 2013
1 parent 72a1715 commit 1d04302
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/octopus/scope_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions spec/octopus/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 1d04302

Please sign in to comment.