Permalink
Browse files

Fix a bug when ActiveRecord is loaded together with Broach.

The JSON gem and ActiveRecord accept different arguments on the to_json
method. This breaks when loading both and calling JSON.dump or JSON.generate
but not the calling object.to_json for some reason.
  • Loading branch information...
Manfred committed Dec 17, 2009
1 parent 4149643 commit 099a17f5a6815075b919ba70554d97b0385c098a
Showing with 41 additions and 16 deletions.
  1. +10 −13 Rakefile
  2. +3 −3 lib/broach/session.rb
  3. +19 −0 test/interaction/active_support_test.rb
  4. +9 −0 test/interaction/scripts/say_hi.rb
View
@@ -1,26 +1,23 @@
require 'rake/rdoctask'
-desc "Run all specs by default"
+TEST_CATEGORIES = [:remote, :interaction, :unit]
+
+desc "Run all unit specs by default"
task :default => 'test:unit'
namespace :test do
- desc "Run all remote tests"
- task :remote do
- Dir[File.dirname(__FILE__) + '/test/remote/*_test.rb'].each do |file|
- load file
- end
- end
-
- desc "Run all unit tests"
- task :unit do
- Dir[File.dirname(__FILE__) + '/test/unit/*_test.rb'].each do |file|
- load file
+ TEST_CATEGORIES.each do |category|
+ desc "Run all #{category} tests"
+ task category do
+ Dir[File.dirname(__FILE__) + "/test/#{category}/*_test.rb"].each do |file|
+ load file
+ end
end
end
end
desc "Run all specs"
-task :test => ['test:unit', 'test:remote']
+task :test => TEST_CATEGORIES.map { |category| "test:#{category}" }
namespace :gem do
desc "Build the gem"
View
@@ -39,7 +39,7 @@ def credentials
def get(path)
response = REST.get(url_for(path), headers_for(:get), credentials)
if response.ok?
- return JSON.parse(response.body)
+ JSON.parse(response.body)
else
handle_response(:get, path, response)
end
@@ -48,9 +48,9 @@ def get(path)
# Posts a resource to a certain path on the server. When the POST is successful
# the parsed body is returned, otherwise an exception is raised.
def post(path, payload)
- response = REST.post(url_for(path), JSON.dump(payload), headers_for(:post), credentials)
+ response = REST.post(url_for(path), payload.to_json, headers_for(:post), credentials)
if response.created?
- return JSON.parse(response.body)
+ JSON.parse(response.body)
else
handle_response(:post, path, response)
end
@@ -0,0 +1,19 @@
+require File.expand_path('../../start', __FILE__)
+
+require 'open3'
+require 'rbconfig'
+module InteractionSpecHelpers
+ def ruby(script)
+ ruby_bin = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
+ stdin, stdout, stderr = Open3.popen3("#{ruby_bin} #{script}")
+ stderr.read
+ end
+end
+
+describe "Broach, when ActiveSupport is loaded" do
+ extend InteractionSpecHelpers
+
+ it "should say hi in a room" do
+ ruby(File.expand_path('../scripts/say_hi.rb', __FILE__)).should == ''
+ end
+end
@@ -0,0 +1,9 @@
+require 'rubygems' rescue nil
+require 'active_support'
+require 'rest'
+
+$:.unshift File.expand_path('../../../../lib', __FILE__)
+require 'broach'
+
+Broach.settings = YAML.load_file(File.expand_path('../../../../settings.yml', __FILE__))
+Broach.speak(Broach.session.room, "Hi!")

0 comments on commit 099a17f

Please sign in to comment.