tagcrumbs 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/License.txt +22 -0
- data/Manifest.txt +177 -0
- data/PostInstall.txt +2 -0
- data/README.rdoc +45 -0
- data/Rakefile +35 -0
- data/TODO.txt +17 -0
- data/bin/tagcrumbs +5 -0
- data/examples/address_update.rb +15 -0
- data/examples/comment_new.rb +19 -0
- data/examples/favorite_new.rb +17 -0
- data/examples/filter_new.rb +15 -0
- data/examples/friendship_create.rb +19 -0
- data/examples/link_new.rb +16 -0
- data/examples/location_update.rb +16 -0
- data/examples/picture_update.rb +16 -0
- data/examples/placemark_new_simple.rb +24 -0
- data/examples/placemark_new_suggestions.rb +24 -0
- data/examples/profile_link_new.rb +14 -0
- data/examples/profile_update.rb +12 -0
- data/examples/request_authorization.rb +25 -0
- data/examples/settings_update.rb +12 -0
- data/examples/subscription_new.rb +15 -0
- data/examples/tagcrumbs_find.rb +25 -0
- data/examples/tagcrumbs_search.rb +7 -0
- data/examples/user.rb +28 -0
- data/examples/user_recommendation_new.rb +15 -0
- data/lib/tagcrumbs/builders/builder.rb +45 -0
- data/lib/tagcrumbs/builders/json_builder.rb +38 -0
- data/lib/tagcrumbs/builders/xml_builder.rb +30 -0
- data/lib/tagcrumbs/cli.rb +268 -0
- data/lib/tagcrumbs/config_store.rb +35 -0
- data/lib/tagcrumbs/exceptions.rb +13 -0
- data/lib/tagcrumbs/node.rb +43 -0
- data/lib/tagcrumbs/parsers/json_parser.rb +79 -0
- data/lib/tagcrumbs/parsers/parser.rb +24 -0
- data/lib/tagcrumbs/parsers/xml_parser.rb +54 -0
- data/lib/tagcrumbs/proxy.rb +32 -0
- data/lib/tagcrumbs/requestor.rb +140 -0
- data/lib/tagcrumbs/resources/array.rb +108 -0
- data/lib/tagcrumbs/resources/models/accessors.rb +252 -0
- data/lib/tagcrumbs/resources/models/activity.rb +19 -0
- data/lib/tagcrumbs/resources/models/address.rb +16 -0
- data/lib/tagcrumbs/resources/models/city.rb +13 -0
- data/lib/tagcrumbs/resources/models/comment.rb +12 -0
- data/lib/tagcrumbs/resources/models/country.rb +15 -0
- data/lib/tagcrumbs/resources/models/fanship.rb +12 -0
- data/lib/tagcrumbs/resources/models/favorite.rb +22 -0
- data/lib/tagcrumbs/resources/models/filter.rb +32 -0
- data/lib/tagcrumbs/resources/models/flag.rb +10 -0
- data/lib/tagcrumbs/resources/models/friendship.rb +12 -0
- data/lib/tagcrumbs/resources/models/geoname.rb +8 -0
- data/lib/tagcrumbs/resources/models/link.rb +13 -0
- data/lib/tagcrumbs/resources/models/location.rb +13 -0
- data/lib/tagcrumbs/resources/models/model.rb +148 -0
- data/lib/tagcrumbs/resources/models/picture.rb +28 -0
- data/lib/tagcrumbs/resources/models/place.rb +17 -0
- data/lib/tagcrumbs/resources/models/placemark.rb +30 -0
- data/lib/tagcrumbs/resources/models/profile.rb +16 -0
- data/lib/tagcrumbs/resources/models/profile_link.rb +12 -0
- data/lib/tagcrumbs/resources/models/root.rb +19 -0
- data/lib/tagcrumbs/resources/models/settings.rb +14 -0
- data/lib/tagcrumbs/resources/models/state.rb +14 -0
- data/lib/tagcrumbs/resources/models/subscription.rb +13 -0
- data/lib/tagcrumbs/resources/models/suggestions.rb +11 -0
- data/lib/tagcrumbs/resources/models/tag.rb +6 -0
- data/lib/tagcrumbs/resources/models/tagcrumb.rb +58 -0
- data/lib/tagcrumbs/resources/models/user.rb +101 -0
- data/lib/tagcrumbs/resources/models/user_recommendation.rb +18 -0
- data/lib/tagcrumbs/resources/resource.rb +76 -0
- data/lib/tagcrumbs/validations.rb +301 -0
- data/lib/tagcrumbs.rb +232 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/fixtures/activity.json +210 -0
- data/spec/fixtures/activity.xml +66 -0
- data/spec/fixtures/address.json +183 -0
- data/spec/fixtures/address.xml +58 -0
- data/spec/fixtures/city.json +88 -0
- data/spec/fixtures/city.xml +34 -0
- data/spec/fixtures/comment.json +286 -0
- data/spec/fixtures/comment.xml +87 -0
- data/spec/fixtures/country.json +32 -0
- data/spec/fixtures/country.xml +13 -0
- data/spec/fixtures/fanship.json +180 -0
- data/spec/fixtures/fanship.xml +54 -0
- data/spec/fixtures/favorite.json +332 -0
- data/spec/fixtures/favorite.xml +109 -0
- data/spec/fixtures/filter.json +243 -0
- data/spec/fixtures/filter.xml +80 -0
- data/spec/fixtures/friendship.json +180 -0
- data/spec/fixtures/friendship.xml +54 -0
- data/spec/fixtures/geoname.json +18 -0
- data/spec/fixtures/geoname.xml +6 -0
- data/spec/fixtures/json_parser.json +25 -0
- data/spec/fixtures/link.json +288 -0
- data/spec/fixtures/link.xml +88 -0
- data/spec/fixtures/location.json +204 -0
- data/spec/fixtures/location.xml +71 -0
- data/spec/fixtures/picture.json +154 -0
- data/spec/fixtures/picture.png +0 -0
- data/spec/fixtures/picture.xml +49 -0
- data/spec/fixtures/placemark.json +357 -0
- data/spec/fixtures/placemark.xml +58 -0
- data/spec/fixtures/placemarks.json +887 -0
- data/spec/fixtures/placemarks.xml +348 -0
- data/spec/fixtures/profile.json +282 -0
- data/spec/fixtures/profile.xml +100 -0
- data/spec/fixtures/profile_link.json +156 -0
- data/spec/fixtures/profile_link.xml +49 -0
- data/spec/fixtures/root.json +46 -0
- data/spec/fixtures/root.xml +14 -0
- data/spec/fixtures/settings.json +147 -0
- data/spec/fixtures/settings.xml +45 -0
- data/spec/fixtures/state.json +62 -0
- data/spec/fixtures/state.xml +23 -0
- data/spec/fixtures/subscription.json +283 -0
- data/spec/fixtures/subscription.xml +86 -0
- data/spec/fixtures/suggestions.json +1877 -0
- data/spec/fixtures/suggestions.xml +724 -0
- data/spec/fixtures/tag.json +9 -0
- data/spec/fixtures/tag.xml +4 -0
- data/spec/fixtures/user.json +105 -0
- data/spec/fixtures/user.xml +31 -0
- data/spec/fixtures/user_recommendation.json +349 -0
- data/spec/fixtures/user_recommendation.xml +106 -0
- data/spec/fixtures/validation_errors.json +5 -0
- data/spec/fixtures/validation_errors.xml +5 -0
- data/spec/fixtures/xml_parser.xml +13 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +75 -0
- data/spec/tagcrumbs/builders/builder_spec.rb +57 -0
- data/spec/tagcrumbs/builders/json_builder_spec.rb +47 -0
- data/spec/tagcrumbs/builders/xml_builder_spec.rb +34 -0
- data/spec/tagcrumbs/exceptions_spec.rb +16 -0
- data/spec/tagcrumbs/node_spec.rb +42 -0
- data/spec/tagcrumbs/parsers/json_parser_spec.rb +117 -0
- data/spec/tagcrumbs/parsers/parser_spec.rb +25 -0
- data/spec/tagcrumbs/parsers/xml_parser_spec.rb +117 -0
- data/spec/tagcrumbs/proxy_spec.rb +48 -0
- data/spec/tagcrumbs/requestor_spec.rb +62 -0
- data/spec/tagcrumbs/resources/array_spec.rb +62 -0
- data/spec/tagcrumbs/resources/models/accessors_spec.rb +123 -0
- data/spec/tagcrumbs/resources/models/activity_spec.rb +33 -0
- data/spec/tagcrumbs/resources/models/address_spec.rb +24 -0
- data/spec/tagcrumbs/resources/models/city_spec.rb +33 -0
- data/spec/tagcrumbs/resources/models/comment_spec.rb +23 -0
- data/spec/tagcrumbs/resources/models/country_spec.rb +26 -0
- data/spec/tagcrumbs/resources/models/fanship_spec.rb +28 -0
- data/spec/tagcrumbs/resources/models/favorite_spec.rb +28 -0
- data/spec/tagcrumbs/resources/models/filter_spec.rb +43 -0
- data/spec/tagcrumbs/resources/models/flag_spec.rb +5 -0
- data/spec/tagcrumbs/resources/models/friendship_spec.rb +28 -0
- data/spec/tagcrumbs/resources/models/geoname_spec.rb +18 -0
- data/spec/tagcrumbs/resources/models/link_spec.rb +24 -0
- data/spec/tagcrumbs/resources/models/location_spec.rb +28 -0
- data/spec/tagcrumbs/resources/models/model_spec.rb +27 -0
- data/spec/tagcrumbs/resources/models/picture_spec.rb +42 -0
- data/spec/tagcrumbs/resources/models/place_spec.rb +12 -0
- data/spec/tagcrumbs/resources/models/placemark_spec.rb +61 -0
- data/spec/tagcrumbs/resources/models/profile_link_spec.rb +29 -0
- data/spec/tagcrumbs/resources/models/profile_spec.rb +43 -0
- data/spec/tagcrumbs/resources/models/root_spec.rb +57 -0
- data/spec/tagcrumbs/resources/models/settings_spec.rb +32 -0
- data/spec/tagcrumbs/resources/models/state_spec.rb +30 -0
- data/spec/tagcrumbs/resources/models/subscription_spec.rb +28 -0
- data/spec/tagcrumbs/resources/models/suggestions_spec.rb +33 -0
- data/spec/tagcrumbs/resources/models/tag_spec.rb +16 -0
- data/spec/tagcrumbs/resources/models/tagcrumb_spec.rb +21 -0
- data/spec/tagcrumbs/resources/models/user_recommendation_spec.rb +35 -0
- data/spec/tagcrumbs/resources/models/user_spec.rb +128 -0
- data/spec/tagcrumbs/resources/resource_spec.rb +62 -0
- data/spec/tagcrumbs/validations_spec.rb +27 -0
- data/spec/tagcrumbs_spec.rb +103 -0
- data/tagcrumbs.gemspec +59 -0
- data/tasks/rspec.rake +21 -0
- metadata +327 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'spec'
|
5
|
+
rescue LoadError
|
6
|
+
require 'rubygems'
|
7
|
+
gem 'rspec'
|
8
|
+
require 'spec'
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
gem 'chrisk-fakeweb', "1.2.0"
|
13
|
+
require 'fakeweb'
|
14
|
+
|
15
|
+
|
16
|
+
dir = File.dirname(__FILE__)
|
17
|
+
|
18
|
+
$:.unshift(File.join(dir, '/../lib/'))
|
19
|
+
require dir + '/../lib/tagcrumbs'
|
20
|
+
|
21
|
+
|
22
|
+
FakeWeb.allow_net_connect = false
|
23
|
+
|
24
|
+
# needed to get FakeWeb to work
|
25
|
+
class NilClass
|
26
|
+
def dump
|
27
|
+
''
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def fixture_file(filename, format = nil)
|
33
|
+
return '' if filename == ''
|
34
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
|
35
|
+
file_path += ".#{format}" if format
|
36
|
+
File.read(file_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def tagcrumbs_url(url, format=nil)
|
40
|
+
if url =~ /^http/
|
41
|
+
u = url
|
42
|
+
else
|
43
|
+
u = "http://www.tagcrumbs.com#{url}"
|
44
|
+
end
|
45
|
+
|
46
|
+
u += ".#{format}" if format
|
47
|
+
|
48
|
+
u
|
49
|
+
end
|
50
|
+
|
51
|
+
# needed to also test it with dev server
|
52
|
+
def fakeweb_url(url, format=nil)
|
53
|
+
if url =~ /^http/
|
54
|
+
u = url
|
55
|
+
else
|
56
|
+
u = "#{Tagcrumbs.options[:consumer_options][:site]}#{url}"
|
57
|
+
end
|
58
|
+
|
59
|
+
u += ".#{format}" if format
|
60
|
+
|
61
|
+
u
|
62
|
+
end
|
63
|
+
|
64
|
+
def stub_get(url, filename, status=nil)
|
65
|
+
options = {:string => fixture_file(filename)}
|
66
|
+
options.merge!({:status => status}) unless status.nil?
|
67
|
+
|
68
|
+
FakeWeb.register_uri(:get, fakeweb_url(url), options)
|
69
|
+
end
|
70
|
+
|
71
|
+
def stub_post(url, filename)
|
72
|
+
FakeWeb.register_uri(:post, fakeweb_url(url), :string => fixture_file(filename))
|
73
|
+
end
|
74
|
+
|
75
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Tagcrumbs::Builder do
|
4
|
+
before(:each) do
|
5
|
+
@builder = Tagcrumbs::Builder.new(nil)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "should typecast" do
|
9
|
+
it "time to iso8601" do
|
10
|
+
t = Time.now
|
11
|
+
@builder.typecast(:created_at, t).should == t.iso8601
|
12
|
+
end
|
13
|
+
|
14
|
+
it "a model to an URL" do
|
15
|
+
m = Tagcrumbs::Model.new
|
16
|
+
m.stub!(:resource_url).and_return('resource_url')
|
17
|
+
|
18
|
+
@builder.typecast(:model, m).should == 'resource_url'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "everything else" do
|
22
|
+
@builder.typecast(:int, 1).should == 1
|
23
|
+
@builder.typecast(:float, 1.12).should == 1.12
|
24
|
+
@builder.typecast(:string, 'abc').should == 'abc'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "should determine type" do
|
29
|
+
it "on nil" do
|
30
|
+
@builder.determine_type(:anything, nil).should == {:nil => true}
|
31
|
+
end
|
32
|
+
|
33
|
+
it "for Time" do
|
34
|
+
@builder.determine_type(:anything, Time.now).should == {:type => :timestamp}
|
35
|
+
end
|
36
|
+
|
37
|
+
it "for Boolean" do
|
38
|
+
@builder.determine_type(:anything, true).should == {:type => :boolean}
|
39
|
+
end
|
40
|
+
|
41
|
+
it "for Float" do
|
42
|
+
@builder.determine_type(:anything, 1.12).should == {:type => :float}
|
43
|
+
end
|
44
|
+
|
45
|
+
it "for Integer" do
|
46
|
+
@builder.determine_type(:anything, 1).should == {:type => :integer}
|
47
|
+
end
|
48
|
+
|
49
|
+
it "for Model" do
|
50
|
+
@builder.determine_type(:anything, Tagcrumbs::User.new).should == {:type => 'User'}
|
51
|
+
end
|
52
|
+
|
53
|
+
it "for unkown" do
|
54
|
+
@builder.determine_type(:anything, Tagcrumbs::Requestor.new).should == {}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
class Tagcrumbs::TestModel < Tagcrumbs::Model
|
4
|
+
readable_attributes :one
|
5
|
+
writeable_attributes :two
|
6
|
+
|
7
|
+
has_one :modifiable_association, :modifiable => true
|
8
|
+
has_one :unmodifiable_association
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Tagcrumbs::JsonBuilder do
|
12
|
+
before(:each) do
|
13
|
+
@model = Tagcrumbs::TestModel.new(:one => 1, :two => 'two')
|
14
|
+
|
15
|
+
@modifiable_association = Tagcrumbs::TestModel.new(:one => 1, :two => 'two')
|
16
|
+
@modifiable_association.resource_url = 'modifiable_resource_url'
|
17
|
+
@model.modifiable_association = @modifiable_association
|
18
|
+
|
19
|
+
@unmodifiable_association = Tagcrumbs::TestModel.new(:one => 1, :two => 'two')
|
20
|
+
@model.unmodifiable_association = @unmodifiable_association
|
21
|
+
|
22
|
+
@builder = Tagcrumbs::JsonBuilder.new(@model)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "build with badgerfish" do
|
26
|
+
it "and all attributes" do
|
27
|
+
@builder.build(:badgerfish => true, :to_json => false).should == {"test_model" => {:two => {'$' => "two"}, '@type' => 'TestModel', :one => {'$' => nil, '@nil' => true}, :modifiable_association => {'@type' => 'TestModel', '$' => "modifiable_resource_url"}}}
|
28
|
+
end
|
29
|
+
|
30
|
+
it "and writeable attributes only" do
|
31
|
+
@builder.build(:badgerfish => true, :to_json => false, :modifiable_only => true).should == {"test_model" => {:two => {'$' => "two"}, '@type' => 'TestModel', :modifiable_association => {'@type' => 'TestModel', '$' => "modifiable_resource_url"}}}
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "build without badgerfish" do
|
37
|
+
it "and writeable attributes only" do
|
38
|
+
@builder.build(:modifiable_only => true, :to_json => false).should == {"test_model" => {:two => "two", :modifiable_association => "modifiable_resource_url"}}
|
39
|
+
end
|
40
|
+
|
41
|
+
it "and all attributes" do
|
42
|
+
@builder.build(:to_json => false).should == {"test_model" => {:two => "two", :one => nil, :modifiable_association => "modifiable_resource_url"}}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
class Tagcrumbs::TestModel < Tagcrumbs::Model
|
4
|
+
readable_attributes :one
|
5
|
+
writeable_attributes :two
|
6
|
+
|
7
|
+
has_one :modifiable_association, :modifiable => true
|
8
|
+
has_one :unmodifiable_association
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Tagcrumbs::XmlBuilder do
|
12
|
+
before(:each) do
|
13
|
+
@model = Tagcrumbs::TestModel.new(:one => 1, :two => 'two')
|
14
|
+
|
15
|
+
@modifiable_association = Tagcrumbs::TestModel.new(:one => 1, :two => 'two')
|
16
|
+
@modifiable_association.resource_url = 'modifiable_resource_url'
|
17
|
+
@model.modifiable_association = @modifiable_association
|
18
|
+
|
19
|
+
@unmodifiable_association = Tagcrumbs::TestModel.new(:one => 1, :two => 'two')
|
20
|
+
@model.unmodifiable_association = @unmodifiable_association
|
21
|
+
|
22
|
+
@builder = Tagcrumbs::XmlBuilder.new(@model)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "build" do
|
26
|
+
it "and writeable attributes only" do
|
27
|
+
@builder.build(:modifiable_only => true, :sorted_attributes => true).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test_model type=\"TestModel\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <modifiable_association type=\"TestModel\">modifiable_resource_url</modifiable_association>\n <two>two</two>\n</test_model>\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "and all attributes" do
|
31
|
+
@builder.build(:sorted_attributes => true).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test_model type=\"TestModel\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <modifiable_association type=\"TestModel\">modifiable_resource_url</modifiable_association>\n <one nil=\"true\"></one>\n <two>two</two>\n</test_model>\n"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Tagcrumbs do
|
4
|
+
it "have exceptions" do
|
5
|
+
Tagcrumbs::UnsupportedFormat.new.is_a?(StandardError)
|
6
|
+
|
7
|
+
Tagcrumbs::CreateURLMissing.new.is_a?(StandardError)
|
8
|
+
Tagcrumbs::ResourceURLMissing.new.is_a?(StandardError)
|
9
|
+
|
10
|
+
Tagcrumbs::CreateImpossible.new.is_a?(StandardError)
|
11
|
+
Tagcrumbs::UpdateImpossible.new.is_a?(StandardError)
|
12
|
+
Tagcrumbs::DestroyImpossible.new.is_a?(StandardError)
|
13
|
+
|
14
|
+
Tagcrumbs::InvalidRequest.new.is_a?(StandardError)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Tagcrumbs::Node do
|
4
|
+
it "should get attributes" do
|
5
|
+
@node = Tagcrumbs::Node.new('name', 'value', {})
|
6
|
+
|
7
|
+
@node.name == 'name'
|
8
|
+
@node.value == 'value'
|
9
|
+
@node.properties == {}
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "typecast value" do
|
13
|
+
it "to nil" do
|
14
|
+
Tagcrumbs::Node.new('name', '', {'nil' => 'true'}).value.should be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "to integer" do
|
18
|
+
Tagcrumbs::Node.new('name', '1', {'type' => 'integer'}).value.should == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
it "to float" do
|
22
|
+
Tagcrumbs::Node.new('name', '1.12', {'type' => 'float'}).value.should == 1.12
|
23
|
+
end
|
24
|
+
|
25
|
+
it "to boolean" do
|
26
|
+
Tagcrumbs::Node.new('name', 'true', {'type' => 'boolean'}).value.should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "to time" do
|
30
|
+
Tagcrumbs::Node.new('name', Time.now.iso8601, {'type' => 'timestamp'}).value.should be_an_instance_of(Time)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "to string" do
|
34
|
+
Tagcrumbs::Node.new('name', "<b> bold").value.should == '<b> bold'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not typecast a non-string value" do
|
38
|
+
Tagcrumbs::Node.new('name', 123).value.should == 123
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Tagcrumbs::JsonParser do
|
4
|
+
before(:each) do
|
5
|
+
@document = fixture_file('json_parser.json')
|
6
|
+
@json = Tagcrumbs::JsonParser.new(@document)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "should initialize" do
|
10
|
+
it "with a document and set parser to root element" do
|
11
|
+
parser = Tagcrumbs::JsonParser.new(@document)
|
12
|
+
parser.document.should be_an_instance_of(Hash)
|
13
|
+
parser.document['@xlink:href'].should == 'test_xlink'
|
14
|
+
parser.format.should == :json
|
15
|
+
end
|
16
|
+
|
17
|
+
it "with a parser" do
|
18
|
+
@json.is_a?(String).should be_false
|
19
|
+
parser = Tagcrumbs::JsonParser.new(@json)
|
20
|
+
|
21
|
+
parser.document.should == @json.document
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "should get node" do
|
26
|
+
it "with success" do
|
27
|
+
node = @json.get_node('child')
|
28
|
+
node.should be_an_instance_of(Hash)
|
29
|
+
node['@xlink:href'].should == 'child_xlink'
|
30
|
+
node['deep'].should == {"$"=>"test"}
|
31
|
+
end
|
32
|
+
|
33
|
+
it "and not find deeper nested nodes" do
|
34
|
+
node = @json.get_node('deep')
|
35
|
+
node.should be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "should find out if node is loaded" do
|
40
|
+
it "with a loaded node" do
|
41
|
+
parser = Tagcrumbs::JsonParser.new(@json.get_node('child'))
|
42
|
+
parser.node_loaded?.should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "with an empty single tag" do
|
46
|
+
parser = Tagcrumbs::JsonParser.new(@json.get_node('empty_single'))
|
47
|
+
parser.node_loaded?.should be_false
|
48
|
+
end
|
49
|
+
|
50
|
+
it "with an empty closed tag" do
|
51
|
+
parser = Tagcrumbs::JsonParser.new(@json.get_node('empty_closed'))
|
52
|
+
parser.node_loaded?.should be_false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "should get nodes by name" do
|
57
|
+
it "in the current level only" do
|
58
|
+
@json.nodes_with_name('element').should == [] # don't get nested nodes
|
59
|
+
end
|
60
|
+
|
61
|
+
it "with success" do
|
62
|
+
@json = Tagcrumbs::JsonParser.new(@json.get_node('array'))
|
63
|
+
|
64
|
+
array = @json.nodes_with_name('element')
|
65
|
+
array.should have(2).items
|
66
|
+
array[0].should == 'one'
|
67
|
+
array[1].should == 'two'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "should get attributes" do
|
72
|
+
it "with multiple attributes" do
|
73
|
+
attributes = @json.get_attributes
|
74
|
+
|
75
|
+
attributes.should have(2).items
|
76
|
+
attributes['xmlns:xlink'].should == 'http://www.w3.org/1999/xlink'
|
77
|
+
attributes['xlink:href'].should == 'test_xlink'
|
78
|
+
end
|
79
|
+
|
80
|
+
it "without attributes" do
|
81
|
+
@json = Tagcrumbs::JsonParser.new(@json.get_node('array'))
|
82
|
+
|
83
|
+
@json.get_attributes.should == {}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "should get attribute" do
|
88
|
+
it "with success" do
|
89
|
+
@json.get_attribute('xlink:href').should == 'test_xlink'
|
90
|
+
end
|
91
|
+
|
92
|
+
it "without an attribute" do
|
93
|
+
@json.get_attribute('unexisting').should be_nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "should get value" do
|
98
|
+
it "with success" do
|
99
|
+
@json = Tagcrumbs::JsonParser.new(@json.get_node('simple'))
|
100
|
+
|
101
|
+
@json.get_value.should == 'value'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "should get name" do
|
106
|
+
it "with success" do
|
107
|
+
@json.name.should == 'test'
|
108
|
+
end
|
109
|
+
|
110
|
+
# TODO_SK: not working, do we need it?
|
111
|
+
# it "with nested element" do
|
112
|
+
# @json = Tagcrumbs::JsonParser.new(@json.get_node('simple'))
|
113
|
+
#
|
114
|
+
# @json.name.should == 'simple'
|
115
|
+
# end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Tagcrumbs::Parser do
|
4
|
+
it "should have a document and format" do
|
5
|
+
parser = Tagcrumbs::Parser.new
|
6
|
+
parser.document = 'document'
|
7
|
+
parser.document.should == 'document'
|
8
|
+
|
9
|
+
parser.format = 'format'
|
10
|
+
parser.format.should == 'format'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return the correct parser" do
|
14
|
+
Tagcrumbs::Parser.new_for_format('<xml></xml>', :xml).should be_an_instance_of(Tagcrumbs::XmlParser)
|
15
|
+
Tagcrumbs::Parser.new_for_format('{"json": 1}', :json).should be_an_instance_of(Tagcrumbs::JsonParser)
|
16
|
+
|
17
|
+
parser = Tagcrumbs::JsonParser.new('{"json": 1}')
|
18
|
+
|
19
|
+
Tagcrumbs::Parser.new_for_format(parser, :json).should == parser
|
20
|
+
|
21
|
+
lambda {
|
22
|
+
Tagcrumbs::Parser.new_for_format('', :exe)
|
23
|
+
}.should raise_error(Tagcrumbs::UnsupportedFormat)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Tagcrumbs::XmlParser do
|
4
|
+
before(:each) do
|
5
|
+
@document = fixture_file('xml_parser.xml')
|
6
|
+
@xml = Tagcrumbs::XmlParser.new(@document)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "should initialize" do
|
10
|
+
it "with a document and set parser to root element" do
|
11
|
+
parser = Tagcrumbs::XmlParser.new(@document)
|
12
|
+
parser.document.should be_an_instance_of(Hpricot::Elem)
|
13
|
+
parser.document.name.should == 'test'
|
14
|
+
parser.format.should == :xml
|
15
|
+
end
|
16
|
+
|
17
|
+
it "with a parser" do
|
18
|
+
@xml.is_a?(String).should be_false
|
19
|
+
parser = Tagcrumbs::XmlParser.new(@xml)
|
20
|
+
|
21
|
+
parser.document.should == @xml.document
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
describe "should get node" do
|
27
|
+
it "with success" do
|
28
|
+
node = @xml.get_node('child')
|
29
|
+
node.should be_an_instance_of(Hpricot::Elem)
|
30
|
+
node.name.should == 'child'
|
31
|
+
node.get_attribute('xlink:href').should == 'child_xlink'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "and not find deeper nested nodes" do
|
35
|
+
node = @xml.get_node('deep')
|
36
|
+
node.should be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "should find out if node is loaded" do
|
41
|
+
it "with a loaded node" do
|
42
|
+
parser = Tagcrumbs::XmlParser.new(@xml.get_node('child'))
|
43
|
+
parser.node_loaded?.should be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "with an empty single tag" do
|
47
|
+
parser = Tagcrumbs::XmlParser.new(@xml.get_node('empty_single'))
|
48
|
+
parser.node_loaded?.should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
it "with an empty closed tag" do
|
52
|
+
parser = Tagcrumbs::XmlParser.new(@xml.get_node('empty_closed'))
|
53
|
+
parser.node_loaded?.should be_false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "should get nodes by name" do
|
58
|
+
it "in the current level only" do
|
59
|
+
@xml.nodes_with_name('element').should == [] # don't get nested nodes
|
60
|
+
end
|
61
|
+
|
62
|
+
it "with success" do
|
63
|
+
@xml = Tagcrumbs::XmlParser.new(@xml.get_node('array'))
|
64
|
+
|
65
|
+
array = @xml.nodes_with_name('element')
|
66
|
+
array.should have(2).items
|
67
|
+
array[0].innerHTML.should == 'one'
|
68
|
+
array[1].innerHTML.should == 'two'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "should get attributes" do
|
73
|
+
it "with multiple attributes" do
|
74
|
+
attributes = @xml.get_attributes
|
75
|
+
|
76
|
+
attributes.should have(2).items
|
77
|
+
attributes['xmlns:xlink'].should == 'http://www.w3.org/1999/xlink'
|
78
|
+
attributes['xlink:href'].should == 'test_xlink'
|
79
|
+
end
|
80
|
+
|
81
|
+
it "without attributes" do
|
82
|
+
@xml = Tagcrumbs::XmlParser.new(@xml.get_node('array'))
|
83
|
+
|
84
|
+
@xml.get_attributes.should == {}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "should get attribute" do
|
89
|
+
it "with success" do
|
90
|
+
@xml.get_attribute('xlink:href').should == 'test_xlink'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "without an attribute" do
|
94
|
+
@xml.get_attribute('unexisting').should be_nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "should get value" do
|
99
|
+
it "with success" do
|
100
|
+
@xml = Tagcrumbs::XmlParser.new(@xml.get_node('simple'))
|
101
|
+
|
102
|
+
@xml.get_value.should == 'value'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "should get name" do
|
107
|
+
it "with success" do
|
108
|
+
@xml.name.should == 'test'
|
109
|
+
end
|
110
|
+
|
111
|
+
it "with nested node" do
|
112
|
+
@xml = Tagcrumbs::XmlParser.new(@xml.get_node('simple'))
|
113
|
+
|
114
|
+
@xml.name.should == 'simple'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Tagcrumbs::Proxy do
|
4
|
+
before(:each) do
|
5
|
+
@object = mock("MockObject", :class => 'MockObject', :properties => {}, :loaded? => false)
|
6
|
+
@object.stub!(:reload)
|
7
|
+
@object.stub!(:my_name)
|
8
|
+
@object.stub!(:resource_url)
|
9
|
+
|
10
|
+
@proxy = Tagcrumbs::Proxy.new(@object)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "with object loaded" do
|
14
|
+
it "should reload and forward methods to the object" do
|
15
|
+
@object.stub!(:loaded?).and_return(true)
|
16
|
+
|
17
|
+
@object.should_not_receive(:reload)
|
18
|
+
@object.should_receive(:my_name)
|
19
|
+
|
20
|
+
@proxy.my_name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "with object not loaded" do
|
25
|
+
it "should reload and forward methods to the object" do
|
26
|
+
@object.should_receive(:reload)
|
27
|
+
@object.should_receive(:resource_url).and_return('something')
|
28
|
+
@object.should_receive(:my_name)
|
29
|
+
|
30
|
+
@proxy.my_name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should pass unproxied methods" do
|
35
|
+
@object.should_receive(:resource_url)
|
36
|
+
@object.should_not_receive(:reload)
|
37
|
+
|
38
|
+
@object.resource_url
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should pass unknown methods" do
|
42
|
+
@object.should_receive(:abcd)
|
43
|
+
@object.should_not_receive(:reload)
|
44
|
+
|
45
|
+
@object.abcd
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Tagcrumbs::Requestor do
|
4
|
+
before(:each) do
|
5
|
+
@requestor = Tagcrumbs::Requestor.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should allow configuration" do
|
9
|
+
@requestor.options.should == Tagcrumbs.options
|
10
|
+
|
11
|
+
@requestor = Tagcrumbs::Requestor.new(:consumer_token => '123')
|
12
|
+
@requestor.options[:consumer_token].should == '123'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have a consumer" do
|
16
|
+
@requestor.consumer.should be_an_instance_of(OAuth::Consumer)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "request token" do
|
20
|
+
it "should exist from configuration" do
|
21
|
+
@requestor = Tagcrumbs::Requestor.new(:consumer_token => 'abc', :consumer_secret => 'def', :consumer_options => {:site => 'http://www.tagcrumbs.com'}, :request_token => '123', :request_secret => '456')
|
22
|
+
@requestor.request_token.should be_an_instance_of(OAuth::RequestToken)
|
23
|
+
@requestor.request_token.token.should == '123'
|
24
|
+
@requestor.request_token.secret.should == '456'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should get a new request token" do
|
28
|
+
@requestor = Tagcrumbs::Requestor.new
|
29
|
+
@request_token = mock("OAuth::RequestToken")
|
30
|
+
@consumer = mock("OAuth::Consumer")
|
31
|
+
@consumer.stub!(:get_request_token)
|
32
|
+
@consumer.should_receive(:get_request_token).and_return(@request_token)
|
33
|
+
@requestor.stub!(:consumer).and_return(@consumer)
|
34
|
+
|
35
|
+
@requestor.request_token.should == @request_token
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "access token" do
|
40
|
+
it "should exist from configuration" do
|
41
|
+
@requestor = Tagcrumbs::Requestor.new(:consumer_token => 'abc', :consumer_secret => 'def', :consumer_options => {:site => 'http://www.tagcrumbs.com'}, :access_token => '123', :access_secret => '456')
|
42
|
+
@requestor.access_token.should be_an_instance_of(OAuth::AccessToken)
|
43
|
+
@requestor.access_token.token.should == '123'
|
44
|
+
@requestor.access_token.secret.should == '456'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should build a query string from a hash" do
|
49
|
+
@requestor.send(:path_with_query_string, "path", {:one => 1, :two => 'two'}).should == 'path?one=1&two=two'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have default headers" do
|
53
|
+
@requestor.send(:default_headers, :xml).should == {"Content-Type"=>"application/xml", "Accept"=>"application/xml, text/xml"}
|
54
|
+
@requestor.send(:default_headers, :json).should == {"Content-Type"=>"application/json", "Accept"=>"application/json, text/json"}
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should raise an error on invalid format on default headers" do
|
58
|
+
lambda {
|
59
|
+
@requestor.send(:default_headers, :abc)
|
60
|
+
}.should raise_error(Tagcrumbs::UnsupportedFormat)
|
61
|
+
end
|
62
|
+
end
|