merit 3.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +3 -20
  3. data/NEWS.md +32 -0
  4. data/README.md +29 -10
  5. data/Rakefile +13 -1
  6. data/app/models/merit/badge.rb +2 -19
  7. data/lib/merit.rb +18 -50
  8. data/lib/merit/{rules_badge_methods.rb → badge_rules_methods.rb} +0 -0
  9. data/lib/merit/base_target_finder.rb +1 -6
  10. data/lib/merit/{model_additions.rb → class_methods.rb} +2 -19
  11. data/lib/merit/controller_extensions.rb +4 -22
  12. data/lib/{generators → merit/generators}/active_record/install_generator.rb +8 -8
  13. data/lib/{generators → merit/generators}/active_record/merit_generator.rb +4 -4
  14. data/lib/{generators → merit/generators}/active_record/remove_generator.rb +5 -5
  15. data/lib/{generators/active_record/templates/add_merit_fields_to_model.rb → merit/generators/active_record/templates/add_merit_fields_to_model.erb} +0 -0
  16. data/lib/{generators/active_record/templates/create_badges_sashes.rb → merit/generators/active_record/templates/create_badges_sashes.erb} +0 -0
  17. data/lib/{generators/active_record/templates/create_merit_actions.rb → merit/generators/active_record/templates/create_merit_actions.erb} +2 -0
  18. data/lib/{generators/active_record/templates/create_merit_activity_logs.rb → merit/generators/active_record/templates/create_merit_activity_logs.erb} +0 -0
  19. data/lib/{generators/active_record/templates/create_sashes.rb → merit/generators/active_record/templates/create_sashes.erb} +0 -0
  20. data/lib/{generators/active_record/templates/create_scores_and_points.rb → merit/generators/active_record/templates/create_scores_and_points.erb} +1 -1
  21. data/lib/{generators/active_record/templates/remove_merit_fields_from_model.rb → merit/generators/active_record/templates/remove_merit_fields_from_model.erb} +0 -0
  22. data/lib/{generators/active_record/templates/remove_merit_tables.rb → merit/generators/active_record/templates/remove_merit_tables.erb} +0 -0
  23. data/lib/merit/generators/install_generator.rb +21 -0
  24. data/lib/{generators/merit → merit/generators}/merit_generator.rb +7 -2
  25. data/lib/{generators/merit → merit/generators}/remove_generator.rb +7 -2
  26. data/lib/{generators/merit/templates/merit.rb → merit/generators/templates/merit.erb} +13 -14
  27. data/lib/{generators/merit/templates/merit_badge_rules.rb → merit/generators/templates/merit_badge_rules.erb} +0 -0
  28. data/lib/{generators/merit/templates/merit_point_rules.rb → merit/generators/templates/merit_point_rules.erb} +0 -0
  29. data/lib/{generators/merit/templates/merit_rank_rules.rb → merit/generators/templates/merit_rank_rules.erb} +0 -0
  30. data/lib/merit/judge.rb +6 -5
  31. data/{app/models/merit/action.rb → lib/merit/models/action_concern.rb} +12 -10
  32. data/lib/merit/models/active_record/action.rb +11 -0
  33. data/lib/merit/models/active_record/{merit/activity_log.rb → activity_log.rb} +4 -6
  34. data/lib/merit/models/active_record/{merit/badges_sash.rb → badges_sash.rb} +4 -4
  35. data/lib/merit/models/active_record/{merit/sash.rb → sash.rb} +5 -2
  36. data/lib/merit/models/active_record/{merit/score.rb → score.rb} +4 -1
  37. data/lib/merit/models/badges_sash_concern.rb +13 -0
  38. data/lib/merit/models/base/badges_sash.rb +1 -1
  39. data/lib/merit/models/base/sash.rb +1 -1
  40. data/lib/merit/models/sash_concern.rb +53 -0
  41. data/lib/merit/{rules_points_methods.rb → point_rules_methods.rb} +0 -0
  42. data/lib/merit/{rules_rank_methods.rb → rank_rules_methods.rb} +3 -18
  43. data/merit.gemspec +7 -5
  44. data/test/dummy/app/controllers/comments_controller.rb +1 -1
  45. data/test/dummy/app/controllers/registrations_controller.rb +1 -1
  46. data/test/dummy/app/models/address.rb +1 -12
  47. data/test/dummy/app/models/comment.rb +3 -25
  48. data/test/dummy/app/models/user.rb +1 -18
  49. data/test/dummy/config/application.rb +8 -10
  50. data/test/dummy/config/application_api_only.rb +28 -0
  51. data/test/dummy/config/environment_api_only.rb +7 -0
  52. data/test/dummy/config/initializers/new_framework_defaults.rb +3 -0
  53. data/test/dummy/db/migrate/20130329224406_create_merit_actions.rb +2 -0
  54. data/test/dummy/db/schema.rb +56 -59
  55. data/test/integration/navigation_test.rb +3 -3
  56. data/test/test_helper.rb +11 -12
  57. data/test/unit/base_target_finder_test.rb +7 -26
  58. data/test/unit/merit_unit_test.rb +13 -17
  59. data/test/unit/rule_unit_test.rb +15 -8
  60. data/test/unit/rules_matcher_test.rb +9 -6
  61. data/test/unit/sash_finder_test.rb +5 -5
  62. data/test/unit/sash_test.rb +16 -0
  63. data/test/unit/score_test.rb +1 -1
  64. data/test/unit/target_finder_test.rb +13 -13
  65. metadata +63 -73
  66. data/UPGRADING.md +0 -256
  67. data/lib/generators/active_record/templates/add_target_data_to_merit_actions.rb +0 -5
  68. data/lib/generators/active_record/upgrade_generator.rb +0 -40
  69. data/lib/generators/merit/install_generator.rb +0 -16
  70. data/lib/generators/merit/upgrade_generator.rb +0 -7
  71. data/lib/merit/models/active_record/merit/action.rb +0 -12
  72. data/lib/merit/models/mongoid/merit/action.rb +0 -18
  73. data/lib/merit/models/mongoid/merit/activity_log.rb +0 -11
  74. data/lib/merit/models/mongoid/merit/badges_sash.rb +0 -22
  75. data/lib/merit/models/mongoid/merit/sash.rb +0 -30
  76. data/lib/merit/models/mongoid/merit/score.rb +0 -45
  77. data/test/dummy/db/migrate/20140906225844_create_players.rb +0 -8
  78. data/test/dummy/public/javascripts/application.js +0 -2
  79. data/test/dummy/public/javascripts/controls.js +0 -965
  80. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  81. data/test/dummy/public/javascripts/effects.js +0 -1123
  82. data/test/dummy/public/javascripts/prototype.js +0 -6001
  83. data/test/dummy/public/javascripts/rails.js +0 -191
  84. data/test/orm/active_record.rb +0 -2
  85. data/test/orm/mongoid.rb +0 -6
  86. data/test/orm_models/active_record.rb +0 -11
  87. data/test/orm_models/mongoid.rb +0 -15
