gamification 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/gamification/application_controller.rb +1 -1
  3. data/app/controllers/gamification/rewards_controller.rb +46 -0
  4. data/app/helpers/gamification/application_helper.rb +24 -0
  5. data/app/helpers/gamification/rewards_helper.rb +20 -0
  6. data/app/models/gamification/goal.rb +5 -0
  7. data/app/models/gamification/medal.rb +5 -0
  8. data/app/models/gamification/reward.rb +5 -0
  9. data/app/uploaders/gamification/image_uploader.rb +47 -0
  10. data/app/views/gamification/rewards/_presentation.html.erb +7 -0
  11. data/app/views/gamification/rewards/_reward.html.erb +9 -0
  12. data/app/views/gamification/scorings/create.html.erb +2 -0
  13. data/config/initializers/routing.rb +15 -0
  14. data/config/locales/en.yml +3 -0
  15. data/config/locales/nb.yml +35 -0
  16. data/config/routes.rb +1 -0
  17. data/db/migrate/20140310081749_rename_everything.rb +10 -0
  18. data/db/migrate/20140313134259_create_gamification_medals.rb +11 -0
  19. data/db/migrate/20140314132611_add_description_to_gamification_medals.rb +5 -0
  20. data/db/migrate/20140315142524_rename_gamification_tasks_to_goals.rb +7 -0
  21. data/db/migrate/20140318220723_add_seen_at_to_gamification_rewards.rb +9 -0
  22. data/lib/gamification.rb +1 -0
  23. data/lib/gamification/activerecord.rb +13 -0
  24. data/lib/gamification/concerns.rb +2 -0
  25. data/lib/gamification/concerns/models.rb +3 -2
  26. data/lib/gamification/concerns/models/goal.rb +44 -0
  27. data/lib/gamification/concerns/models/medal.rb +13 -0
  28. data/lib/gamification/concerns/models/reward.rb +33 -0
  29. data/lib/gamification/concerns/rewardable.rb +12 -0
  30. data/lib/gamification/concerns/rewarding.rb +7 -0
  31. data/lib/gamification/engine.rb +10 -0
  32. data/lib/gamification/version.rb +1 -1
  33. data/spec/controllers/gamification/rewards_controller_spec.rb +57 -0
  34. data/spec/dummy/app/assets/javascripts/articles.js +2 -0
  35. data/spec/dummy/app/assets/stylesheets/articles.css +4 -0
  36. data/spec/dummy/app/controllers/articles_controller.rb +5 -0
  37. data/spec/dummy/app/helpers/articles_helper.rb +2 -0
  38. data/spec/dummy/app/models/article.rb +2 -2
  39. data/spec/dummy/app/models/user.rb +2 -2
  40. data/spec/dummy/app/views/articles/show.html.erb +1 -0
  41. data/spec/dummy/config/routes.rb +1 -0
  42. data/spec/dummy/db/development.sqlite3 +0 -0
  43. data/spec/dummy/db/schema.rb +25 -12
  44. data/spec/dummy/db/test.sqlite3 +0 -0
  45. data/spec/dummy/log/development.log +3893 -1707
  46. data/spec/dummy/log/test.log +22080 -2888
  47. data/spec/dummy/spec/controllers/articles_controller_spec.rb +15 -0
  48. data/spec/dummy/spec/helpers/articles_helper_spec.rb +14 -0
  49. data/spec/dummy/spec/models/article_spec.rb +0 -1
  50. data/spec/dummy/spec/models/user_spec.rb +0 -1
  51. data/spec/dummy/spec/views/articles/show.html.erb_spec.rb +4 -0
  52. data/spec/factories/gamification_goals.rb +14 -0
  53. data/spec/factories/gamification_medals.rb +10 -0
  54. data/spec/factories/gamification_rewards.rb +8 -0
  55. data/spec/helpers/gamification/application_helper_spec.rb +14 -0
  56. data/spec/helpers/gamification/rewards_helper_spec.rb +18 -0
  57. data/spec/lib/gamification/concerns/rewardable_spec.rb +17 -0
  58. data/spec/models/gamification/goal_spec.rb +65 -0
  59. data/spec/models/gamification/medal_spec.rb +6 -0
  60. data/spec/models/gamification/reward_spec.rb +102 -0
  61. data/spec/spec_helper.rb +2 -0
  62. data/spec/views/gamification/rewards/_presentation.html.erb_spec.rb +23 -0
  63. metadata +173 -28
  64. data/MIT-LICENSE +0 -20
  65. data/app/models/gamification/scoring.rb +0 -5
  66. data/app/models/gamification/task.rb +0 -5
  67. data/app/views/layouts/gamification/application.html.erb +0 -14
  68. data/lib/gamification/concerns/models/scoring.rb +0 -8
  69. data/lib/gamification/concerns/models/task.rb +0 -50
  70. data/spec/factories/gamification_scorings.rb +0 -8
  71. data/spec/factories/gamification_tasks.rb +0 -8
  72. data/spec/models/gamification/scoring_spec.rb +0 -7
  73. data/spec/models/gamification/task_spec.rb +0 -77
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2014 YOURNAME
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,5 +0,0 @@
1
- module Gamification
2
- class Scoring < ActiveRecord::Base
3
- include Concerns::Models::Scoring
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- module Gamification
2
- class Task < ActiveRecord::Base
3
- include Concerns::Models::Task
4
- end
5
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Gamification</title>
5
- <%= stylesheet_link_tag "gamification/application", media: "all" %>
6
- <%= javascript_include_tag "gamification/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,8 +0,0 @@
1
- module Gamification::Concerns::Models::Scoring
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- belongs_to :task
6
- belongs_to :subjectable, polymorphic: true
7
- end
8
- end
@@ -1,50 +0,0 @@
1
- module Gamification::Concerns::Models::Task
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- belongs_to :taskable, polymorphic: true
6
- has_many :scorings
7
-
8
- # TODO: These should be SQL. But that's hard.
9
- scope :completed_by, ->(subject) { all.select { |task| task.completed_by? subject }}
10
- scope :incomplete_by, ->(subject) { all.reject { |task| task.completed_by? subject }}
11
-
12
- # Determine whether the given subject has completed the task.
13
- #
14
- # subject - An ActiveRecord model that can receive scorings.
15
- def completed_by? subject
16
- !!scoring_for(subject)
17
- end
18
-
19
- # Complete the task for the given subject.
20
- #
21
- # subject - An ActiveRecord model that can receive scorings.
22
- def complete_for subject
23
- if completed_by? subject
24
- raise Completed, "Task is already completed for #{subject}"
25
- else
26
- ::Gamification::Scoring.create! task: self, subjectable: subject
27
- end
28
- end
29
-
30
- private
31
-
32
- # Find the Scoring for the given subject.
33
- #
34
- # subject - An ActiveRecord model that can receive scorings.
35
- def scoring_for subject
36
- scorings.find_by subjectable: subject
37
- end
38
-
39
- class Completed < StandardError; end
40
- end
41
-
42
- module ClassMethods
43
- # Complete all tasks for the given subject.
44
- #
45
- # subject - An ActiveRecord model that can receive scorings.
46
- def complete_for subject
47
- all.map { |task| task.complete_for subject unless task.completed_by? subject }.compact
48
- end
49
- end
50
- end
@@ -1,8 +0,0 @@
1
- # Read about factories at https://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :gamification_scoring, :class => 'Gamification::Scoring' do
5
- task nil
6
- subjectable nil
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # Read about factories at https://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :gamification_task, :class => 'Gamification::Task' do
5
- taskable nil
6
- points 1
7
- end
8
- end
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Gamification
4
- describe Scoring do
5
- pending "add some examples to (or delete) #{__FILE__}"
6
- end
7
- end
@@ -1,77 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Gamification
4
- describe Task do
5
- let(:subject) { create :user }
6
- let(:task) { create :gamification_task }
7
-
8
- describe '#completed_by?' do
9
- context 'for a task that is completed by the given subject' do
10
- before do
11
- create :gamification_scoring, task: task, subjectable: subject
12
- end
13
-
14
- it 'returns true' do
15
- expect(task).to be_completed_by subject
16
- end
17
- end
18
-
19
- context 'for a task that is not completed by the given subject' do
20
- it 'returns false' do
21
- expect(task).not_to be_completed_by subject
22
- end
23
- end
24
- end
25
-
26
- describe '#complete_for' do
27
- context 'for a task that is not yet completed' do
28
- it 'creates a scoring for the given subject' do
29
- expect(task.complete_for subject).to be_instance_of Scoring
30
- end
31
- end
32
-
33
- context 'for a task that is already completed' do
34
- before do
35
- create :gamification_scoring, task: task, subjectable: subject
36
- end
37
-
38
- it 'raises an error' do
39
- expect { task.complete_for subject}.to raise_error Task::Completed
40
- end
41
- end
42
- end
43
-
44
- describe '.complete_for' do
45
- let!(:tasks) { create_list :gamification_task, 3 }
46
-
47
- before do
48
- create :gamification_scoring, task: tasks.first, subjectable: subject
49
- end
50
-
51
- it 'creates scorings for tasks that were completed' do
52
- expect(Task.complete_for(subject).count).to eq 2
53
- end
54
- end
55
-
56
- describe '.completed_by' do
57
- let!(:complete_task) { create :gamification_task }
58
- let!(:incomplete_task) { create :gamification_task }
59
-
60
- before do
61
- complete_task.complete_for subject
62
- end
63
-
64
- it 'returns completed tasks by a given subject' do
65
- expect(Task.completed_by(subject).count).to eq 1
66
- end
67
- end
68
-
69
- describe '.incomplete_by' do
70
- let!(:incomplete_tasks) { create_list :gamification_task, 2 }
71
-
72
- it 'returns incomplete tasks by a given subject' do
73
- expect(Task.incomplete_by(subject).count).to eq 2
74
- end
75
- end
76
- end
77
- end