rapidfire 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf282cfdca2422d38ece7af4cb87094810907d87
4
- data.tar.gz: e9270a2229db1cb26aa3e502446756e0975be8e2
3
+ metadata.gz: 98a860721e84efa9238468ab8d4de455acfc1004
4
+ data.tar.gz: d4a2bbade0997c99ac53d8344dc07a7f56e67b80
5
5
  SHA512:
6
- metadata.gz: e06b07da985f333727aa9673f3551b1e06aa0cbfc34ab0c883d574462c22bdf6fbe13a5603c06ef685331039a410bfb7e9fed6e70d01b1e25679deda62cd565f
7
- data.tar.gz: 55bad4a32186f3fca55958be7c5e8a7703f59d7064394cfe040c0aadc7b99961876a555cd66f361520979c4f5622c6e3d8004059eeabf7c222559318221a1703
6
+ metadata.gz: 859a4f282ae1505193d540ef46137d229a5efc4d2797d2640cc47fcea265151145071617b404a7fbcf4c48a2eec5e2acb1e02ed54127b546894406b48badf545
7
+ data.tar.gz: d8f1a0e3645f7ceb8e84e11e407d0d75dbb6763dfbb827e7c27965e9364745324e968f8ef1883a9339636b6929da4ee8c1381842b79b32f31d2d1ef84165c44a
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2013 YOURNAME
1
+ Copyright 2013 Yuva Kumar
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -185,6 +185,39 @@ The typical flow about how to use this gem is:
185
185
  creating questions fail.
186
186
 
187
187
 
