badgeville_berlin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/.yardoc/checksums +17 -0
  5. data/.yardoc/objects/root.dat +0 -0
  6. data/.yardoc/proxy_types +0 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.md +7 -0
  9. data/README.md +150 -0
  10. data/README_ADVANCED.md +120 -0
  11. data/Rakefile +11 -0
  12. data/badgeville.gemspec +36 -0
  13. data/doc/BadgevilleBerlin.html +131 -0
  14. data/doc/BadgevilleBerlin/Activity.html +135 -0
  15. data/doc/BadgevilleBerlin/ActivityDefinition.html +135 -0
  16. data/doc/BadgevilleBerlin/BaseResource.html +462 -0
  17. data/doc/BadgevilleBerlin/Config.html +280 -0
  18. data/doc/BadgevilleBerlin/Errors.html +276 -0
  19. data/doc/BadgevilleBerlin/Group.html +135 -0
  20. data/doc/BadgevilleBerlin/Leaderboard.html +135 -0
  21. data/doc/BadgevilleBerlin/Player.html +135 -0
  22. data/doc/BadgevilleBerlin/Reward.html +135 -0
  23. data/doc/BadgevilleBerlin/RewardDefinition.html +135 -0
  24. data/doc/BadgevilleBerlin/Site.html +135 -0
  25. data/doc/BadgevilleBerlin/Track.html +135 -0
  26. data/doc/BadgevilleBerlin/User.html +135 -0
  27. data/doc/BadgevilleBerlinJsonFormat.html +530 -0
  28. data/doc/_index.html +285 -0
  29. data/doc/class_list.html +47 -0
  30. data/doc/css/common.css +1 -0
  31. data/doc/css/full_list.css +53 -0
  32. data/doc/css/style.css +320 -0
  33. data/doc/file.README.html +182 -0
  34. data/doc/file_list.html +49 -0
  35. data/doc/frames.html +13 -0
  36. data/doc/index.html +182 -0
  37. data/doc/js/app.js +205 -0
  38. data/doc/js/full_list.js +150 -0
  39. data/doc/js/jquery.js +16 -0
  40. data/doc/method_list.html +118 -0
  41. data/doc/top-level-namespace.html +103 -0
  42. data/examples/.DS_Store +0 -0
  43. data/examples/shell/.DS_Store +0 -0
  44. data/examples/shell/lib/.DS_Store +0 -0
  45. data/examples/shell/lib/berlin_shell.rb +34 -0
  46. data/examples/shell/lib/berlin_shell/.DS_Store +0 -0
  47. data/examples/shell/lib/berlin_shell/cd.rb +17 -0
  48. data/examples/shell/lib/berlin_shell/core.rb +118 -0
  49. data/examples/shell/lib/berlin_shell/ls.rb +72 -0
  50. data/examples/shell/lib/berlin_shell/prompt.rb +39 -0
  51. data/examples/shell/shell_demo.rb +319 -0
  52. data/examples/shell/spec/integration/basic_spec.rb +7 -0
  53. data/lib/.yardoc/checksums +0 -0
  54. data/lib/.yardoc/objects/root.dat +0 -0
  55. data/lib/.yardoc/proxy_types +0 -0
  56. data/lib/badgeville_berlin.rb +24 -0
  57. data/lib/badgeville_berlin/.yardoc/checksums +0 -0
  58. data/lib/badgeville_berlin/.yardoc/objects/root.dat +0 -0
  59. data/lib/badgeville_berlin/.yardoc/proxy_types +0 -0
  60. data/lib/badgeville_berlin/activity.rb +5 -0
  61. data/lib/badgeville_berlin/activity_definition.rb +5 -0
  62. data/lib/badgeville_berlin/base_resource.rb +68 -0
  63. data/lib/badgeville_berlin/config.rb +36 -0
  64. data/lib/badgeville_berlin/doc/_index.html +84 -0
  65. data/lib/badgeville_berlin/doc/class_list.html +47 -0
  66. data/lib/badgeville_berlin/doc/css/common.css +1 -0
  67. data/lib/badgeville_berlin/doc/css/full_list.css +53 -0
  68. data/lib/badgeville_berlin/doc/css/style.css +320 -0
  69. data/lib/badgeville_berlin/doc/file_list.html +46 -0
  70. data/lib/badgeville_berlin/doc/frames.html +13 -0
  71. data/lib/badgeville_berlin/doc/index.html +84 -0
  72. data/lib/badgeville_berlin/doc/js/app.js +205 -0
  73. data/lib/badgeville_berlin/doc/js/full_list.js +150 -0
  74. data/lib/badgeville_berlin/doc/js/jquery.js +16 -0
  75. data/lib/badgeville_berlin/doc/method_list.html +46 -0
  76. data/lib/badgeville_berlin/doc/top-level-namespace.html +93 -0
  77. data/lib/badgeville_berlin/errors.rb +28 -0
  78. data/lib/badgeville_berlin/formats/badgeville_berlin_json_format.rb +55 -0
  79. data/lib/badgeville_berlin/group.rb +5 -0
  80. data/lib/badgeville_berlin/leaderboard.rb +5 -0
  81. data/lib/badgeville_berlin/player.rb +5 -0
  82. data/lib/badgeville_berlin/reward.rb +5 -0
  83. data/lib/badgeville_berlin/reward_definition.rb +5 -0
  84. data/lib/badgeville_berlin/site.rb +5 -0
  85. data/lib/badgeville_berlin/track.rb +5 -0
  86. data/lib/badgeville_berlin/user.rb +5 -0
  87. data/lib/badgeville_berlin/version.rb +3 -0
  88. data/lib/doc/_index.html +84 -0
  89. data/lib/doc/class_list.html +47 -0
  90. data/lib/doc/css/common.css +1 -0
  91. data/lib/doc/css/full_list.css +53 -0
  92. data/lib/doc/css/style.css +320 -0
  93. data/lib/doc/file_list.html +46 -0
  94. data/lib/doc/frames.html +13 -0
  95. data/lib/doc/index.html +84 -0
  96. data/lib/doc/js/app.js +205 -0
  97. data/lib/doc/js/full_list.js +150 -0
  98. data/lib/doc/js/jquery.js +16 -0
  99. data/lib/doc/method_list.html +46 -0
  100. data/lib/doc/top-level-namespace.html +93 -0
  101. data/spec/factories.rb +54 -0
  102. data/spec/integration/activity_spec.rb +0 -0
  103. data/spec/integration/basic_spec.rb +68 -0
  104. data/spec/integration/player_spec.rb +6 -0
  105. data/spec/integration/site_spec.rb +11 -0
  106. data/spec/integration/user_spec.rb +3 -0
  107. data/spec/response_json.yml +36 -0
  108. data/spec/spec_helper.rb +60 -0
  109. data/spec/unit/badgeville_berlin_json_format_spec.rb +68 -0
  110. data/spec/unit/base_resource_spec.rb +47 -0
  111. data/spec/unit/config_spec.rb +65 -0
  112. data/spec/unit/errors_spec.rb +47 -0
  113. data/spec/use_case/readme_use_case_spec.rb +262 -0
  114. metadata +286 -0
