tagcrumbs-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.rb +232 -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/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 +325 -0
@@ -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
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Tagcrumbs::Array do
|
4
|
+
before(:each) do
|
5
|
+
@array = Tagcrumbs::Array.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should reset" do
|
9
|
+
@array.properties = {1 => 2}
|
10
|
+
@array.resource_url = 'test.de'
|
11
|
+
@array.loaded = true
|
12
|
+
@array.array = [1,2,3]
|
13
|
+
|
14
|
+
@array.reset!
|
15
|
+
|
16
|
+
@array.properties.should == {}
|
17
|
+
@array.resource_url.should be_nil
|
18
|
+
@array.loaded.should be_false
|
19
|
+
@array.array.should == []
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set properties and typecast" do
|
23
|
+
@array.properties = {'xlink:href' => 'array_url', 'page' => '5', 'total_entries' => '20'}
|
24
|
+
|
25
|
+
@array.resource_url.should == 'array_url'
|
26
|
+
@array.properties[:page].should == '5'
|
27
|
+
@array.page.should == 5
|
28
|
+
@array.properties[:total_entries].should == '20'
|
29
|
+
@array.total_entries.should == 20
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should delegate missing methods to the array" do
|
33
|
+
@array.size.should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should initialize from document" do
|
37
|
+
@array.initialize_from_document(fixture_file('placemarks.xml'))
|
38
|
+
|
39
|
+
@array.resource_url.should == 'http://www.tagcrumbs.com/sascha/tagcrumbs.xml'
|
40
|
+
@array.loaded.should == true
|
41
|
+
@array.properties.should be_present
|
42
|
+
|
43
|
+
@array.properties[:page].should == '1'
|
44
|
+
@array.page.should == 1
|
45
|
+
@array.properties[:per_page].should == '10'
|
46
|
+
@array.per_page.should == 10
|
47
|
+
@array.properties[:pages].should == '21'
|
48
|
+
@array.pages.should == 21
|
49
|
+
@array.properties[:total_entries].should == '206'
|
50
|
+
@array.total_entries.should == 206
|
51
|
+
|
52
|
+
@array.properties[:sort].should == 'date'
|
53
|
+
@array.sort.should == 'date'
|
54
|
+
@array.properties[:order].should == 'desc'
|
55
|
+
@array.order.should == 'desc'
|
56
|
+
|
57
|
+
@array.size.should == 3
|
58
|
+
@array[0].should be_an_instance_of(Tagcrumbs::Placemark)
|
59
|
+
@array[1].should be_an_instance_of(Tagcrumbs::Placemark)
|
60
|
+
@array[2].should be_an_instance_of(Tagcrumbs::Placemark)
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
+
|
3
|
+
class Tagcrumbs::AccessorTestModel < Tagcrumbs::Model
|
4
|
+
can_be :created, :updated
|
5
|
+
|
6
|
+
readable_attributes :readable1, :readable2
|
7
|
+
writeable_attributes :writeable1, :writeable2
|
8
|
+
|
9
|
+
has_one :tagcrumb
|
10
|
+
has_one :has_one_subitem
|
11
|
+
has_one :has_one_subitem_modifiable, :modifiable => true
|
12
|
+
|
13
|
+
has_many :has_many_subitems
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Tagcrumbs::Accessors do
|
18
|
+
before(:each) do
|
19
|
+
@model = Tagcrumbs::AccessorTestModel.new(:writeable1 => 1, :writeable2 => 2, :has_one_subitem_modifiable => 'url')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have nodes" do
|
23
|
+
@model.nodes.should == {}
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have nodes_updates" do
|
27
|
+
@model.nodes_updates.keys.should have(2).items
|
28
|
+
@model.nodes_updates[:writeable1].should be_an_instance_of(Tagcrumbs::Node)
|
29
|
+
@model.nodes_updates[:writeable2].should be_an_instance_of(Tagcrumbs::Node)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have has_one associations" do
|
33
|
+
@model.has_one_associations.should == {}
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have has_one association updates" do
|
37
|
+
@model.has_one_associations_updates.should == {:has_one_subitem_modifiable => 'url'}
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have has_one association updates" do
|
41
|
+
@model.has_many_associations.should == {}
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should restore changes" do
|
45
|
+
@model.nodes_updates.keys.should have(2).items
|
46
|
+
@model.has_one_associations_updates.keys.should have(1).item
|
47
|
+
|
48
|
+
@model.restore!
|
49
|
+
|
50
|
+
@model.nodes_updates.should == {}
|
51
|
+
@model.has_one_associations_updates.should == {}
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should update attributes" do
|
55
|
+
@model.attributes = {:writeable1 => 'one'}
|
56
|
+
|
57
|
+
@model.nodes_updates[:writeable1].value.should == 'one'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return all attributes" do
|
61
|
+
@model.attributes.should == {:writeable1 => 1, :writeable2 => 2, :has_one_subitem_modifiable => 'url', :readable1 => nil, :readable2 => nil}
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return modifiable-only attributes" do
|
65
|
+
@model.attributes(:modifiable_only => true).should == {:writeable1 => 1, :writeable2 => 2, :has_one_subitem_modifiable => 'url'}
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should inspect" do
|
69
|
+
@model.inspect.should_not be_blank
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return the class name without modules" do
|
73
|
+
@model.class_name.should == 'AccessorTestModel'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should have a create url" do
|
77
|
+
stub_get('/you', 'user.xml', [200])
|
78
|
+
|
79
|
+
lambda {
|
80
|
+
@model.create_url
|
81
|
+
}.should raise_error(Tagcrumbs::CreateURLMissing)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
it "should have an error on create url if object can not be created" do
|
86
|
+
@model.stub!(:can_be?).and_return(false)
|
87
|
+
|
88
|
+
lambda {
|
89
|
+
@model.create_url
|
90
|
+
}.should raise_error(Tagcrumbs::CreateImpossible)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should create a has_many_url method" do
|
94
|
+
stub_get('/you', 'user.xml', [200])
|
95
|
+
|
96
|
+
Tagcrumbs.current_user.tagcrumbs_url.should == tagcrumbs_url('/sascha/tagcrumbs.xml')
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should find out what actions can be done" do
|
100
|
+
@model.can_be?(:created).should be_true
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should alias tagcrumb to placemark" do
|
104
|
+
@model.placemark = 123
|
105
|
+
@model.tagcrumb.should == 123
|
106
|
+
@model.placemark.should == 123
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "(Class Methods)" do
|
110
|
+
it "should have can_be options" do
|
111
|
+
Tagcrumbs::AccessorTestModel.can_be_options.should == [:created, :updated]
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should have all attributes" do
|
115
|
+
Tagcrumbs::AccessorTestModel.attributes.sort{|a, b| a.to_s <=> b.to_s}.should == [:writeable2, :writeable1, :readable1, :readable2, :has_one_subitem_modifiable].sort{|a, b| a.to_s <=> b.to_s}
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should have modifiable_only attributes" do
|
119
|
+
Tagcrumbs::AccessorTestModel.attributes(:modifiable_only => true).sort{|a, b| a.to_s <=> b.to_s}.should == [:writeable2, :writeable1, :has_one_subitem_modifiable].sort{|a, b| a.to_s <=> b.to_s}
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
+
|
3
|
+
describe Tagcrumbs::Activity do
|
4
|
+
it "should create from a document" do
|
5
|
+
Tagcrumbs.supported_formats.keys.each do |format|
|
6
|
+
activity = Tagcrumbs::Activity.new_from_document(fixture_file("activity", format), format)
|
7
|
+
|
8
|
+
activity.resource_url.should == tagcrumbs_url('/sascha/activities/460', format)
|
9
|
+
activity.new_record.should be_false
|
10
|
+
activity.loaded.should be_true
|
11
|
+
|
12
|
+
activity.event_type.should == 'create'
|
13
|
+
activity.created_at.should be_an_instance_of(Time)
|
14
|
+
activity.updated_at.should be_an_instance_of(Time)
|
15
|
+
|
16
|
+
# has one associations
|
17
|
+
activity.user.class.should == Tagcrumbs::User
|
18
|
+
activity.user.loaded?.should be_true
|
19
|
+
activity.user.resource_url.should == tagcrumbs_url('/sascha', format)
|
20
|
+
|
21
|
+
activity.subject.class.should == Tagcrumbs::Comment
|
22
|
+
activity.subject.loaded?.should be_true
|
23
|
+
activity.subject.resource_url.should == tagcrumbs_url('/sascha/comments/84', format)
|
24
|
+
activity.subject.text.should == 'COMMENT TEXT'
|
25
|
+
|
26
|
+
activity.secondary_subject.class.should == Tagcrumbs::Placemark
|
27
|
+
activity.secondary_subject.loaded?.should be_true
|
28
|
+
activity.secondary_subject.resource_url.should == tagcrumbs_url('/sascha/placemarks/placemark-name', format)
|
29
|
+
activity.secondary_subject.name.should == 'PLACEMARK NAME'
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|