188
+ ## Notes on upgrading
189
+ ##### Upgrading from 1.2.0 to 2.0.0
190
+
191
+ The default delimiter which is used to store options for questions like select
192
+ input, multiple answers for checkbox question is comma (,). This resulted in
193
+ problems where gem is unable to parse options properly if answers also contain
194
+ commas. For more information see [issue-19](https://github.com/code-mancers/rapidfire/issues/19).
195
+
196
+ Starting from version `2.0.0` default delimiter is changed to `\r\n`, but a
197
+ configuration is provided to change the delimiter. Please run this rake task
198
+ to make existing questions or stored answers to use new delimiter.
199
+
200
+ NOTE: Please take database backup before running this rake task.
201
+
202
+ ```ruby
203
+ bundle exec rake rapidfire:change_delimiter_from_comma_to_srsn
204
+ ```
205
+
206
+
207
+ If you dont want to make this change rightaway, and would like to use comma
208
+ as delimiter, then please use this initializer, but be warned that in future
209
+ delimiter will be hardcoded to `\r\n`:
210
+
211
+
212
+ ```ruby
213
+ # /<path-to-app>/config/initializers/rapidfire.rb
214
+
215
+ Rapidfire.config do |config|
216
+ config.answers_delimiter = ','
217
+ end
218
+ ```
219
+
220
+
188
221
  ## TODO
189
222
  1. Add ability to sort questions, so that order is preserved.
190
223
  2. Add multi tenant support.
@@ -6,7 +6,9 @@ module Rapidfire
6
6
  end
7
7
 
8
8
  def checkbox_checked?(answer, option)
9
- answer.answer_text.to_s.split(",").include?(option)
9
+ answers_delimiter = Rapidfire.answers_delimiter
10
+ answers = answer.answer_text.to_s.split(answers_delimiter)
11
+ answers.include?(option)
10
12
  end
11
13
  end
12
14
  end
@@ -4,14 +4,14 @@ module Rapidfire
4
4
  validates :answer_options, :presence => true
5
5
 
6
6
  def options
7
- answer_options.split(/\r?\n/)
7
+ answer_options.split(Rapidfire.answers_delimiter)
8
8
  end
9
9
 
10
10
  def validate_answer(answer)
11
11
  super(answer)
12
12
 
13
13
  if rules[:presence] == "1" || answer.answer_text.present?
14
- answer.answer_text.split(",").each do |value|
14
+ answer.answer_text.split(Rapidfire.answers_delimiter).each do |value|
15
15
  answer.errors.add(:answer_text, :invalid) unless options.include?(value)
16
16
  end
17
17
  end
@@ -4,7 +4,7 @@ module Rapidfire
4
4
  validates :answer_options, :presence => true
5
5
 
6
6
  def options
7
- answer_options.split(/\r?\n/)
7
+ answer_options.split(Rapidfire.answers_delimiter)
8
8
  end
9
9
 
10
10
  def validate_answer(answer)
@@ -15,8 +15,17 @@ module Rapidfire
15
15
  params.each do |question_id, answer_attributes|
16
16
  if answer = @answer_group.answers.find { |a| a.question_id.to_s == question_id.to_s }
17
17
  text = answer_attributes[:answer_text]
18
+
19
+ # in case of checkboxes, values are submitted as an array of
20
+ # strings. we will store answers as one big string separated
21
+ # by delimiter.
18
22
  answer.answer_text =
19
- text.is_a?(Array) ? strip_checkbox_answers(text).join(',') : text
23
+ if text.is_a?(Array)
24
+ stripped_answers = strip_checkbox_answers(text)
25
+ stripped_answers.join(Rapidfire.answers_delimiter)
26
+ else
27
+ text
28
+ end
20
29
  end
21
30
  end
22
31
 
@@ -25,7 +34,7 @@ module Rapidfire
25
34
 
26
35
  def save(options = {})
27
36
  save!(options)
28
- rescue Exception => e
37
+ rescue ActiveRecord::ActiveRecordError => e
29
38
  # repopulate answers here in case of failure as they are not getting updated
30
39
  @answers = @question_group.questions.collect do |question|
31
40
  @answer_group.answers.find { |a| a.question_id == question.id }
@@ -14,9 +14,11 @@ module Rapidfire
14
14
  case question
15
15
  when Rapidfire::Questions::Select, Rapidfire::Questions::Radio,
16
16
  Rapidfire::Questions::Checkbox
17
- answers = question.answers.map(&:answer_text).map { |text| text.split(',') }.flatten
18
- answers.inject(Hash.new(0)) { |total, e| total[e] += 1; total }
17
+ answers = question.answers.map(&:answer_text).map do |text|
18
+ text.to_s.split(Rapidfire.answers_delimiter)
19
+ end.flatten
19
20
 
21
+ answers.inject(Hash.new(0)) { |total, e| total[e] += 1; total }
20
22
  when Rapidfire::Questions::Short, Rapidfire::Questions::Date,
21
23
  Rapidfire::Questions::Long, Rapidfire::Questions::Numeric
22
24
  question.answers.pluck(:answer_text)
data/lib/rapidfire.rb CHANGED
@@ -3,4 +3,14 @@ require "rapidfire/engine"
3
3
  module Rapidfire
4
4
  class AccessDenied < StandardError
5
5
  end
6
+
7
+ # configuration which will be used as delimiter in case answers are bunch
8
+ # of collection values. This is the default delimiter which is used by
9
+ # all the browsers.
10
+ mattr_accessor :answers_delimiter
11
+ self.answers_delimiter = "\r\n"
12
+
13
+ def self.config
14
+ yield(self)
15
+ end
6
16
  end
@@ -1,3 +1,3 @@
1
1
  module Rapidfire
2
- VERSION = "1.2.0"
2
+ VERSION = '2.0.0'
3
3
  end
@@ -0,0 +1,16 @@
1
+ desc 'Earlier delimiter used to be comma(,), but for #19, delimter is changed to \r\n'
2
+ namespace :rapidfire do
3
+ task change_delimiter_from_comma_to_srsn: :environment do
4
+ Rapidfire::Question.transaction do
5
+ Rapidfire::Question.all.each do |question|
6
+ if question.is_a?(Rapidfire::Questions::Checkbox) ||
7
+ question.is_a?(Rapidfire::Questions::Select)
8
+
9
+ new_answer_options = question.answer_options.split(',')
10
+ .join(Rapidfire.answers_delimiter)
11
+ question.update_attributes!(answer_options: new_answer_options)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,125 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapidfire
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuva Kumar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-02 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.13
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.13
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: active_model_serializers
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.8.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.8.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: quiet_assets
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 2.14.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 2.14.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: shoulda
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: database_cleaner
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: factory_girl_rails
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
@@ -140,28 +140,28 @@ dependencies:
140
140
  name: capybara-webkit
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: launchy
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - '>='
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  description: One stop solution for all survey related requirements! Its tad easy!.
@@ -171,6 +171,9 @@ executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
+ - MIT-LICENSE
175
+ - README.md
176
+ - Rakefile
174
177
  - app/assets/javascripts/rapidfire/application.js
175
178
  - app/assets/stylesheets/rapidfire/application.css
176
179
  - app/controllers/rapidfire/answer_groups_controller.rb
@@ -221,33 +224,33 @@ files:
221
224
  - db/migrate/20130502195415_create_rapidfire_answer_groups.rb
222
225
  - db/migrate/20130502195504_create_rapidfire_answers.rb
223
226
  - lib/generators/rapidfire/views_generator.rb
227
+ - lib/rapidfire.rb
224
228
  - lib/rapidfire/engine.rb
225
229
  - lib/rapidfire/version.rb
226
- - lib/rapidfire.rb
230
+ - lib/tasks/change_delimiter_to_srsn.rake
227
231
  - lib/tasks/rapidfire_tasks.rake
228
- - MIT-LICENSE
229
- - Rakefile
230
- - README.md
231
232
  homepage: https://github.com/code-mancers/rapidfire
232
233
  licenses: []
233
234
  metadata: {}
234
- post_install_message:
235
+ post_install_message: |
236
+ There is breaking delimiter change when upgrading to version 2.0.0.
237
+ Please see Readme for more information.
235
238
  rdoc_options: []
236
239
  require_paths:
237
240
  - lib
238
241
  required_ruby_version: !ruby/object:Gem::Requirement
239
242
  requirements:
240
- - - '>='
243
+ - - ">="
241
244
  - !ruby/object:Gem::Version
242
245
  version: '0'
243
246
  required_rubygems_version: !ruby/object:Gem::Requirement
244
247
  requirements:
245
- - - '>='
248
+ - - ">="
246
249
  - !ruby/object:Gem::Version
247
250
  version: '0'
248
251
  requirements: []
249
252
  rubyforge_project:
250
- rubygems_version: 2.0.3
253
+ rubygems_version: 2.4.2
251
254
  signing_key:
252
255
  specification_version: 4
253
256
  summary: Surveys made easy.