tagcrumbs-tagcrumbs 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/History.txt +9 -0
  2. data/License.txt +22 -0
  3. data/Manifest.txt +177 -0
  4. data/PostInstall.txt +2 -0
  5. data/README.rdoc +45 -0
  6. data/Rakefile +35 -0
  7. data/TODO.txt +17 -0
  8. data/bin/tagcrumbs +5 -0
  9. data/examples/address_update.rb +15 -0
  10. data/examples/comment_new.rb +19 -0
  11. data/examples/favorite_new.rb +17 -0
  12. data/examples/filter_new.rb +15 -0
  13. data/examples/friendship_create.rb +19 -0
  14. data/examples/link_new.rb +16 -0
  15. data/examples/location_update.rb +16 -0
  16. data/examples/picture_update.rb +16 -0
  17. data/examples/placemark_new_simple.rb +24 -0
  18. data/examples/placemark_new_suggestions.rb +24 -0
  19. data/examples/profile_link_new.rb +14 -0
  20. data/examples/profile_update.rb +12 -0
  21. data/examples/request_authorization.rb +25 -0
  22. data/examples/settings_update.rb +12 -0
  23. data/examples/subscription_new.rb +15 -0
  24. data/examples/tagcrumbs_find.rb +25 -0
  25. data/examples/tagcrumbs_search.rb +7 -0
  26. data/examples/user.rb +28 -0
  27. data/examples/user_recommendation_new.rb +15 -0
  28. data/lib/tagcrumbs.rb +232 -0
  29. data/lib/tagcrumbs/builders/builder.rb +45 -0
  30. data/lib/tagcrumbs/builders/json_builder.rb +38 -0
  31. data/lib/tagcrumbs/builders/xml_builder.rb +30 -0
  32. data/lib/tagcrumbs/cli.rb +268 -0
  33. data/lib/tagcrumbs/config_store.rb +35 -0
  34. data/lib/tagcrumbs/exceptions.rb +13 -0
  35. data/lib/tagcrumbs/node.rb +43 -0
  36. data/lib/tagcrumbs/parsers/json_parser.rb +79 -0
  37. data/lib/tagcrumbs/parsers/parser.rb +24 -0
  38. data/lib/tagcrumbs/parsers/xml_parser.rb +54 -0
  39. data/lib/tagcrumbs/proxy.rb +32 -0
  40. data/lib/tagcrumbs/requestor.rb +140 -0
  41. data/lib/tagcrumbs/resources/array.rb +108 -0
  42. data/lib/tagcrumbs/resources/models/accessors.rb +252 -0
  43. data/lib/tagcrumbs/resources/models/activity.rb +19 -0
  44. data/lib/tagcrumbs/resources/models/address.rb +16 -0
  45. data/lib/tagcrumbs/resources/models/city.rb +13 -0
  46. data/lib/tagcrumbs/resources/models/comment.rb +12 -0
  47. data/lib/tagcrumbs/resources/models/country.rb +15 -0
  48. data/lib/tagcrumbs/resources/models/fanship.rb +12 -0
  49. data/lib/tagcrumbs/resources/models/favorite.rb +22 -0
  50. data/lib/tagcrumbs/resources/models/filter.rb +32 -0
  51. data/lib/tagcrumbs/resources/models/flag.rb +10 -0
  52. data/lib/tagcrumbs/resources/models/friendship.rb +12 -0
  53. data/lib/tagcrumbs/resources/models/geoname.rb +8 -0
  54. data/lib/tagcrumbs/resources/models/link.rb +13 -0
  55. data/lib/tagcrumbs/resources/models/location.rb +13 -0
  56. data/lib/tagcrumbs/resources/models/model.rb +148 -0
  57. data/lib/tagcrumbs/resources/models/picture.rb +28 -0
  58. data/lib/tagcrumbs/resources/models/place.rb +17 -0
  59. data/lib/tagcrumbs/resources/models/placemark.rb +30 -0
  60. data/lib/tagcrumbs/resources/models/profile.rb +16 -0
  61. data/lib/tagcrumbs/resources/models/profile_link.rb +12 -0
  62. data/lib/tagcrumbs/resources/models/root.rb +19 -0
  63. data/lib/tagcrumbs/resources/models/settings.rb +14 -0
  64. data/lib/tagcrumbs/resources/models/state.rb +14 -0
  65. data/lib/tagcrumbs/resources/models/subscription.rb +13 -0
  66. data/lib/tagcrumbs/resources/models/suggestions.rb +11 -0
  67. data/lib/tagcrumbs/resources/models/tag.rb +6 -0
  68. data/lib/tagcrumbs/resources/models/tagcrumb.rb +58 -0
  69. data/lib/tagcrumbs/resources/models/user.rb +101 -0
  70. data/lib/tagcrumbs/resources/models/user_recommendation.rb +18 -0
  71. data/lib/tagcrumbs/resources/resource.rb +76 -0
  72. data/lib/tagcrumbs/validations.rb +301 -0
  73. data/script/console +10 -0
  74. data/script/destroy +14 -0
  75. data/script/generate +14 -0
  76. data/spec/fixtures/activity.json +210 -0
  77. data/spec/fixtures/activity.xml +66 -0
  78. data/spec/fixtures/address.json +183 -0
  79. data/spec/fixtures/address.xml +58 -0
  80. data/spec/fixtures/city.json +88 -0
  81. data/spec/fixtures/city.xml +34 -0
  82. data/spec/fixtures/comment.json +286 -0
  83. data/spec/fixtures/comment.xml +87 -0
  84. data/spec/fixtures/country.json +32 -0
  85. data/spec/fixtures/country.xml +13 -0
  86. data/spec/fixtures/fanship.json +180 -0
  87. data/spec/fixtures/fanship.xml +54 -0
  88. data/spec/fixtures/favorite.json +332 -0
  89. data/spec/fixtures/favorite.xml +109 -0
  90. data/spec/fixtures/filter.json +243 -0
  91. data/spec/fixtures/filter.xml +80 -0
  92. data/spec/fixtures/friendship.json +180 -0
  93. data/spec/fixtures/friendship.xml +54 -0
  94. data/spec/fixtures/geoname.json +18 -0
  95. data/spec/fixtures/geoname.xml +6 -0
  96. data/spec/fixtures/json_parser.json +25 -0
  97. data/spec/fixtures/link.json +288 -0
  98. data/spec/fixtures/link.xml +88 -0
  99. data/spec/fixtures/location.json +204 -0
  100. data/spec/fixtures/location.xml +71 -0
  101. data/spec/fixtures/picture.json +154 -0
  102. data/spec/fixtures/picture.png +0 -0
  103. data/spec/fixtures/picture.xml +49 -0
  104. data/spec/fixtures/placemark.json +357 -0
  105. data/spec/fixtures/placemark.xml +58 -0
  106. data/spec/fixtures/placemarks.json +887 -0
  107. data/spec/fixtures/placemarks.xml +348 -0
  108. data/spec/fixtures/profile.json +282 -0
  109. data/spec/fixtures/profile.xml +100 -0
  110. data/spec/fixtures/profile_link.json +156 -0
  111. data/spec/fixtures/profile_link.xml +49 -0
  112. data/spec/fixtures/root.json +46 -0
  113. data/spec/fixtures/root.xml +14 -0
  114. data/spec/fixtures/settings.json +147 -0
  115. data/spec/fixtures/settings.xml +45 -0
  116. data/spec/fixtures/state.json +62 -0
  117. data/spec/fixtures/state.xml +23 -0
  118. data/spec/fixtures/subscription.json +283 -0
  119. data/spec/fixtures/subscription.xml +86 -0
  120. data/spec/fixtures/suggestions.json +1877 -0
  121. data/spec/fixtures/suggestions.xml +724 -0
  122. data/spec/fixtures/tag.json +9 -0
  123. data/spec/fixtures/tag.xml +4 -0
  124. data/spec/fixtures/user.json +105 -0
  125. data/spec/fixtures/user.xml +31 -0
  126. data/spec/fixtures/user_recommendation.json +349 -0
  127. data/spec/fixtures/user_recommendation.xml +106 -0
  128. data/spec/fixtures/validation_errors.json +5 -0
  129. data/spec/fixtures/validation_errors.xml +5 -0
  130. data/spec/fixtures/xml_parser.xml +13 -0
  131. data/spec/spec.opts +1 -0
  132. data/spec/spec_helper.rb +75 -0
  133. data/spec/tagcrumbs/builders/builder_spec.rb +57 -0
  134. data/spec/tagcrumbs/builders/json_builder_spec.rb +47 -0
  135. data/spec/tagcrumbs/builders/xml_builder_spec.rb +34 -0
  136. data/spec/tagcrumbs/exceptions_spec.rb +16 -0
  137. data/spec/tagcrumbs/node_spec.rb +42 -0
  138. data/spec/tagcrumbs/parsers/json_parser_spec.rb +117 -0
  139. data/spec/tagcrumbs/parsers/parser_spec.rb +25 -0
  140. data/spec/tagcrumbs/parsers/xml_parser_spec.rb +117 -0
  141. data/spec/tagcrumbs/proxy_spec.rb +48 -0
  142. data/spec/tagcrumbs/requestor_spec.rb +62 -0
  143. data/spec/tagcrumbs/resources/array_spec.rb +62 -0
  144. data/spec/tagcrumbs/resources/models/accessors_spec.rb +123 -0
  145. data/spec/tagcrumbs/resources/models/activity_spec.rb +33 -0
  146. data/spec/tagcrumbs/resources/models/address_spec.rb +24 -0
  147. data/spec/tagcrumbs/resources/models/city_spec.rb +33 -0
  148. data/spec/tagcrumbs/resources/models/comment_spec.rb +23 -0
  149. data/spec/tagcrumbs/resources/models/country_spec.rb +26 -0
  150. data/spec/tagcrumbs/resources/models/fanship_spec.rb +28 -0
  151. data/spec/tagcrumbs/resources/models/favorite_spec.rb +28 -0
  152. data/spec/tagcrumbs/resources/models/filter_spec.rb +43 -0
  153. data/spec/tagcrumbs/resources/models/flag_spec.rb +5 -0
  154. data/spec/tagcrumbs/resources/models/friendship_spec.rb +28 -0
  155. data/spec/tagcrumbs/resources/models/geoname_spec.rb +18 -0
  156. data/spec/tagcrumbs/resources/models/link_spec.rb +24 -0
  157. data/spec/tagcrumbs/resources/models/location_spec.rb +28 -0
  158. data/spec/tagcrumbs/resources/models/model_spec.rb +27 -0
  159. data/spec/tagcrumbs/resources/models/picture_spec.rb +42 -0
  160. data/spec/tagcrumbs/resources/models/place_spec.rb +12 -0
  161. data/spec/tagcrumbs/resources/models/placemark_spec.rb +61 -0
  162. data/spec/tagcrumbs/resources/models/profile_link_spec.rb +29 -0
  163. data/spec/tagcrumbs/resources/models/profile_spec.rb +43 -0
  164. data/spec/tagcrumbs/resources/models/root_spec.rb +57 -0
  165. data/spec/tagcrumbs/resources/models/settings_spec.rb +32 -0
  166. data/spec/tagcrumbs/resources/models/state_spec.rb +30 -0
  167. data/spec/tagcrumbs/resources/models/subscription_spec.rb +28 -0
  168. data/spec/tagcrumbs/resources/models/suggestions_spec.rb +33 -0
  169. data/spec/tagcrumbs/resources/models/tag_spec.rb +16 -0
  170. data/spec/tagcrumbs/resources/models/tagcrumb_spec.rb +21 -0
  171. data/spec/tagcrumbs/resources/models/user_recommendation_spec.rb +35 -0
  172. data/spec/tagcrumbs/resources/models/user_spec.rb +128 -0
  173. data/spec/tagcrumbs/resources/resource_spec.rb +62 -0
  174. data/spec/tagcrumbs/validations_spec.rb +27 -0
  175. data/spec/tagcrumbs_spec.rb +103 -0
  176. data/tagcrumbs.gemspec +59 -0
  177. data/tasks/rspec.rake +21 -0
  178. metadata +325 -0
