Permalink
Browse files

Fix for scoping issue (was creating/replacing methods on module inste…

…ad of on objects).

Bumped version number to 0.6.3
Updated README to reflect that the known issue with scoping has been fixed.
  • Loading branch information...
1 parent 4861ea5 commit a067265ab40d96176ac402e2a8b95ac8077851c3 Jen-Mei Wu committed Dec 10, 2010
View
@@ -1,5 +1,6 @@
source :gemcutter
-# Specify your gem's dependencies in ruby-satisfaction.gemspec
+# Dependencies are specified in ruby-satisfaction.gemspec; the following statement
+# pulls info from the gemspec.
gemspec
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- ruby-satisfaction (0.6.0)
+ ruby-satisfaction (0.6.1)
activesupport (~> 2.3)
json (>= 1.4.6)
memcache-client (>= 1.5.0)
@@ -16,6 +16,7 @@ GEM
configuration (1.2.0)
diff-lcs (1.1.2)
fakeweb (1.3.0)
+ gemcutter (0.6.1)
json (1.4.6)
launchy (0.3.7)
configuration (>= 0.0.5)
@@ -27,6 +28,7 @@ GEM
open_gem (1.4.2)
launchy (~> 0.3.5)
rake (0.8.7)
+ rr (1.0.2)
rspec (2.2.0)
rspec-core (~> 2.2)
rspec-expectations (~> 2.2)
@@ -48,11 +50,13 @@ DEPENDENCIES
activesupport (~> 2.3)
bundler (>= 1.0.0)
fakeweb (~> 1.3)
+ gemcutter (>= 0.6.1)
json (>= 1.4.6)
memcache-client (>= 1.5.0)
nokogiri (>= 1.4.2)
oauth (>= 0.3.5)
open_gem (>= 1.4)
+ rr (= 1.0.2)
rspec (~> 2.2)
ruby-debug (>= 0.10.4)
ruby-satisfaction!
View
@@ -9,28 +9,22 @@ Please check our Web site for the latest documentation:
For questions, please visit the [Get Satisfaction API community][3]
-Known Issues
-============
-
-If you use your Satisfaction object to get a person, then that object is scoped to that person.
-
-For example:
-
- sfn = Satisfaction.new
- person = sfn.peson.get('jargon')
- topics = sfn.topics.page(3, :order => 'recently_created') # Jargon's topics
+Changelog
+=========
-In the above case, topics will be scoped to topics created by Jargon instead of scoped to the
-top level. A simple workaround for now is to create a new Satisfaction object like so:
+0.6.2
- sfn = Satisfaction.new
- person = sfn.peson.get('jargon')
+* Fixed known issue with scoping. Calling resource methods could potentially change scope for
+ other objects. For example:
- sfn = Satisfaction.new
- topics = sfn.topics.page(3, :order => 'recently_created') # Everyone's topics
+ sfn = Satisfaction.new
+ sfn2 = Satisfaction.new
+ person = sfn.peson.get('jargon')
+ topics = sfn.topics.page(3, :order => 'recently_created') # Jargon's topics
+ sfn2.topics # Also Jargon's topics
-Changelog
-=========
+ This now behaves as expected (where topics and sfn2.topics would be scoped to the set of all i
+ topics)
0.6.0
@@ -2,7 +2,7 @@ module Associations
def has_many(resource, options={})
class_name = options[:class_name] || "Sfn::#{resource.to_s.classify}"
eval <<-EOS
- def #{resource}
+ def self.#{resource}
@#{resource} ||= Sfn::ResourceCollection.new(#{class_name}, self.satisfaction, '#{options[:url]}')
end
EOS
@@ -12,9 +12,9 @@ def belongs_to(resource, options={})
class_name = options[:class_name] || "Sfn::#{resource.to_s.classify}"
parent_id = options[:parent_attribute] || "#{resource}_id"
eval <<-EOS
- def #{resource}
+ def self.#{resource}
@#{resource} ||= #{class_name}.new(#{parent_id}, self.satisfaction)
end
EOS
end
-end
+end
@@ -2,8 +2,8 @@ module Satisfaction
module VERSION
MAJOR = 0
MINOR = 6
- PATCH = 1
- PRE = ""
+ PATCH = 3
+ PRE = nil
STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
end
@@ -3,13 +3,13 @@ require File.expand_path("../lib/satisfaction/version", __FILE__)
Gem::Specification.new do |s|
s.name = "ruby-satisfaction"
- s.version = '0.6.1'
+ s.version = Satisfaction::VERSION::STRING
s.platform = Gem::Platform::RUBY
s.author = 'Get Satisfaction'
s.email = ["nerds+rubygems@getsatisfaction.com"]
s.homepage = "https://github.com/satisfaction/ruby-satisfaction"
s.summary = "Get Satisfaction ruby client"
- s.description = "Get Satisfaction is a simple way to build online communities that enable productive conversations between companies and their customers. More than 46,000 companies use Get Satisfaction to provide a more social support experience, build better products, increase SEO and improve customer loyalty. Get Satisfaction communities are available at http://getsatisfaction.com."
+ s.description = "Ruby client for using Get Satisfaction's RESTful API. Get Satisfaction is a simple way to build online communities that enable productive conversations between companies and their customers. More than 46,000 companies use Get Satisfaction to provide a more social support experience, build better products, increase SEO and improve customer loyalty. Get Satisfaction communities are available at http://getsatisfaction.com."
s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "ruby-satisfaction"
@@ -21,10 +21,12 @@ Gem::Specification.new do |s|
s.add_dependency 'oauth', '>= 0.3.5'
s.add_development_dependency "bundler", ">= 1.0.0"
+ s.add_development_dependency "gemcutter", ">= 0.6.1"
s.add_development_dependency "rspec", "~> 2.2"
s.add_development_dependency "fakeweb", "~> 1.3"
s.add_development_dependency "open_gem", ">= 1.4"
s.add_development_dependency "ruby-debug", ">= 0.10.4"
+ s.add_development_dependency "rr", '1.0.2'
s.extra_rdoc_files = [ "README.markdown" ]
s.files = `git ls-files`.split("\n") - ['.rvmrc', '.gitignore']
@@ -0,0 +1,58 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe "Associations" do
+ describe "when included in a class" do
+ attr_reader :klass, :obj
+
+ before(:each) do
+ @klass = Class.new
+ @klass.class_eval do
+ include Associations
+ end
+ @obj = @klass.new
+ end
+
+ describe "#has_many" do
+ before(:each) do
+ klass.instance_methods.should_not include("topics")
+ Associations.instance_methods.should_not include("topics")
+ obj.methods.should_not include("topics")
+ obj.has_many :topics, :url => "/path/topics"
+ end
+
+ it "should create a method on the object the method is invoked on" do
+ obj.methods.should include("topics")
+ end
+
+ it "should not create an instance method on the including class" do
+ klass.instance_methods.should_not include("topics")
+ end
+
+ it "should not create an instance method on Associations" do
+ Associations.instance_methods.should_not include("topics")
+ end
+
+ end
+
+ describe "#belongs_to" do
+ before(:each) do
+ klass.instance_methods.should_not include("company")
+ Associations.instance_methods.should_not include("company")
+ obj.methods.should_not include("company")
+ obj.belongs_to :company, :url => "/path/company"
+ end
+
+ it "should create a method on the object the method is invoked on" do
+ obj.methods.should include("company")
+ end
+
+ it "should create an instance method on the including class" do
+ klass.instance_methods.should_not include("company")
+ end
+
+ it "should not create an instance method on Associations" do
+ Associations.instance_methods.should_not include("company")
+ end
+ end
+ end
+end

0 comments on commit a067265

Please sign in to comment.