Permalink
Browse files

1.8.7 support first pass

  • Loading branch information...
1 parent a321936 commit dbe47779458c89bd87f095685a690373b0c3983c @tpitale committed Feb 17, 2012
View
@@ -3,3 +3,4 @@
Gemfile.lock
pkg/*
lib/demo.rb
+.rvmrc
View
@@ -1,5 +1,6 @@
language: ruby
rvm:
+ - 1.8.7
- 1.9.2
- 1.9.3
script: bundle exec rspec spec
View
@@ -27,5 +27,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "vcr", "2.0.0.beta2"
s.add_development_dependency "fakeweb"
+ s.add_runtime_dependency "multi_json"
s.add_runtime_dependency "oauth2"
end
View
@@ -1,7 +1,7 @@
require "legato/version"
-require 'json'
require 'oauth2'
+require 'multi_json'
require 'cgi'
require 'ostruct'
View
@@ -0,0 +1,5 @@
+module Legato
+ class Collection
+
+ end
+end
@@ -7,7 +7,7 @@ def base_uri
def all(user, path=default_path)
json = user.access_token.get(base_uri + path).body
- JSON.parse(json)['items'].map {|item| new(item, user)}
+ MultiJson.decode(json)['items'].map {|item| new(item, user)}
end
end
end
View
@@ -18,11 +18,11 @@ def filters
@filters ||= {}
end
- def filter(name, block)
+ def filter(name, &block)
filters[name] = block
(class << self; self; end).instance_eval do
- define_method(name) {|*args| Query.new(self).apply_filter(*args, block)}
+ define_method(name) {|*args| Query.new(self).apply_filter(*args, &block)}
end
end
View
@@ -4,9 +4,9 @@ class Query
MONTH = 2592000
- def define_filter(name, block)
+ def define_filter(name, &block)
(class << self; self; end).instance_eval do
- define_method(name) {|*args| apply_filter(*args, block)}
+ define_method(name) {|*args| apply_filter(*args, &block)}
end
end
@@ -33,7 +33,7 @@ def initialize(klass)
self.end_date = Time.now
klass.filters.each do |name, block|
- define_filter(name, block)
+ define_filter(name, &block)
end
# may add later for dynamic segments
@@ -42,7 +42,7 @@ def initialize(klass)
# end
end
- def apply_filter(*args, block)
+ def apply_filter(*args, &block)
@profile = extract_profile(args)
join_character = Legato.and_join_character # filters are joined by AND
View
@@ -11,7 +11,7 @@
# end
#
# def parsed_response
-# JSON.parse(raw_response)
+# MultiJson.decode(raw_response)
# end
#
# def raw_response
View
@@ -6,7 +6,7 @@ def initialize(raw_response, instance_klass = OpenStruct)
end
def data
- @data ||= JSON.parse(@raw_response.body)
+ @data ||= MultiJson.decode(@raw_response.body)
end
def collection
@@ -38,24 +38,24 @@ def new_model_class
end
it 'creates a class method' do
- @model.filter :high, @block
+ @model.filter :high, &@block
@model.respond_to?(:high).should be_true
end
it 'stores the filter' do
- @model.filter :high, @block
+ @model.filter :high, &@block
@model.filters[:high].should == @block
end
it 'returns a Query instance for a filter' do
query = stub(:apply_filter => "a query")
Legato::Query.stubs(:new).returns(query)
- @model.filter :high, @block
+ @model.filter :high, &@block
@model.high('arg1').should == 'a query'
Legato::Query.should have_received(:new).with(@model)
- query.should have_received(:apply_filter).with('arg1', @block)
+ query.should have_received(:apply_filter).with('arg1')
end
end
@@ -39,7 +39,7 @@ def self.it_defines_operators(*operators)
it "has filter methods that call apply with the given block" do
@query.stubs(:apply_filter)
@query.high('hi')
- @query.should have_received(:apply_filter).with('hi', @block)
+ @query.should have_received(:apply_filter).with('hi')
end
it 'does not load results by default' do
@@ -120,38 +120,38 @@ def self.it_defines_operators(*operators)
end
it 'returns the query' do
- @query.apply_filter(@block).should == @query
+ @query.apply_filter(&@block).should == @query
end
it 'executes the block' do
- @query.apply_filter(@block)
+ @query.apply_filter(&@block)
@query.should have_received(:eql).with(:key, 1000)
end
it 'accepts a profile as the first argument' do
profile = Legato::Management::Profile.new({}, stub)
- @query.apply_filter(profile, @block)
+ @query.apply_filter(profile, &@block)
@query.should have_received(:eql)
@query.profile.should == profile
end
it 'accepts a profile as the last argument' do
profile = Legato::Management::Profile.new({}, stub)
block_with_arg = lambda {|count| eql(:key, count)}
- @query.apply_filter(100, profile, block_with_arg)
+ @query.apply_filter(100, profile, &block_with_arg)
@query.should have_received(:eql).with(:key, 100)
@query.profile.should == profile
end
it 'does not override the existing profile if none is provide' do
@query.profile = Legato::Management::Profile.new({}, stub)
block_with_arg = lambda {|count| eql(:key, count)}
- @query.apply_filter(100, block_with_arg)
+ @query.apply_filter(100, &block_with_arg)
@query.profile.should_not == nil
end
it 'adds to the filter set' do
- @query.apply_filter(@block)
+ @query.apply_filter(&@block)
@filters.should have_received(:<<).with(@filter)
end
@@ -160,7 +160,7 @@ def self.it_defines_operators(*operators)
block = lambda {|*browsers| browsers.map {|browser| eql(:browser, browser)}}
@filter.stubs(:join_character=)
- @query.apply_filter('chrome', 'safari', block)
+ @query.apply_filter('chrome', 'safari', &block)
@filter.should have_received(:join_character=).with(Legato.and_join_character)
@filter.should have_received(:join_character=).with(Legato.or_join_character)
@@ -1,6 +1,6 @@
shared_examples_for "a management finder" do
it "returns an array of all #{subject_class_name} available to a user" do
- JSON.stubs(:parse).returns({'items' => ['item1', 'item2']})
+ MultiJson.stubs(:decode).returns({'items' => ['item1', 'item2']})
response = stub(:body => 'some json')
access_token = stub(:get => response)
user = stub(:access_token => access_token)
@@ -11,7 +11,7 @@
user.should have_received(:access_token)
access_token.should have_received(:get).with('https://www.googleapis.com/analytics/v3/management'+described_class.default_path)
response.should have_received(:body)
- JSON.should have_received(:parse).with('some json')
+ MultiJson.should have_received(:decode).with('some json')
described_class.should have_received(:new).with('item1', user)
described_class.should have_received(:new).with('item2', user)
end

0 comments on commit dbe4777

Please sign in to comment.