@@ -1,191 +0,0 @@
1
- (function() {
2
- // Technique from Juriy Zaytsev
3
- // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
- function isEventSupported(eventName) {
5
- var el = document.createElement('div');
6
- eventName = 'on' + eventName;
7
- var isSupported = (eventName in el);
8
- if (!isSupported) {
9
- el.setAttribute(eventName, 'return;');
10
- isSupported = typeof el[eventName] == 'function';
11
- }
12
- el = null;
13
- return isSupported;
14
- }
15
-
16
- function isForm(element) {
17
- return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
- }
19
-
20
- function isInput(element) {
21
- if (Object.isElement(element)) {
22
- var name = element.nodeName.toUpperCase()
23
- return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
- }
25
- else return false
26
- }
27
-
28
- var submitBubbles = isEventSupported('submit'),
29
- changeBubbles = isEventSupported('change')
30
-
31
- if (!submitBubbles || !changeBubbles) {
32
- // augment the Event.Handler class to observe custom events when needed
33
- Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
- function(init, element, eventName, selector, callback) {
35
- init(element, eventName, selector, callback)
36
- // is the handler being attached to an element that doesn't support this event?
37
- if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
- (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
- // "submit" => "emulated:submit"
40
- this.eventName = 'emulated:' + this.eventName
41
- }
42
- }
43
- )
44
- }
45
-
46
- if (!submitBubbles) {
47
- // discover forms on the page by observing focus events which always bubble
48
- document.on('focusin', 'form', function(focusEvent, form) {
49
- // special handler for the real "submit" event (one-time operation)
50
- if (!form.retrieve('emulated:submit')) {
51
- form.on('submit', function(submitEvent) {
52
- var emulated = form.fire('emulated:submit', submitEvent, true)
53
- // if custom event received preventDefault, cancel the real one too
54
- if (emulated.returnValue === false) submitEvent.preventDefault()
55
- })
56
- form.store('emulated:submit', true)
57
- }
58
- })
59
- }
60
-
61
- if (!changeBubbles) {
62
- // discover form inputs on the page
63
- document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
- // special handler for real "change" events
65
- if (!input.retrieve('emulated:change')) {
66
- input.on('change', function(changeEvent) {
67
- input.fire('emulated:change', changeEvent, true)
68
- })
69
- input.store('emulated:change', true)
70
- }
71
- })
72
- }
73
-
74
- function handleRemote(element) {
75
- var method, url, params;
76
-
77
- var event = element.fire("ajax:before");
78
- if (event.stopped) return false;
79
-
80
- if (element.tagName.toLowerCase() === 'form') {
81
- method = element.readAttribute('method') || 'post';
82
- url = element.readAttribute('action');
83
- params = element.serialize();
84
- } else {
85
- method = element.readAttribute('data-method') || 'get';
86
- url = element.readAttribute('href');
87
- params = {};
88
- }
89
-
90
- new Ajax.Request(url, {
91
- method: method,
92
- parameters: params,
93
- evalScripts: true,
94
-
95
- onComplete: function(request) { element.fire("ajax:complete", request); },
96
- onSuccess: function(request) { element.fire("ajax:success", request); },
97
- onFailure: function(request) { element.fire("ajax:failure", request); }
98
- });
99
-
100
- element.fire("ajax:after");
101
- }
102
-
103
- function handleMethod(element) {
104
- var method = element.readAttribute('data-method'),
105
- url = element.readAttribute('href'),
106
- csrf_param = $$('meta[name=csrf-param]')[0],
107
- csrf_token = $$('meta[name=csrf-token]')[0];
108
-
109
- var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
- element.parentNode.insert(form);
111
-
112
- if (method !== 'post') {
113
- var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
- form.insert(field);
115
- }
116
-
117
- if (csrf_param) {
118
- var param = csrf_param.readAttribute('content'),
119
- token = csrf_token.readAttribute('content'),
120
- field = new Element('input', { type: 'hidden', name: param, value: token });
121
- form.insert(field);
122
- }
123
-
124
- form.submit();
125
- }
126
-
127
-
128
- document.on("click", "*[data-confirm]", function(event, element) {
129
- var message = element.readAttribute('data-confirm');
130
- if (!confirm(message)) event.stop();
131
- });
132
-
133
- document.on("click", "a[data-remote]", function(event, element) {
134
- if (event.stopped) return;
135
- handleRemote(element);
136
- event.stop();
137
- });
138
-
139
- document.on("click", "a[data-method]", function(event, element) {
140
- if (event.stopped) return;
141
- handleMethod(element);
142
- event.stop();
143
- });
144
-
145
- document.on("submit", function(event) {
146
- var element = event.findElement(),
147
- message = element.readAttribute('data-confirm');
148
- if (message && !confirm(message)) {
149
- event.stop();
150
- return false;
151
- }
152
-
153
- var inputs = element.select("input[type=submit][data-disable-with]");
154
- inputs.each(function(input) {
155
- input.disabled = true;
156
- input.writeAttribute('data-original-value', input.value);
157
- input.value = input.readAttribute('data-disable-with');
158
- });
159
-
160
- var element = event.findElement("form[data-remote]");
161
- if (element) {
162
- handleRemote(element);
163
- event.stop();
164
- }
165
- });
166
-
167
- document.on("ajax:after", "form", function(event, element) {
168
- var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
- inputs.each(function(input) {
170
- input.value = input.readAttribute('data-original-value');
171
- input.removeAttribute('data-original-value');
172
- input.disabled = false;
173
- });
174
- });
175
-
176
- Ajax.Responders.register({
177
- onCreate: function(request) {
178
- var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
179
-
180
- if (csrf_meta_tag) {
181
- var header = 'X-CSRF-Token',
182
- token = csrf_meta_tag.readAttribute('content');
183
-
184
- if (!request.options.requestHeaders) {
185
- request.options.requestHeaders = {};
186
- }
187
- request.options.requestHeaders[header] = token;
188
- }
189
- }
190
- });
191
- })();
@@ -1,2 +0,0 @@
1
- # Place orm-dependent test preparation here
2
- ActiveRecord::Migrator.migrate File.expand_path("../../dummy/db/migrate/", __FILE__)
data/test/orm/mongoid.rb DELETED
@@ -1,6 +0,0 @@
1
- # Place orm-dependent test preparation here
2
- class ActiveSupport::TestCase
3
- setup do
4
- Mongoid.purge!
5
- end
6
- end
@@ -1,11 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Fruit < ActiveRecord::Base
4
- end
5
-
6
- class Soldier < ActiveRecord::Base
7
- has_merit
8
- end
9
- class Player < ActiveRecord::Base
10
- has_merit
11
- end
@@ -1,15 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Fruit
4
- include Mongoid::Document
5
- end
6
-
7
- class Soldier
8
- include Mongoid::Document
9
- has_merit
10
- end
11
-
12
- class Player
13
- include Mongoid::Document
14
- has_merit
15
- end