data/spec/factories.rb ADDED
@@ -0,0 +1,54 @@
1
+ FactoryGirl.define do
2
+ factory :activity, :class => BadgevilleBerlin::Activity do
3
+ _id '4f0b435ea768656ca400001b'
4
+ end
5
+
6
+ factory :activity_definition, :class => BadgevilleBerlin::ActivityDefinition do
7
+ _id '4f0b435ea768656ca400001b'
8
+ name 'A Cool Comment Behavior'
9
+ site_id '4f079a04a76865329a000087'
10
+ selector '{"verb" : "comment"}'
11
+ adjustment '{"points" : 5}'
12
+ end
13
+
14
+ factory :group, :class => BadgevilleBerlin::Group do
15
+ _id "4f05ef5ea768651b3500009f"
16
+ end
17
+
18
+ factory :leaderboard, :class => BadgevilleBerlin::Leaderboard do
19
+ _id "4f05ef5ea768651b3500009f"
20
+ end
21
+
22
+ factory :player, :class => BadgevilleBerlin::Player do
23
+ _id '4f0b29bca76865329a0000ae'
24
+ email 'supraja220494@BadgevilleBerlin-berlin.com'
25
+ end
26
+
27
+ factory :reward, :class => BadgevilleBerlin::Reward do
28
+ _id '4f0b29bca76865329a0000ae'
29
+ end
30
+
31
+ factory :reward_definition, :class => BadgevilleBerlin::RewardDefinition do
32
+ _id '4f0b29bca76865329a0000ae'
33
+ end
34
+
35
+ factory :site, :class => BadgevilleBerlin::Site do
36
+ _id '4f079a04a76865329a000087'
37
+ name "My Website"
38
+ url "mydomain.com"
39
+ network_id '4d5dc61ed0c0b32b79000001'
40
+ end
41
+
42
+ factory :track, :class => BadgevilleBerlin::Track do
43
+ _id '4f0b29bca76865329a0000ae'
44
+ end
45
+
46
+ factory :user, :class => BadgevilleBerlin::User do
47
+ _id "4f05ef5ea768651b3500009f"
48
+ name "visitor_username"
49
+ network_id "4d5dc61ed0c0b32b79000001"
50
+ email "visitor@emailserver.com"
51
+ password "testing123"
52
+ end
53
+ end
54
+
File without changes
@@ -0,0 +1,68 @@
1
+ module BadgevilleBerlin
2
+ [Activity, ActivityDefinition, Group, Leaderboard, Player, Reward, RewardDefinition, Site, Track, User].each do |module_klass|
3
+ klass = module_klass.to_s.split('::')[1].underscore
4
+ describe 'Create a new ' + klass do
5
+ before do
6
+ @mock = Factory.build(klass)
7
+ @mock_json = BadgevilleBerlin.response_json["valid_" + klass + "_create"]
8
+ @path = ENDPOINTKEY + "/" + klass.pluralize + ".json"
9
+ @method = :post
10
+ @mock_http = MockHTTP.new(@method, @path, {:body => @mock_json, :status => [201, "Created"]})
11
+ end
12
+
13
+ it "should make the correct http request and return the correct object." do
14
+ @mock_http.request.should_receive(:send).with(@method, @path, @mock.to_json, {"Content-Type"=>"application/json"}).and_return(@mock_http.response)
15
+ @mock.save()
16
+ BadgevilleBerlin.test_attr(@mock, @mock_json)
17
+ end
18
+ end
19
+
20
+ describe "Find a " + klass do
21
+ before do
22
+ @mock = Factory.build(klass)
23
+ @mock_json = BadgevilleBerlin.response_json["valid_" + klass + "_find"]
24
+ @path = ENDPOINTKEY + "/" + klass.pluralize + "/" + @mock._id + ".json"
25
+ @method = :get
26
+ @mock_http = MockHTTP.new(@method, @path, {:body => @mock_json, :status => [200, "Ok"]})
27
+ end
28
+
29
+ it "should make the correct http request and return the correct object." do
30
+ @mock_http.request.should_receive(:send).with(@method, @path, {"Accept"=>"application/json"}).and_return(@mock_http.response)
31
+ @mock = module_klass.find(@mock._id)
32
+ BadgevilleBerlin.test_attr(@mock, @mock_json)
33
+ end
34
+ end
35
+
36
+ describe "Update a " + klass do
37
+ before do
38
+ @mock = Factory.build(klass)
39
+ @mock_json = BadgevilleBerlin.response_json["valid_" + klass + "_update"]
40
+ @path = ENDPOINTKEY + "/" + klass.pluralize + "/" + @mock._id + ".json"
41
+ @method = :put
42
+ @mock_http = MockHTTP.new(@method, @path, {:body => @mock_json, :status => [200, "Ok"]})
43
+ @mock.stub(:persisted?).and_return(true) # Force ActiveResource to use put
44
+ end
45
+
46
+ it "should make the correct http request." do
47
+ @mock_http.request.should_receive(:send).with(@method, @path, @mock.to_json, {"Content-Type"=>"application/json"}).and_return(@mock_http.response)
48
+ @mock.save()
49
+ # BadgevilleBerlin.test_attr(@mock, @mock_json)
50
+ end
51
+ end
52
+
53
+ describe "Delete a " + klass do
54
+ before do
55
+ @mock = Factory.build(klass)
56
+ @mock_json = "{\"data\":{\"name\":\"visitor_username\",\"created_at\":\"2012-01-05T10:43:42-08:00\",\"email\":\"revised_visitor@emailserver.com\",\"_id\":\"4f05ef5ea768651b3500009f\"},\"paging\":null}" #Factory.build(klass + '_json_save')
57
+ @path = ENDPOINTKEY + "/" + klass.pluralize + "/" + @mock._id + ".json"
58
+ @method = :delete
59
+ @mock_http = MockHTTP.new(@method, @path, {:body => @mock_json, :status => [200, "Ok"]})
60
+ end
61
+
62
+ it "should make the correct http request." do
63
+ @mock_http.request.should_receive(:send).with(@method, @path, {"Accept"=>"application/json"}).and_return(@mock_http.response)
64
+ module_klass.delete(@mock._id)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+
3
+
4
+ module BadgevilleBerlin
5
+
6
+ end
@@ -0,0 +1,11 @@
1
+ require 'badgeville_berlin'
2
+ require 'rspec'
3
+ require 'fakeweb'
4
+ require 'factory_girl'
5
+ require 'ruby-debug'
6
+ require 'factories.rb'
7
+
8
+
9
+ module BadgevilleBerlin
10
+
11
+ end
@@ -0,0 +1,3 @@
1
+ module BadgevilleBerlin
2
+
3
+ end
@@ -0,0 +1,36 @@
1
+ valid_site_create: "{\"name\":\"TsOjhaGEmkewjSrD\",\"created_at\":\"2012-01-25T11:21:00-08:00\",\"url\":\"TsOjhaGEmkewjSrD.com\",\"id\":\"4f20561ca7686573bb0003e2\",\"_id\":\"4f20561ca7686573bb0003e2\"}"
2
+ valid_site_find: "{\"data\":{\"name\":\"TsOjhaGEmkewjSrD\",\"created_at\":\"2012-01-25T11:21:00-08:00\",\"url\":\"TsOjhaGEmkewjSrD.com\",\"id\":\"4f20561ca7686573bb0003e2\",\"_id\":\"4f20561ca7686573bb0003e2\"},\"paging\":null}"
3
+ valid_group_create: "{\"id\":\"4f20561ca7686573bb0003e3\",\"name\":\"hmGxHthofkrqxIJT\",\"type\":\"ladder\",\"image_url\":null,\"tip\":null,\"message\":null,\"privileges\":null,\"note\":null,\"display_priority\":0,\"reward_definitions\":[],\"reward_image_url\":null}"
4
+ valid_group_find: "{\"data\":{\"id\":\"4f20561ca7686573bb0003e3\",\"name\":\"hmGxHthofkrqxIJT\",\"type\":\"ladder\",\"image_url\":null,\"tip\":null,\"message\":null,\"privileges\":null,\"note\":null,\"display_priority\":0,\"reward_definitions\":[],\"reward_image_url\":null},\"paging\":null}"
5
+ valid_leaderboard_create: "{\"id\":\"4f20561da7686573bb0003e4\",\"type\":\"Leaderboard\",\"name\":\"rcXUaKNRcaeDfAkO\",\"target_model\":\"Activity\",\"command\":\"sum\",\"field\":\"+5\",\"selector\":{},\"label\":\"rcXUaKNRcaeDfAkO\",\"data\":{}}"
6
+ valid_leaderboard_find: "{\"data\":{\"id\":\"4f20561da7686573bb0003e4\",\"type\":\"Leaderboard\",\"name\":\"rcXUaKNRcaeDfAkO\",\"target_model\":\"Activity\",\"command\":\"sum\",\"field\":\"+5\",\"selector\":{},\"label\":\"rcXUaKNRcaeDfAkO\",\"data\":{}},\"paging\":null}"
7
+ valid_user_create: "{\"name\":\"UQrQtllBUanUCSoj\",\"created_at\":\"2012-01-25T11:21:01-08:00\",\"email\":\"UQrQtllBUanUCSoj@badgeville.com\",\"_id\":\"4f20561da7686573bb0003e5\"}"
8
+ valid_user_find: "{\"data\":{\"name\":\"UQrQtllBUanUCSoj\",\"created_at\":\"2012-01-25T11:21:01-08:00\",\"email\":\"UQrQtllBUanUCSoj@badgeville.com\",\"_id\":\"4f20561da7686573bb0003e5\"},\"paging\":null}"
9
+ valid_player_create: "{\"_id\":\"4f20561ea7686573bb0003e6\",\"id\":\"4f20561ea7686573bb0003e6\",\"name\":\"UQrQtllBUanUCSoj\",\"first_name\":\"FYRCjkgJfGQVkchR\",\"last_name\":\"FYRCjkgJfGQVkchR\",\"display_name\":null,\"nick_name\":null,\"email\":\"UQrQtllBUanUCSoj@badgeville.com\",\"user_email\":\"UQrQtllBUanUCSoj@badgeville.com\",\"created_at\":\"2012-01-25T11:21:02-08:00\",\"user_id\":\"4f20561da7686573bb0003e5\",\"site_id\":\"4f20561ca7686573bb0003e2\",\"site_url\":\"TsOjhaGEmkewjSrD.com\",\"admin\":false,\"points_day\":0.0,\"points_week\":0.0,\"points_month\":0.0,\"points_all\":0.0,\"facebook_id\":null,\"facebook_link\":null,\"twitter_id\":null,\"twitter_username\":null,\"twitter_link\":null,\"email_notifications\":true,\"custom_picture_url\":null,\"picture_url\":null,\"preferences\":{\"email_notifications\":true,\"hide_notifications\":false,\"publish_activity\":true},\"tracks\":{},\"units\":{\"points_day\":0.0,\"points_week\":0.0,\"points_month\":0.0,\"points_all\":0.0,\"badges_day\":0,\"badges_week\":0,\"badges_month\":0,\"badges_all\":0}}"
10
+ valid_player_find: "{\"data\":{\"_id\":\"4f20561ea7686573bb0003e6\",\"id\":\"4f20561ea7686573bb0003e6\",\"name\":\"UQrQtllBUanUCSoj\",\"first_name\":\"FYRCjkgJfGQVkchR\",\"last_name\":\"FYRCjkgJfGQVkchR\",\"display_name\":null,\"nick_name\":null,\"email\":\"UQrQtllBUanUCSoj@badgeville.com\",\"user_email\":\"UQrQtllBUanUCSoj@badgeville.com\",\"created_at\":\"2012-01-25T11:21:02-08:00\",\"user_id\":\"4f20561da7686573bb0003e5\",\"site_id\":\"4f20561ca7686573bb0003e2\",\"site_url\":\"TsOjhaGEmkewjSrD.com\",\"admin\":false,\"points_day\":0.0,\"points_week\":0.0,\"points_month\":0.0,\"points_all\":0.0,\"facebook_id\":null,\"facebook_link\":null,\"twitter_id\":null,\"twitter_username\":null,\"twitter_link\":null,\"email_notifications\":true,\"custom_picture_url\":null,\"picture_url\":null,\"preferences\":{\"email_notifications\":true,\"hide_notifications\":false,\"publish_activity\":true},\"tracks\":{},\"units\":{\"points_day\":0.0,\"points_week\":0.0,\"points_month\":0.0,\"points_all\":0.0,\"badges_day\":0,\"badges_week\":0,\"badges_month\":0,\"badges_all\":0}},\"paging\":null}"
11
+ valid_reward_definition_create: "{\"type\":\"rewarddefinition\",\"name\":\"VIFsIFJOJffENkDx\",\"created_at\":\"2012-01-25T11:21:02-08:00\",\"assignable\":false,\"allow_duplicates\":false,\"components\":\"[]\",\"reward_template\":{},\"tags\":null,\"site_id\":\"4f20561ca7686573bb0003e2\",\"image_url\":\"http://staging.badgeville.com/images/misc/missing_badge.png\",\"image_file_name\":null,\"data\":{},\"_id\":\"4f20561ea7686573bb0003e7\",\"id\":\"4f20561ea7686573bb0003e7\",\"active\":false,\"hint\":null,\"message\":null,\"active_start_at\":null,\"active_end_at\":null}"
12
+ valid_reward_definition_find: "{\"data\":{\"type\":\"rewarddefinition\",\"name\":\"VIFsIFJOJffENkDx\",\"created_at\":\"2012-01-25T11:21:02-08:00\",\"assignable\":false,\"allow_duplicates\":false,\"components\":\"[]\",\"reward_template\":{},\"tags\":null,\"site_id\":\"4f20561ca7686573bb0003e2\",\"image_url\":\"http://staging.badgeville.com/images/misc/missing_badge.png\",\"image_file_name\":null,\"data\":{},\"_id\":\"4f20561ea7686573bb0003e7\",\"id\":\"4f20561ea7686573bb0003e7\",\"active\":false,\"hint\":null,\"message\":null,\"active_start_at\":null,\"active_end_at\":null},\"paging\":null}"
13
+ valid_reward_create: "{\"name\":\"VIFsIFJOJffENkDx\",\"created_at\":\"2012-01-25T11:21:03-08:00\",\"activity_id\":null,\"id\":\"4f20561fa7686573bb0003e8\",\"user_id\":\"4f20561da7686573bb0003e5\",\"site_id\":\"4f20561ca7686573bb0003e2\",\"definition\":{\"type\":\"rewarddefinition\",\"name\":\"VIFsIFJOJffENkDx\",\"created_at\":\"2012-01-25T11:21:02-08:00\",\"assignable\":false,\"allow_duplicates\":false,\"components\":\"[]\",\"reward_template\":{},\"tags\":null,\"site_id\":\"4f20561ca7686573bb0003e2\",\"image_url\":\"http://staging.badgeville.com/images/misc/missing_badge.png\",\"image_file_name\":null,\"data\":{},\"_id\":\"4f20561ea7686573bb0003e7\",\"id\":\"4f20561ea7686573bb0003e7\",\"active\":false,\"hint\":null,\"message\":null,\"active_start_at\":null,\"active_end_at\":null},\"image\":\"http://staging.badgeville.com/images/misc/missing_badge.png\",\"tags\":[],\"status\":null,\"message\":null,\"history\":null,\"next_reward_id\":null}"
14
+ valid_reward_find: "{\"data\":{\"name\":\"VIFsIFJOJffENkDx\",\"created_at\":\"2012-01-25T11:21:03-08:00\",\"activity_id\":null,\"id\":\"4f20561fa7686573bb0003e8\",\"user_id\":\"4f20561da7686573bb0003e5\",\"site_id\":\"4f20561ca7686573bb0003e2\",\"definition\":{\"type\":\"rewarddefinition\",\"name\":\"VIFsIFJOJffENkDx\",\"created_at\":\"2012-01-25T11:21:02-08:00\",\"assignable\":false,\"allow_duplicates\":false,\"components\":\"[]\",\"reward_template\":{},\"tags\":null,\"site_id\":\"4f20561ca7686573bb0003e2\",\"image_url\":\"http://staging.badgeville.com/images/misc/missing_badge.png\",\"image_file_name\":null,\"data\":{},\"_id\":\"4f20561ea7686573bb0003e7\",\"id\":\"4f20561ea7686573bb0003e7\",\"active\":false,\"hint\":null,\"message\":null,\"active_start_at\":null,\"active_end_at\":null},\"image\":\"http://staging.badgeville.com/images/misc/missing_badge.png\",\"tags\":[],\"status\":null,\"message\":null,\"history\":null,\"next_reward_id\":null},\"paging\":null}"
15
+ valid_activity_definition_create: "{\"_id\":\"4f20561fa7686573bb0003e9\",\"name\":\"pQAwIayIcbVhQdns\",\"selector\":{\"verb\":\"read\"},\"adjustment\":{\"points\":5},\"bucket_drain_rate\":null,\"bucket_max_capacity\":null,\"limit_per_player\":null,\"limit_field_scope\":null,\"site_id\":\"4f20561ca7686573bb0003e2\",\"verb\":\"read\",\"icon\":null,\"tool_tip\":null,\"hide_in_widgets\":true,\"enable_rate_limiting\":false,\"enable_count_limiting\":false,\"enable_site_notification\":null,\"enable_user_notification\":null,\"enable_auto_subscription\":null,\"description\":null}"
16
+ valid_activity_definition_find: "{\"data\":{\"_id\":\"4f20561fa7686573bb0003e9\",\"name\":\"pQAwIayIcbVhQdns\",\"selector\":{\"verb\":\"read\"},\"adjustment\":{\"points\":5},\"bucket_drain_rate\":null,\"bucket_max_capacity\":null,\"limit_per_player\":null,\"limit_field_scope\":null,\"site_id\":\"4f20561ca7686573bb0003e2\",\"verb\":\"read\",\"icon\":null,\"tool_tip\":null,\"hide_in_widgets\":true,\"enable_rate_limiting\":false,\"enable_count_limiting\":false,\"enable_site_notification\":null,\"enable_user_notification\":null,\"enable_auto_subscription\":null,\"description\":null},\"paging\":null}"
17
+ valid_activity_create: "{\"_id\":\"4f205620a7686573aa0003f2\",\"created_at\":\"2012-01-25T11:21:04-08:00\",\"definition_ids\":[],\"deleted_at\":null,\"internal\":false,\"player_id\":\"4f20561ea7686573bb0003e6\",\"points\":0,\"shard_id\":\"690d7a5709dd29851a4546744fc34d2a\",\"site_id\":\"4f20561ca7686573bb0003e2\",\"team_ids\":[],\"user_id\":\"4f20561da7686573bb0003e5\",\"verb\":\"cVjEEoViLttiyAYT\",\"rewards\":[],\"contents\":[]}"
18
+ valid_activity_find: "{\"data\":{\"_id\":\"4f205620a7686573aa0003f2\",\"created_at\":\"2012-01-25T11:21:04-08:00\",\"definition_ids\":[],\"deleted_at\":null,\"internal\":false,\"player_id\":\"4f20561ea7686573bb0003e6\",\"points\":0,\"shard_id\":\"690d7a5709dd29851a4546744fc34d2a\",\"site_id\":\"4f20561ca7686573bb0003e2\",\"team_ids\":[],\"user_id\":\"4f20561da7686573bb0003e5\",\"verb\":\"cVjEEoViLttiyAYT\",\"rewards\":[],\"contents\":[]},\"paging\":null}"
19
+ valid_track_create: "{\"id\":\"4f205620a7686573aa0003f3\",\"label\":\"KAPPuWMooBMFAyAl\",\"type\":\"Track\",\"image_url\":null,\"hint\":null,\"missionList\":[],\"nextMission\":null}"
20
+ valid_track_find: "{\"data\":{\"id\":\"4f205620a7686573aa0003f3\",\"label\":\"KAPPuWMooBMFAyAl\",\"type\":\"Track\",\"image_url\":null,\"hint\":null,\"missionList\":[],\"nextMission\":null},\"paging\":null}"
21
+ valid_site_update: "{}"
22
+ valid_group_update: "{}"
23
+ valid_activity_definition_update: "{}"
24
+ valid_leaderboard_update: "{}"
25
+ valid_player_update: "{}"
26
+ valid_reward_definition_update: "{}"
27
+ valid_track_update: "{}"
28
+ valid_user_update: "{}"
29
+ valid_track_delete: "{}"
30
+ valid_activity_definition_delete: "{}"
31
+ valid_reward_delete: "{}"
32
+ valid_reward_definition_delete: "{}"
33
+ valid_player_delete: "{}"
34
+ valid_user_delete: "{}"
35
+ valid_group_delete: "{}"
36
+ valid_site_delete: "{}"
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'fakeweb'
4
+ require 'factory_girl'
5
+ require 'active_support/inflector'
6
+ require 'logger'
7
+ require_relative '../lib/badgeville_berlin'
8
+ require_relative 'factories'
9
+
10
+ RSpec.configure do |c|
11
+ c.filter_run_excluding :affects_bv_server => true
12
+ end
13
+
14
+ module BadgevilleBerlin
15
+ @@response_json = YAML::load(File.open("spec/response_json.yml"))
16
+
17
+ def self.response_json
18
+ @@response_json
19
+ end
20
+
21
+ HOST = "example.com"
22
+ APIKEY = "fakeapikey"
23
+ ENDPOINT = "/api/berlin/"
24
+ ENDPOINTKEY = ENDPOINT + APIKEY
25
+ PORT = "80"
26
+
27
+ FakeWeb.allow_net_connect = false # Requests to a URI you haven’t registered with #register_uri, a NetConnectNotAllowedError will be raised
28
+ Config.conf(:host_name => 'http://' + HOST + '/', :api_key => APIKEY)
29
+
30
+ # Instantiate a logger so HTTP request and response information will be
31
+ # printed to STDOUT.
32
+ BaseResource.logger = Logger.new(STDOUT)
33
+ BaseResource.logger.level = Logger::DEBUG
34
+
35
+ class MockHTTP
36
+ attr_accessor :request, :response
37
+
38
+ def initialize(method, path, options)
39
+ # URI must be registered to prevent fail
40
+ FakeWeb.register_uri(method, "http://" + HOST + ":" + PORT + path, options)
41
+ # Mocks
42
+ @request = Net::HTTP.new(HOST, PORT)
43
+ @response = @request.send(method, path, {"Accept"=>"application/json"})
44
+
45
+ # Force Net::HTTP.new to return @request
46
+ Net::HTTP.should_receive(:new).with(HOST, Integer(PORT)).and_return(@request)
47
+ end
48
+ end
49
+
50
+ def self.test_attr (mock, mock_json)
51
+ # BadgevilleBerlinJsonFormat::decode(mock_json).each do |key, value|
52
+ # value.should == mock.send(key)
53
+ # end
54
+ if mock_json != "{}"
55
+ BadgevilleBerlinJsonFormat::decode(mock_json)["_id"].should == mock.id
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,68 @@
1
+ describe BadgevilleBerlinJsonFormat, ".decode" do
2
+
3
+ it "should convert a string into a hash" do
4
+ BadgevilleBerlinJsonFormat.decode('{}').should == {}
5
+ end
6
+
7
+ it "should handle nils" do
8
+ BadgevilleBerlinJsonFormat.decode(nil).should == nil
9
+ end
10
+
11
+
12
+ context "with a single object" do
13
+
14
+ it "should handle it" do
15
+ @json_record_w_root =
16
+ "{\"data\":{\"name\":\"visitor_username\",\"created_at\":\"2012-01-05T10:43:42-08:00\",\"email\":\"revised_visitor@emailserver.com\",\"_id\":\"4f05ef5ea768651b3500009f\"},\"paging\":null}"
17
+
18
+ BadgevilleBerlinJsonFormat.decode(@json_record_w_root).should ==
19
+ {"name"=>"visitor_username", "created_at"=>"2012-01-05T10:43:42-08:00", "email"=>"revised_visitor@emailserver.com", "_id"=>"4f05ef5ea768651b3500009f"}
20
+ end
21
+
22
+ it "should handle when there's a nested key 'data'" do
23
+ @json_w_2_keys_data =
24
+ "{\"data\":{\"name\":\"visitor_username\",\"data\":\"value_of_nested_key_data\"},\"paging\":null}"
25
+
26
+ BadgevilleBerlinJsonFormat.decode(@json_w_2_keys_data).should == {"name"=>"visitor_username", "data" => "value_of_nested_key_data"}
27
+ end
28
+
29
+ it "should handle when there's no root key 'data'" do
30
+ @json_record_without_root =
31
+ "{\"name\":\"visitor_username\",\"created_at\":\"2012-01-05T10:43:42-08:00\",\"email\":\"revised_visitor@emailserver.com\",\"_id\":\"4f05ef5ea768651b3500009f\"}"
32
+
33
+ BadgevilleBerlinJsonFormat.decode(@json_record_without_root).should ==
34
+ {"name"=>"visitor_username", "created_at"=>"2012-01-05T10:43:42-08:00", "email"=>"revised_visitor@emailserver.com", "_id"=>"4f05ef5ea768651b3500009f"}
35
+ end
36
+
37
+ it "should return entire hash when there is an empty hash at root key 'data'" do
38
+ @json_record_data_empty =
39
+ "{\"data\":{}, \"name\":\"visitor_username\",\"created_at\":\"2012-01-05T10:43:42-08:00\",\"email\":\"revised_visitor@emailserver.com\",\"_id\":\"4f05ef5ea768651b3500009f\"}"
40
+ BadgevilleBerlinJsonFormat.decode(@json_record_data_empty).should ==
41
+ {"data"=>{}, "name"=>"visitor_username", "created_at"=>"2012-01-05T10:43:42-08:00", "email"=>"revised_visitor@emailserver.com", "_id"=>"4f05ef5ea768651b3500009f"}
42
+ end
43
+
44
+ end
45
+
46
+
47
+ context "with multiple objects" do
48
+ it "should handle it" do
49
+ @json_collection_w_root =
50
+ '{"data":[{"name":"visitor1","_id":"4dfa6cbc888bae20b0000016"},{"name":"visitor2","_id":"4dfa8908888bae20b50000d1"}],"paging":{"current_page":1,"per_page":10}}'
51
+
52
+ BadgevilleBerlinJsonFormat.decode(@json_collection_w_root).should ==
53
+ [ {"name" => "visitor1", "_id" => "4dfa6cbc888bae20b0000016"},
54
+ {"name" => "visitor2", "_id" => "4dfa8908888bae20b50000d1"} ]
55
+ end
56
+
57
+ it "should handle when there's no root key 'data'" do
58
+ @json_collection_without_root =
59
+ '[{"name":"visitor1","_id":"4dfa6cbc888bae20b0000016"},{"name":"visitor2","_id":"4dfa8908888bae20b50000d1"}]'
60
+
61
+ BadgevilleBerlinJsonFormat.decode(@json_collection_without_root).should ==
62
+ [ {"name" => "visitor1", "_id" => "4dfa6cbc888bae20b0000016"},
63
+ {"name" => "visitor2", "_id" => "4dfa8908888bae20b50000d1"} ]
64
+ end
65
+ end
66
+
67
+ end
68
+
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+ require 'factories'
3
+
4
+ module BadgevilleBerlin
5
+
6
+ describe BaseResource, ".errors" do
7
+ before do
8
+ @mock_user_without_err_obj = User.new
9
+ @mock_user_with_errors_obj = User.new
10
+ @mock_user_with_errors_obj.errors.add(:base, "Mock error string.")
11
+ end
12
+
13
+ context "BaseResource has associated BadgevilleBerlin::Errors object" do
14
+ it "should call .new from BadgevilleBerlin::Errors (not from ActiveResource::Errors)" do
15
+ BadgevilleBerlin::Errors.should_receive( :new )
16
+ @mock_user_without_err_obj.errors
17
+ end
18
+ end
19
+
20
+ context "BaseResource does not have associated BadgevilleBerlin::Errors object" do
21
+ it "should not call .new for BadgevilleBerlin::Errors" do
22
+ BadgevilleBerlin::Errors.should_not_receive( :new )
23
+ @mock_user_with_errors_obj.errors
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ describe BaseResource, ".encode" do
30
+ before do
31
+ @mock_activity_definition = Factory.create(:activity_definition)
32
+ end
33
+
34
+ context "BaseResource passes correct arguments to send method" do
35
+ it "should call sanitize request and update record." do
36
+ @mock_activity_definition.bucket_drain_rate = 180
37
+ @path = ENDPOINTKEY + "/activity_definitions/" + @mock_activity_definition._id + ".json"
38
+
39
+ @mock_activity_definition.should_receive(:sanitize_request)
40
+ @mock_http = MockHTTP.new(:put, @path, {:body => BadgevilleBerlin.response_json["valid_activity_definition_update"], :status => [200, "Ok"]})
41
+ @mock_activity_definition.save()
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,65 @@
1
+ module BadgevilleBerlin
2
+
3
+ describe Config, ".conf" do
4
+
5
+ before do
6
+ @host_name = 'http://example.com'
7
+ @my_api_key = 'fakeapikey'
8
+ Config.conf(:host_name => @host_name, :api_key => @my_api_key)
9
+ @empty_string = ''
10
+ end
11
+
12
+
13
+ context "where host name and API key are both valid" do
14
+ it "should assign the user-specified scheme to BaseResource.site.scheme" do
15
+ BaseResource.site.scheme.should == @host_name.split('://')[0]
16
+ end
17
+
18
+ it "should assign the user-specified host to BaseResource.site.host" do
19
+ BaseResource.site.host.should == @host_name.split('://')[1]
20
+ end
21
+
22
+ it "should contain the user-specified apikey to BaseResource.prefix" do
23
+ BaseResource.prefix.should == "/api/berlin/#{@my_api_key}/"
24
+ end
25
+ end
26
+
27
+
28
+ context "where host name is empty or not given, but API key is valid" do
29
+ it "should raise an ArgumentError with an error message" do
30
+ lambda { Config.conf(:host_name => @empty_string, :api_key => @my_api_key) }.should raise_error(ArgumentError)
31
+ end
32
+
33
+ it "should raise ArgumentError" do
34
+ lambda { Config.conf(:api_key => @my_api_key) }.should raise_error(ArgumentError)
35
+ end
36
+ end
37
+
38
+
39
+ context "where API Key is empty or not given, but the host name is valid" do
40
+ it "should raise ArgumentError" do
41
+ lambda { Config.conf(:host_name => @host_name, :api_key => @empty_string) }.should raise_error(ArgumentError)
42
+ end
43
+
44
+ it "should raise ArgumentError" do
45
+ lambda { Config.conf(:host_name => @host_name) }.should raise_error(ArgumentError)
46
+ end
47
+ end
48
+
49
+
50
+ context "where neither host name or API key are given" do
51
+ it "should raise ArgumentError" do
52
+ lambda { Config.conf }.should raise_error(ArgumentError)
53
+ end
54
+ end
55
+
56
+
57
+ context "where the :host_name has no scheme (i.e. no 'http')" do
58
+ it "should raise ArgumentError" do
59
+ @host_name_no_scheme = 'example.com'
60
+ lambda { Config.conf(:host_name => @host_name_no_scheme, :api_key => @my_api_key) }.should raise_error(ArgumentError)
61
+ end
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ module BadgevilleBerlin
4
+ describe Errors, ".from_badgeville_berlin_json" do
5
+ before do
6
+ @mock_user = User.new
7
+ @mock_error = Errors.new(@mock_user)
8
+ Errors.stub(:new).and_return(@mock_error);
9
+ end
10
+
11
+
12
+ it "should handle nils" do
13
+ @mock_error.from_badgeville_berlin_json( nil )
14
+ @mock_error.messages.should == {}
15
+ end
16
+
17
+
18
+ context "without root key 'errors'" do
19
+
20
+ it "should set error messages for errors object" do
21
+ json_without_root_key = "{\"email\":[\"user email is already taken\"]}"
22
+ @mock_error.from_badgeville_berlin_json( json_without_root_key )
23
+ @mock_error.messages.should == {:base=>["Email user email is already taken"]}
24
+ end
25
+
26
+ end
27
+
28
+
29
+ context "with root key 'errors'" do
30
+
31
+ it "should set error messages for errors object" do
32
+ json_w_root_key = "{\"errors\": {\"email\":[\"user email is already taken\"]}}"
33
+ @mock_error.from_badgeville_berlin_json( json_w_root_key )
34
+ @mock_error.messages.should == {:base=>["Email user email is already taken"]}
35
+ end
36
+
37
+ # #(ActiveSupport::JSON.decode(json))['errors']
38
+ # #MultiJson::DecodeError Exception: 710: unexpected token at '{"errors": {"errors":["user email is already taken"]}'
39
+ it "error messages should be set to empty when there is a nested key 'errors'" do
40
+ @json_two_errors_keys = "{\"errors\": {\"errors\":[\"user email is already taken\"]}"
41
+ @mock_error.from_badgeville_berlin_json( @json_two_errors_keys )
42
+ @mock_error.messages.should == {}
43
+ end
44
+ end
45
+
46
+ end
47
+ end