plataforma_social 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/.DS_Store +0 -0
  2. data/.rspec +1 -0
  3. data/CHANGELOG.rdoc +4 -0
  4. data/Gemfile +4 -1
  5. data/lib/plataforma_social.rb +5 -0
  6. data/lib/plataforma_social/badge.rb +61 -0
  7. data/lib/plataforma_social/domains.rb +1 -1
  8. data/lib/plataforma_social/helpers.rb +9 -5
  9. data/lib/plataforma_social/ranking.rb +91 -0
  10. data/lib/plataforma_social/ranking/custom.rb +28 -0
  11. data/lib/plataforma_social/ranking/general.rb +22 -0
  12. data/lib/plataforma_social/request.rb +4 -14
  13. data/lib/plataforma_social/support.rb +25 -0
  14. data/lib/plataforma_social/version.rb +1 -1
  15. data/plataforma_social.gemspec +6 -0
  16. data/spec/.DS_Store +0 -0
  17. data/spec/cassettes/PlataformaSocial_Badge/CREATE_a_new_badge/when_request_is_successful.yml +51 -0
  18. data/spec/cassettes/PlataformaSocial_Badge/GIVE_points_to_user/when_request_is_successful_and_badges_is_array.yml +99 -0
  19. data/spec/cassettes/PlataformaSocial_Badge/GIVE_points_to_user/when_request_is_successful_and_badges_is_hash.yml +101 -0
  20. data/spec/cassettes/PlataformaSocial_Badge/return_INDEX_to_user/when_request_is_successful_and_user_has_already_earned_some_badge.yml +204 -0
  21. data/spec/cassettes/PlataformaSocial_Badge/return_INDEX_to_user/when_request_is_successful_but_user_hasnt_earned_any_badge.yml +202 -0
  22. data/spec/cassettes/PlataformaSocial_Ranking/GET_friends/when_request_is_successful/with_limit_param.yml +48 -0
  23. data/spec/cassettes/PlataformaSocial_Ranking/GET_friends/when_request_is_successful/with_page_and_limit_param.yml +48 -0
  24. data/spec/cassettes/PlataformaSocial_Ranking/GET_friends/when_request_is_successful/with_page_param.yml +48 -0
  25. data/spec/cassettes/PlataformaSocial_Ranking/GET_window/when_request_is_successful/with_date_params.yml +96 -0
  26. data/spec/cassettes/PlataformaSocial_Ranking/GET_window/when_request_is_successful/with_down_param.yml +48 -0
  27. data/spec/cassettes/PlataformaSocial_Ranking/GET_window/when_request_is_successful/with_friends_param.yml +192 -0
  28. data/spec/cassettes/PlataformaSocial_Ranking/GET_window/when_request_is_successful/with_limit_param.yml +48 -0
  29. data/spec/cassettes/PlataformaSocial_Ranking/GET_window/when_request_is_successful/with_up_and_down_param.yml +192 -0
  30. data/spec/cassettes/PlataformaSocial_Ranking/GET_window/when_request_is_successful/with_up_param.yml +192 -0
  31. data/spec/cassettes/PlataformaSocial_Ranking/GET_window/when_request_is_successful/without_up_and_down_param.yml +192 -0
  32. data/spec/cassettes/PlataformaSocial_Ranking/create_a_new_ranking/when_request_is_successful.yml +51 -0
  33. data/spec/cassettes/PlataformaSocial_Ranking/create_a_new_ranking/when_request_is_successful/for_custom_date_ranking.yml +51 -0
  34. data/spec/cassettes/PlataformaSocial_Ranking/create_a_new_ranking/when_request_is_successful/for_general_ranking.yml +51 -0
  35. data/spec/cassettes/PlataformaSocial_Ranking/create_a_new_ranking/when_request_is_successful/using_max_param_ranking.yml +51 -0
  36. data/spec/cassettes/PlataformaSocial_Ranking/create_a_new_ranking/when_request_is_successful/using_min_and_max_params_ranking.yml +51 -0
  37. data/spec/cassettes/PlataformaSocial_Ranking/create_a_new_ranking/when_request_is_successful/using_min_param_ranking.yml +51 -0
  38. data/spec/cassettes/PlataformaSocial_Ranking_Custom/GET_custom_ranking/when_request_is_successful/using_another_dates.yml +288 -0
  39. data/spec/cassettes/PlataformaSocial_Ranking_Custom/GET_custom_ranking/when_request_is_successful/using_corrects_params.yml +288 -0
  40. data/spec/cassettes/PlataformaSocial_Ranking_Custom/GET_custom_ranking/when_request_is_successful/using_params_user_reference_and_friends.yml +288 -0
  41. data/spec/cassettes/PlataformaSocial_Ranking_General/GET_full_ranking/return_all_ranking.yml +48 -0
  42. data/spec/dummy/.DS_Store +0 -0
  43. data/spec/dummy/.gitignore +16 -0
  44. data/spec/dummy/Gemfile +45 -0
  45. data/spec/dummy/README.rdoc +28 -0
  46. data/spec/dummy/Rakefile +6 -0
  47. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  48. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  49. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  50. data/spec/dummy/{log/development.log → app/controllers/concerns/.keep} +0 -0
  51. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  52. data/spec/dummy/app/mailers/.keep +0 -0
  53. data/spec/dummy/app/models/.keep +0 -0
  54. data/spec/dummy/app/models/concerns/.keep +0 -0
  55. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  56. data/spec/dummy/bin/bundle +3 -0
  57. data/spec/dummy/bin/rails +4 -0
  58. data/spec/dummy/bin/rake +4 -0
  59. data/spec/dummy/config.ru +4 -0
  60. data/spec/dummy/config/application.rb +14 -0
  61. data/spec/dummy/config/boot.rb +4 -0
  62. data/spec/dummy/config/database.yml +25 -0
  63. data/spec/dummy/config/environment.rb +5 -0
  64. data/spec/dummy/config/environments/development.rb +37 -0
  65. data/spec/dummy/config/environments/production.rb +80 -0
  66. data/spec/dummy/config/environments/test.rb +44 -0
  67. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  69. data/spec/dummy/config/initializers/inflections.rb +16 -0
  70. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  71. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  72. data/spec/dummy/config/initializers/session_store.rb +3 -0
  73. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  74. data/spec/dummy/config/locales/en.yml +23 -0
  75. data/spec/dummy/config/routes.rb +49 -0
  76. data/spec/dummy/db/seeds.rb +7 -0
  77. data/spec/dummy/keys/public.pem +5 -0
  78. data/spec/dummy/lib/assets/.keep +0 -0
  79. data/spec/dummy/lib/tasks/.keep +0 -0
  80. data/spec/dummy/log/.keep +0 -0
  81. data/spec/dummy/plataforma_social/keys/public.pem +5 -0
  82. data/spec/dummy/public/404.html +58 -0
  83. data/spec/dummy/public/422.html +58 -0
  84. data/spec/dummy/public/500.html +57 -0
  85. data/spec/dummy/public/favicon.ico +0 -0
  86. data/spec/dummy/public/robots.txt +5 -0
  87. data/spec/dummy/test/controllers/.keep +0 -0
  88. data/spec/dummy/test/fixtures/.keep +0 -0
  89. data/spec/dummy/test/helpers/.keep +0 -0
  90. data/spec/dummy/test/integration/.keep +0 -0
  91. data/spec/dummy/test/mailers/.keep +0 -0
  92. data/spec/dummy/test/models/.keep +0 -0
  93. data/spec/dummy/test/test_helper.rb +15 -0
  94. data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
  95. data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
  96. data/spec/plataforma_social/.DS_Store +0 -0
  97. data/spec/plataforma_social/badge_spec.rb +83 -0
  98. data/spec/plataforma_social/ranking/custom_spec.rb +53 -0
  99. data/spec/plataforma_social/ranking/general_spec.rb +23 -0
  100. data/spec/plataforma_social/ranking_spec.rb +147 -0
  101. data/spec/spec_helper.rb +18 -0
  102. metadata +279 -6
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, '\1en'
8
+ # inflect.singular /^(ox)en/i, '\1'
9
+ # inflect.irregular 'person', 'people'
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,12 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure your secret_key_base is kept private
11
+ # if you're sharing your code publicly.
12
+ Dummy::Application.config.secret_key_base = 'e6d15bdc648ab739c822b4fb140a4dbd724bfb6d887695e13202d7a136d812211749584d9b357b2f8d14484fd611dd78d4a774e61f952d82e5729f0833725f9e'
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
+ end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -0,0 +1,23 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ hello: "Hello world"
@@ -0,0 +1,49 @@
1
+ Dummy::Application.routes.draw do
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+ # See how all your routes lay out with "rake routes".
4
+
5
+ # You can have the root of your site routed with "root"
6
+ # root 'welcome#index'
7
+
8
+ # Example of regular route:
9
+ # get 'products/:id' => 'catalog#view'
10
+
11
+ # Example of named route that can be invoked with purchase_url(id: product.id)
12
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13
+
14
+ # Example resource route (maps HTTP verbs to controller actions automatically):
15
+ # resources :products
16
+
17
+ # Example resource route with options:
18
+ # resources :products do
19
+ # member do
20
+ # get 'short'
21
+ # post 'toggle'
22
+ # end
23
+ #
24
+ # collection do
25
+ # get 'sold'
26
+ # end
27
+ # end
28
+
29
+ # Example resource route with sub-resources:
30
+ # resources :products do
31
+ # resources :comments, :sales
32
+ # resource :seller
33
+ # end
34
+
35
+ # Example resource route with more complex sub-resources:
36
+ # resources :products do
37
+ # resources :comments
38
+ # resources :sales do
39
+ # get 'recent', on: :collection
40
+ # end
41
+ # end
42
+
43
+ # Example resource route within a namespace:
44
+ # namespace :admin do
45
+ # # Directs /admin/products/* to Admin::ProductsController
46
+ # # (app/controllers/admin/products_controller.rb)
47
+ # resources :products
48
+ # end
49
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7
+ # Mayor.create(name: 'Emanuel', city: cities.first)
@@ -0,0 +1,5 @@
1
+ -----BEGIN RSA PUBLIC KEY-----
2
+ MIGJAoGBALt2P6Ra1KTzVqxEaS29WvQtaiBOecuL8P/MOd1Ik8EBMteRJSZX86nE
3
+ ymGrUXySAjyvtRpj6nR0yOIyZyQo3ZWCcdmIsPQ/xfaDogxS31gPPQnQBdprrnSe
4
+ g99DGQ3PP3ut2eqRyKqWFtt6Cc3x7UfLXuwvdjgEHE+v6+XboDI7AgMBAAE=
5
+ -----END RSA PUBLIC KEY-----
File without changes
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ -----BEGIN RSA PUBLIC KEY-----
2
+ MIGJAoGBALt2P6Ra1KTzVqxEaS29WvQtaiBOecuL8P/MOd1Ik8EBMteRJSZX86nE
3
+ ymGrUXySAjyvtRpj6nR0yOIyZyQo3ZWCcdmIsPQ/xfaDogxS31gPPQnQBdprrnSe
4
+ g99DGQ3PP3ut2eqRyKqWFtt6Cc3x7UfLXuwvdjgEHE+v6+XboDI7AgMBAAE=
5
+ -----END RSA PUBLIC KEY-----
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ ENV["RAILS_ENV"] ||= "test"
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ ActiveRecord::Migration.check_pending!
7
+
8
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
9
+ #
10
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
11
+ # -- they do not yet inherit this setting
12
+ fixtures :all
13
+
14
+ # Add more helper methods to be used by all tests here...
15
+ end
File without changes
File without changes
Binary file
@@ -0,0 +1,83 @@
1
+ #encoding: UTF-8
2
+ require "spec_helper"
3
+
4
+ describe PlataformaSocial::Badge do
5
+ describe "Platform Route" do
6
+ it "return correct url" do
7
+ PlataformaSocial::Badge.socialp_route.should == "http://badge.dev.plataformasocial.com.br"
8
+ end
9
+ end
10
+
11
+ describe "CREATE a new badge" do
12
+ before :each do
13
+ @params = { :badge_reference => 1, :badge_obj => "{\"reference\":\"1432423423\",\"updated_at\":\"2012-07-13T19:53:20Z\",\"id\":1,\"share_text\":\"Parab\\u00e9ns, voc\\u00ea ganhou a Badge de Coloridos da Dito.\",\"events_count\":10,\"picture_url\":\"http://www.jorge.com.br/sergio\",\"description\":\"Essa badge \\u00e9 dada para todos os Coloridos da Dito.\",\"name\":\"Dito Colorida\",\"created_at\":\"2012-07-13T19:53:20Z\",\"app_id\":23}" }
14
+ end
15
+
16
+ it "when request is successful", :vcr do
17
+ badge = PlataformaSocial::Badge.new
18
+ badge.create(@params).match(/badge_reference=1/).should be_true
19
+ end
20
+
21
+ context "when request is failed" do
22
+ [:badge_reference, :badge_obj].each do |param|
23
+ it "dont using params: #{param}" do
24
+ @params.delete param
25
+ badge = PlataformaSocial::Badge.new
26
+ badge.create(@params).should == "Faltando o parâmetro: #{param}"
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "GIVE points to user" do
33
+ before :each, :vcr do
34
+ params = { :badge_reference => 1, :badge_obj => "{\"reference\":\"1\",\"updated_at\":\"2012-07-13T19:53:20Z\",\"id\":1,\"share_text\":\"Parab\\u00e9ns, voc\\u00ea ganhou a Badge de Coloridos da Dito.\",\"events_count\":10,\"picture_url\":\"http://www.jorge.com.br/sergio\",\"description\":\"Essa badge \\u00e9 dada para todos os Coloridos da Dito.\",\"name\":\"Dito Colorida\",\"created_at\":\"2012-07-13T19:53:20Z\",\"app_id\":23}" }
35
+ @badge = PlataformaSocial::Badge.new
36
+ @badge.create(params)
37
+ end
38
+
39
+ it "when request is successful and badges is array", :vcr do
40
+ @badge.give({:user_reference => 1, :badges => [1]}).should == []
41
+ end
42
+
43
+ it "when request is successful and badges is hash", :vcr do
44
+ @badge.give({:user_reference => 1, :badges => [{ 1 => 12 }]}).should == [{"reference"=>"1", "updated_at"=>"2012-07-13T19:53:20Z", "id"=>1, "share_text"=>"Parabéns, você ganhou a Badge de Coloridos da Dito.", "events_count"=>10, "picture_url"=>"http://www.jorge.com.br/sergio", "description"=>"Essa badge é dada para todos os Coloridos da Dito.", "name"=>"Dito Colorida", "created_at"=>"2012-07-13T19:53:20Z", "app_id"=>23, "url"=>"http://appprova.sandbox.plataformasocial.com.br/badge?badge_reference=1&app_id=23"}]
45
+ end
46
+
47
+ context "when request is failed" do
48
+ [:user_reference, :badges].each do |param|
49
+ params = { :user_reference => 1, :badges => [1] }
50
+ it "dont using params: #{param}" do
51
+ params.delete param
52
+ @badge.give(params).should == "Faltando o parâmetro: #{param}"
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "return INDEX to user" do
59
+ before :each do
60
+ params = { :badge_reference => 5, :badge_obj => "{\"reference\":\"5\",\"updated_at\":\"2012-07-13T19:53:20Z\",\"id\":1,\"share_text\":\"Parab\\u00e9ns, voc\\u00ea ganhou a Badge de Coloridos da Dito.\",\"events_count\":10,\"picture_url\":\"http://www.jorge.com.br/sergio\",\"description\":\"Essa badge \\u00e9 dada para todos os Coloridos da Dito.\",\"name\":\"Dito Colorida\",\"created_at\":\"2012-07-13T19:53:20Z\",\"app_id\":23}" }
61
+ params1 = { :badge_reference => 6, :badge_obj => "{\"reference\":\"6\",\"updated_at\":\"2012-07-13T19:53:20Z\",\"id\":1,\"share_text\":\"Parab\\u00e9ns, voc\\u00ea ganhou a Badge de Coloridos da Dito.\",\"events_count\":10,\"picture_url\":\"http://www.jorge.com.br/sergio\",\"description\":\"Essa badge \\u00e9 dada para todos os Coloridos da Dito.\",\"name\":\"Dito Colorida\",\"created_at\":\"2012-07-13T19:53:20Z\",\"app_id\":23}" }
62
+ @badge = PlataformaSocial::Badge.new
63
+ @badge.create(params)
64
+ @badge.create(params1)
65
+ end
66
+
67
+ it "when request is successful, but user hasnt earned any badge", :vcr do
68
+ @badge.give({:user_reference => 4, :badges => [5]})
69
+ @badge.index({ :user_reference => 4 }).should include({"reference"=>"5", "updated_at"=>"2012-07-13T19:53:20Z", "id"=>1, "share_text"=>"Parabéns, você ganhou a Badge de Coloridos da Dito.", "events_count"=>10, "picture_url"=>"http://www.jorge.com.br/sergio", "description"=>"Essa badge é dada para todos os Coloridos da Dito.", "name"=>"Dito Colorida", "created_at"=>"2012-07-13T19:53:20Z", "app_id"=>23, "earned"=>false, "url"=>"http://appprova.sandbox.plataformasocial.com.br/badge?badge_reference=5&app_id=23"})
70
+ end
71
+
72
+ it "when request is successful and user has already earned some badge", :vcr do
73
+ @badge.give({:user_reference => 5, :badges => [{ 6 => 12 }]})
74
+ @badge.index({ :user_reference => 5 }).should include({"reference"=>"6", "updated_at"=>"2012-07-13T19:53:20Z", "id"=>1, "share_text"=>"Parabéns, você ganhou a Badge de Coloridos da Dito.", "events_count"=>10, "picture_url"=>"http://www.jorge.com.br/sergio", "description"=>"Essa badge é dada para todos os Coloridos da Dito.", "name"=>"Dito Colorida", "created_at"=>"2012-07-13T19:53:20Z", "app_id"=>23, "earned"=>true, "url"=>"http://appprova.sandbox.plataformasocial.com.br/badge?badge_reference=6&app_id=23"})
75
+ end
76
+
77
+ context "when request is failed" do
78
+ it "dont using params: user_reference" do
79
+ @badge.index.should == "Faltando o parâmetro: user_reference"
80
+ end
81
+ end
82
+ end
83
+ end