@@ -0,0 +1,106 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <recommendation type="UserRecommendation" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.tagcrumbs.com/sascha/recommendations/70.xml">
3
+ <message>MESSAGE</message>
4
+ <created_at type="timestamp">2009-02-01T14:41:12+01:00</created_at>
5
+ <updated_at type="timestamp">2009-03-01T18:02:51+01:00</updated_at>
6
+ <recommended_user type="User" xlink:href="http://www.tagcrumbs.com/peter.xml">
7
+ <username>peter</username>
8
+ <created_at type="timestamp">2008-06-13T11:45:22+02:00</created_at>
9
+
10
+ <profile type="Profile" xlink:href="http://www.tagcrumbs.com/peter/profile.xml"/>
11
+ <picture type="Picture" xlink:href="http://www.tagcrumbs.com/peter/profile/picture.xml"/>
12
+ <profile_links type="array" xlink:href="http://www.tagcrumbs.com/peter/profile/links.xml"/>
13
+ <tagcrumbs type="array" xlink:href="http://www.tagcrumbs.com/peter/tagcrumbs.xml"/>
14
+ <placemarks type="array" xlink:href="http://www.tagcrumbs.com/peter/placemarks.xml"/>
15
+ <favorites type="array" xlink:href="http://www.tagcrumbs.com/peter/favorites.xml"/>
16
+ <activities type="array" xlink:href="http://www.tagcrumbs.com/peter/activities.xml"/>
17
+ <tags type="array" xlink:href="http://www.tagcrumbs.com/peter/tags.xml"/>
18
+ <places type="array" xlink:href="http://www.tagcrumbs.com/peter/places.xml"/>
19
+
20
+ <friendships type="array" xlink:href="http://www.tagcrumbs.com/peter/friends.xml"/>
21
+ <fanships type="array" xlink:href="http://www.tagcrumbs.com/peter/fans.xml"/>
22
+ <tagcrumbs_friends type="array" xlink:href="http://www.tagcrumbs.com/peter/friends/tagcrumbs.xml"/>
23
+ <tagcrumbs_fans type="array" xlink:href="http://www.tagcrumbs.com/peter/fans/tagcrumbs.xml"/>
24
+ </recommended_user>
25
+ <user type="User" xlink:href="http://www.tagcrumbs.com/sascha.xml">
26
+ <username>sascha</username>
27
+ <created_at type="timestamp">2008-06-12T09:34:00+02:00</created_at>
28
+
29
+ <profile type="Profile" xlink:href="http://www.tagcrumbs.com/sascha/profile.xml"/>
30
+ <settings type="Settings" xlink:href="http://www.tagcrumbs.com/sascha/settings.xml"/>
31
+ <location type="Location" xlink:href="http://www.tagcrumbs.com/location.xml"/>
32
+ <suggestions type="Suggestions" xlink:href="http://www.tagcrumbs.com/sascha/tagcrumbs/suggestions.xml"/>
33
+ <filters type="array" xlink:href="http://www.tagcrumbs.com/sascha/filters.xml"/>
34
+ <links type="array" xlink:href="http://www.tagcrumbs.com/sascha/links.xml"/>
35
+ <comments type="array" xlink:href="http://www.tagcrumbs.com/sascha/comments.xml"/>
36
+ <flags type="array" xlink:href="http://www.tagcrumbs.com/sascha/flags.xml"/>
37
+ <recommendations type="array" xlink:href="http://www.tagcrumbs.com/sascha/recommendations.xml"/>
38
+
39
+ <received_recommendations type="array" xlink:href="http://www.tagcrumbs.com/sascha/recommendations/received.xml"/>
40
+ <subscriptions type="array" xlink:href="http://www.tagcrumbs.com/sascha/subscriptions.xml"/>
41
+ <picture type="Picture" xlink:href="http://www.tagcrumbs.com/sascha/profile/picture.xml"/>
42
+ <profile_links type="array" xlink:href="http://www.tagcrumbs.com/sascha/profile/links.xml"/>
43
+ <tagcrumbs type="array" xlink:href="http://www.tagcrumbs.com/sascha/tagcrumbs.xml"/>
44
+ <placemarks type="array" xlink:href="http://www.tagcrumbs.com/sascha/placemarks.xml"/>
45
+ <favorites type="array" xlink:href="http://www.tagcrumbs.com/sascha/favorites.xml"/>
46
+ <activities type="array" xlink:href="http://www.tagcrumbs.com/sascha/activities.xml"/>
47
+ <tags type="array" xlink:href="http://www.tagcrumbs.com/sascha/tags.xml"/>
48
+
49
+ <places type="array" xlink:href="http://www.tagcrumbs.com/sascha/places.xml"/>
50
+ <friendships type="array" xlink:href="http://www.tagcrumbs.com/sascha/friends.xml"/>
51
+ <fanships type="array" xlink:href="http://www.tagcrumbs.com/sascha/fans.xml"/>
52
+ <tagcrumbs_friends type="array" xlink:href="http://www.tagcrumbs.com/sascha/friends/tagcrumbs.xml"/>
53
+ <tagcrumbs_fans type="array" xlink:href="http://www.tagcrumbs.com/sascha/fans/tagcrumbs.xml"/>
54
+ </user>
55
+ <tagcrumb type="Placemark" xlink:href="http://www.tagcrumbs.com/sascha/placemarks/placemark-name.xml">
56
+ <name>PLACEMARK NAME</name>
57
+
58
+ <notes>PLACEMARK NOTES</notes>
59
+ <tag_list>tag1, tag2</tag_list>
60
+ <latitude type="float">48.7189419455889</latitude>
61
+ <longitude type="float">8.96329879760742</longitude>
62
+ <permalink>placemark-name</permalink>
63
+ <favorites_count type="integer">0</favorites_count>
64
+
65
+ <short_url>http://www.tagcrumbs.com/p/ZGM2ZTk</short_url>
66
+ <created_at type="timestamp">2009-02-01T14:41:11+01:00</created_at>
67
+ <updated_at type="timestamp">2009-02-20T07:53:06+01:00</updated_at>
68
+ <private type="boolean">false</private>
69
+ <city type="City" xlink:href="http://www.tagcrumbs.com/places/germany/states/land-baden-w%C3%BCrttemberg/cities/b%C3%B6blingen.xml"/>
70
+ <address type="Address" xlink:href="http://www.tagcrumbs.com/sascha/placemarks/placemark-name/address.xml"/>
71
+ <links type="array" xlink:href="http://www.tagcrumbs.com/sascha/placemarks/placemark-name/links.xml"/>
72
+
73
+ <recommendations type="array" xlink:href="http://www.tagcrumbs.com/sascha/placemarks/placemark-name/recommendations.xml"/>
74
+ <comments type="array" xlink:href="http://www.tagcrumbs.com/sascha/placemarks/placemark-name/comments.xml"/>
75
+ <user type="User" xlink:href="http://www.tagcrumbs.com/sascha.xml">
76
+ <username>sascha</username>
77
+ <created_at type="timestamp">2008-06-12T09:34:00+02:00</created_at>
78
+ <profile type="Profile" xlink:href="http://www.tagcrumbs.com/sascha/profile.xml"/>
79
+ <settings type="Settings" xlink:href="http://www.tagcrumbs.com/sascha/settings.xml"/>
80
+ <location type="Location" xlink:href="http://www.tagcrumbs.com/location.xml"/>
81
+
82
+ <suggestions type="Suggestions" xlink:href="http://www.tagcrumbs.com/sascha/tagcrumbs/suggestions.xml"/>
83
+ <filters type="array" xlink:href="http://www.tagcrumbs.com/sascha/filters.xml"/>
84
+ <links type="array" xlink:href="http://www.tagcrumbs.com/sascha/links.xml"/>
85
+ <comments type="array" xlink:href="http://www.tagcrumbs.com/sascha/comments.xml"/>
86
+ <flags type="array" xlink:href="http://www.tagcrumbs.com/sascha/flags.xml"/>
87
+ <recommendations type="array" xlink:href="http://www.tagcrumbs.com/sascha/recommendations.xml"/>
88
+ <received_recommendations type="array" xlink:href="http://www.tagcrumbs.com/sascha/recommendations/received.xml"/>
89
+ <subscriptions type="array" xlink:href="http://www.tagcrumbs.com/sascha/subscriptions.xml"/>
90
+ <picture type="Picture" xlink:href="http://www.tagcrumbs.com/sascha/profile/picture.xml"/>
91
+
92
+ <profile_links type="array" xlink:href="http://www.tagcrumbs.com/sascha/profile/links.xml"/>
93
+ <tagcrumbs type="array" xlink:href="http://www.tagcrumbs.com/sascha/tagcrumbs.xml"/>
94
+ <placemarks type="array" xlink:href="http://www.tagcrumbs.com/sascha/placemarks.xml"/>
95
+ <favorites type="array" xlink:href="http://www.tagcrumbs.com/sascha/favorites.xml"/>
96
+ <activities type="array" xlink:href="http://www.tagcrumbs.com/sascha/activities.xml"/>
97
+ <tags type="array" xlink:href="http://www.tagcrumbs.com/sascha/tags.xml"/>
98
+ <places type="array" xlink:href="http://www.tagcrumbs.com/sascha/places.xml"/>
99
+ <friendships type="array" xlink:href="http://www.tagcrumbs.com/sascha/friends.xml"/>
100
+ <fanships type="array" xlink:href="http://www.tagcrumbs.com/sascha/fans.xml"/>
101
+
102
+ <tagcrumbs_friends type="array" xlink:href="http://www.tagcrumbs.com/sascha/friends/tagcrumbs.xml"/>
103
+ <tagcrumbs_fans type="array" xlink:href="http://www.tagcrumbs.com/sascha/fans/tagcrumbs.xml"/>
104
+ </user>
105
+ </tagcrumb>
106
+ </recommendation>
@@ -0,0 +1,5 @@
1
+ {
2
+ "errors": {
3
+ "error": ["general message", "two is invalid"]
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <errors>
3
+ <error>general message</error>
4
+ <error>two is invalid</error>
5
+ </errors>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <test xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="test_xlink">
3
+ <child xlink:href="child_xlink">
4
+ <deep>test</deep>
5
+ </child>
6
+ <empty_single attribute="allowed"/>
7
+ <empty_closed attribute="allowed"></empty_closed>
8
+ <array>
9
+ <element>one</element>
10
+ <element>two</element>
11
+ </array>
12
+ <simple>value</simple>
13
+ </test>
@@ -0,0 +1 @@
1
+ --colour
@@ -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', "&lt;b&gt; 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