Skip to content

Commit

Permalink
separating and isolating json specs a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Plentz committed Sep 20, 2011
1 parent 7986f74 commit 8c22492
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -3,6 +3,8 @@ source 'http://rubygems.org'
gem 'rails', '3.1.0'
gem 'rspec-rails'

gem 'multi_json'

gem 'sqlite3-ruby', :platforms => :ruby

platforms :jruby do
Expand Down
11 changes: 6 additions & 5 deletions Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/nicksieger/activerecord-jdbc-adapter.git
revision: 9a34f861abc42d0d3ae3a6d699d5614253421f9e
revision: fc54124b9ebec41e609646526b8bd97c708e20d5
specs:
activerecord-jdbc-adapter (1.2.0)
activerecord-jdbcsqlite3-adapter (1.2.0)
Expand Down Expand Up @@ -41,8 +41,8 @@ GEM
activesupport (3.1.0)
multi_json (~> 1.0)
arel (2.2.1)
bcrypt-ruby (3.0.0)
bcrypt-ruby (3.0.0-java)
bcrypt-ruby (3.0.1)
bcrypt-ruby (3.0.1-java)
builder (3.0.0)
diff-lcs (1.1.3)
erubis (2.7.0)
Expand All @@ -55,7 +55,7 @@ GEM
mime-types (1.16)
multi_json (1.0.3)
polyglot (0.3.2)
rack (1.3.2)
rack (1.3.3)
rack-cache (1.0.3)
rack (>= 0.4)
rack-mount (0.8.3)
Expand Down Expand Up @@ -97,7 +97,7 @@ GEM
sprockets (2.0.0)
hike (~> 1.2)
rack (~> 1.0)
tilt (!= 1.3.0, ~> 1.1)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.4)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
Expand All @@ -115,6 +115,7 @@ PLATFORMS
DEPENDENCIES
activerecord-jdbc-adapter!
activerecord-jdbcsqlite3-adapter
multi_json
rails (= 3.1.0)
rspec-rails
sqlite3-ruby
5 changes: 0 additions & 5 deletions spec/models/foo_spec.rb
@@ -1,16 +1,11 @@
# encoding: UTF-8

require 'spec_helper'
require 'multi_json'

describe Foo do
it "should do the right interpolation for error messages" do
foo = Foo.new
foo.valid?
lambda{I18n.t("errors.messages.record_invalid", :errors => foo.errors.full_messages)}.should_not raise_error
end

it "should decode json even with special chars" do
MultiJson.decode({:message => "á"}.to_json)['message'].should eq "á"
end
end
20 changes: 20 additions & 0 deletions spec/models/json_spec.rb
@@ -0,0 +1,20 @@
# encoding: UTF-8

require 'spec_helper'
require 'multi_json'

describe "jruby json" do
#fail
it "should decode json even with special chars using to_json" do
MultiJson.decode({:message => "á"}.to_json)['message'].should eq "á"
end

#works
it "should decode json even with special chars using a json string directly" do
MultiJson.decode("{\"message\":\"á\"}")['message'].should eq "á"
end

it "should generate equals jsons" do
({:message => "á"}).to_json.should == "{\"message\":\"á\"}"
end
end

0 comments on commit 8c22492

Please sign in to comment.