diff --git a/Gemfile.rails_version b/Gemfile.rails_version index d8ecdd46..488f186e 100644 --- a/Gemfile.rails_version +++ b/Gemfile.rails_version @@ -1,6 +1,8 @@ # For testing against different releases of Rails. This is in a # separate fragment so that it can be sourced from the test # application's Gemfile in addition to the main development Gemfile. + +ENV['RAILS_VERSION'] = '4.0.0' # SMELL Explicitly setting RAILS_VERSION as it's not set if ENV['RAILS_VERSION'] case ENV['RAILS_VERSION'] when /3.0$/ @@ -13,7 +15,14 @@ if ENV['RAILS_VERSION'] gem 'rails', '~> 3.2.0' # A JS runtime is required for Rails 3.1+ gem 'therubyracer', '~> 0.10.2' + when /4.0.0$/ + gem 'rails', '~> 4.0.0' + # A JS runtime is required for Rails 4.0+ + gem 'therubyracer', platforms: :ruby + gem 'protected_attributes' # SMELL remove this to provide full Rails 4 support for Strong Parameters else fail "Unknown Rails version #{ENV['RAILS_VERSION']}" end +else + fail "ENV['RAILS_VERSION'] not set" end diff --git a/lib/surveyor.rb b/lib/surveyor.rb index 064700c5..50acc4f3 100644 --- a/lib/surveyor.rb +++ b/lib/surveyor.rb @@ -1,5 +1,5 @@ module Surveyor - require 'surveyor/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3 + require 'surveyor/engine' if defined?(Rails) && Rails::VERSION::MAJOR >= 3 autoload :VERSION, 'surveyor/version' autoload :ParserError, 'surveyor/parser' end diff --git a/lib/surveyor/models/dependency_methods.rb b/lib/surveyor/models/dependency_methods.rb index 60b6c95b..2bf5c185 100644 --- a/lib/surveyor/models/dependency_methods.rb +++ b/lib/surveyor/models/dependency_methods.rb @@ -11,7 +11,7 @@ def self.included(base) unless @@validations_already_included # Validations base.send :validates_presence_of, :rule - base.send :validates_format_of, :rule, :with => /^(?:and|or|\)|\(|[A-Z]|\s)+$/ #TODO properly formed parenthesis etc. + base.send :validates_format_of, :rule, :with => /^(?:and|or|\)|\(|[A-Z]|\s)+$/, :multiline => true #TODO properly formed parenthesis etc. # SMELL with :multiline => true Rails reports a security risk base.send :validates_numericality_of, :question_id, :if => Proc.new { |d| d.question_group_id.nil? } base.send :validates_numericality_of, :question_group_id, :if => Proc.new { |d| d.question_id.nil? } diff --git a/lib/surveyor/models/validation_methods.rb b/lib/surveyor/models/validation_methods.rb index 3a86ac37..b3b418b4 100644 --- a/lib/surveyor/models/validation_methods.rb +++ b/lib/surveyor/models/validation_methods.rb @@ -12,7 +12,7 @@ def self.included(base) unless @@validations_already_included # Validations base.send :validates_presence_of, :rule - base.send :validates_format_of, :rule, :with => /^(?:and|or|\)|\(|[A-Z]|\s)+$/ + base.send :validates_format_of, :rule, :with => /^(?:and|or|\)|\(|[A-Z]|\s)+$/, :multiline => true # this causes issues with building and saving # base.send :validates_numericality_of, :answer_id diff --git a/spec/factories.rb b/spec/factories.rb index f4e13062..5e5e2eff 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -3,159 +3,164 @@ require 'rubygems' require 'factory_girl' -Factory.sequence(:unique_survey_access_code){|n| "simple survey #{UUIDTools::UUID.random_create.to_s}" } +FactoryGirl.define do + + sequence(:unique_survey_access_code){|n| "simple survey #{UUIDTools::UUID.random_create.to_s}" } + + factory :survey do |s| + s.title "Simple survey" + s.description "A simple survey for testing" + s.access_code { FactoryGirl.next :unique_survey_access_code } + s.survey_version 0 + end + + + factory :survey_translation do |t| + t.locale "es" + t.translation %(title: "Un idioma nunca es suficiente" + survey_sections: + one: + title: "Uno" + questions: + hello: + text: "¡Hola!" + name: + text: "¿Cómo se llama Usted?" + answers: + name: + help_text: "Mi nombre es...") + end + + sequence(:survey_section_display_order){|n| n } + + factory :survey_section do |s| + s.association :survey # s.survey_id {} + s.title {"Demographics"} + s.description {"Asking you about your personal data"} + s.display_order {FactoryGirl.next :survey_section_display_order} + s.reference_identifier {"demographics"} + s.data_export_identifier {"demographics"} + end + + sequence(:question_display_order){|n| n } + + factory :question do |q| + q.association :survey_section # s.survey_section_id {} + # q.question_group_id {} + q.text "What is your favorite color?" + q.short_text "favorite_color" + q.help_text "just write it in the box" + q.pick :none + q.reference_identifier {|me| "q_#{me.object_id}"} + # q.data_export_identifier {} + # q.common_namespace {} + # q.common_identifier {} + q.display_order FactoryGirl.generate(:question_display_order) + # q.display_type {} # nil is default + q.is_mandatory false + # q.display_width {} + q.correct_answer_id nil + end + + factory :question_group do |g| + g.text {"Describe your family"} + g.help_text {} + g.reference_identifier {|me| "g_#{me.object_id}"} + g.data_export_identifier {} + g.common_namespace {} + g.common_identifier {} + g.display_type {} + g.custom_class {} + g.custom_renderer {} + end + + sequence(:answer_display_order){|n| n } + + factory :answer do |a| + a.association :question # a.question_id {} + a.text "My favorite color is clear" + a.short_text "clear" + a.help_text "Clear is the absense of color" + # a.weight + a.response_class "string" + # a.reference_identifier {} + # a.data_export_identifier {} + # a.common_namespace {} + # a.common_identifier {} + a.display_order {FactoryGirl.next :answer_display_order} + # a.is_exclusive {} + a.display_type "default" + # a.display_length {} + # a.custom_class {} + # a.custom_renderer {} + end + + factory :dependency do |d| + # the dependent question + d.association :question # d.question_id {} + d.question_group_id {} + d.rule {"A"} + end + + factory :dependency_condition do |d| + d.association :dependency # d.dependency_id {} + d.rule_key {"A"} + # the conditional question + d.question_id {} + d.operator {"=="} + d.answer_id {} + d.datetime_value {} + d.integer_value {} + d.float_value {} + d.unit {} + d.text_value {} + d.string_value {} + d.response_other {} + end + + factory :response_set do |r| + r.user_id {} + r.association :survey # r.survey_id {} + r.access_code {Surveyor::Common.make_tiny_code} + r.started_at {Time.now} + r.completed_at {} + end + + factory :response do |r| + r.association :response_set # r.response_set_id {} + r.survey_section_id {} + r.question_id {} + r.answer_id {} + r.datetime_value {} + r.integer_value {} + r.float_value {} + r.unit {} + r.text_value {} + r.string_value {} + r.response_other {} + r.response_group {} + end + + factory :validation do |v| + v.association :answer # v.answer_id {} + v.rule {"A"} + v.message {} + end + + factory :validation_condition do |v| + v.association :validation # v.validation_id {} + v.rule_key {"A"} + v.question_id {} + v.operator {"=="} + v.answer_id {} + v.datetime_value {} + v.integer_value {} + v.float_value {} + v.unit {} + v.text_value {} + v.string_value {} + v.response_other {} + v.regexp {} + end -Factory.define :survey do |s| - s.title "Simple survey" - s.description "A simple survey for testing" - s.access_code { Factory.next :unique_survey_access_code } - s.survey_version 0 -end - -Factory.define :survey_translation do |t| - t.locale "es" - t.translation %(title: "Un idioma nunca es suficiente" -survey_sections: - one: - title: "Uno" -questions: - hello: - text: "¡Hola!" - name: - text: "¿Cómo se llama Usted?" - answers: - name: - help_text: "Mi nombre es...") -end - -Factory.sequence(:survey_section_display_order){|n| n } - -Factory.define :survey_section do |s| - s.association :survey # s.survey_id {} - s.title {"Demographics"} - s.description {"Asking you about your personal data"} - s.display_order {Factory.next :survey_section_display_order} - s.reference_identifier {"demographics"} - s.data_export_identifier {"demographics"} -end - -Factory.sequence(:question_display_order){|n| n } - -Factory.define :question do |q| - q.association :survey_section # s.survey_section_id {} - # q.question_group_id {} - q.text "What is your favorite color?" - q.short_text "favorite_color" - q.help_text "just write it in the box" - q.pick :none - q.reference_identifier {|me| "q_#{me.object_id}"} - # q.data_export_identifier {} - # q.common_namespace {} - # q.common_identifier {} - q.display_order Factory.next :question_display_order - # q.display_type {} # nil is default - q.is_mandatory false - # q.display_width {} - q.correct_answer_id nil -end - -Factory.define :question_group do |g| - g.text {"Describe your family"} - g.help_text {} - g.reference_identifier {|me| "g_#{me.object_id}"} - g.data_export_identifier {} - g.common_namespace {} - g.common_identifier {} - g.display_type {} - g.custom_class {} - g.custom_renderer {} -end - -Factory.sequence(:answer_display_order){|n| n } - -Factory.define :answer do |a| - a.association :question # a.question_id {} - a.text "My favorite color is clear" - a.short_text "clear" - a.help_text "Clear is the absense of color" - # a.weight - a.response_class "string" - # a.reference_identifier {} - # a.data_export_identifier {} - # a.common_namespace {} - # a.common_identifier {} - a.display_order {Factory.next :answer_display_order} - # a.is_exclusive {} - a.display_type "default" - # a.display_length {} - # a.custom_class {} - # a.custom_renderer {} -end - -Factory.define :dependency do |d| - # the dependent question - d.association :question # d.question_id {} - d.question_group_id {} - d.rule {"A"} -end - -Factory.define :dependency_condition do |d| - d.association :dependency # d.dependency_id {} - d.rule_key {"A"} - # the conditional question - d.question_id {} - d.operator {"=="} - d.answer_id {} - d.datetime_value {} - d.integer_value {} - d.float_value {} - d.unit {} - d.text_value {} - d.string_value {} - d.response_other {} -end - -Factory.define :response_set do |r| - r.user_id {} - r.association :survey # r.survey_id {} - r.access_code {Surveyor::Common.make_tiny_code} - r.started_at {Time.now} - r.completed_at {} -end - -Factory.define :response do |r| - r.association :response_set # r.response_set_id {} - r.survey_section_id {} - r.question_id {} - r.answer_id {} - r.datetime_value {} - r.integer_value {} - r.float_value {} - r.unit {} - r.text_value {} - r.string_value {} - r.response_other {} - r.response_group {} -end - -Factory.define :validation do |v| - v.association :answer # v.answer_id {} - v.rule {"A"} - v.message {} -end - -Factory.define :validation_condition do |v| - v.association :validation # v.validation_id {} - v.rule_key {"A"} - v.question_id {} - v.operator {"=="} - v.answer_id {} - v.datetime_value {} - v.integer_value {} - v.float_value {} - v.unit {} - v.text_value {} - v.string_value {} - v.response_other {} - v.regexp {} end diff --git a/surveyor.gemspec b/surveyor.gemspec index 938ef821..f733cd0c 100644 --- a/surveyor.gemspec +++ b/surveyor.gemspec @@ -17,28 +17,29 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency('rails', '~> 3.0') + s.add_dependency('rails', '~> 4.0') # '< 5.0' is to be conservative; once 5.0 comes out we should test with it and # allow it if it works. - s.add_dependency('haml', '>= 3.1.3', '< 5.0') + s.add_dependency('haml')#, '>= 3.1.3', '< 5.0') s.add_dependency('sass') - s.add_dependency('fastercsv', '~> 1.5.4') - s.add_dependency('formtastic', '~> 2.1.0') - s.add_dependency('uuidtools', '~> 2.1') - s.add_dependency('mustache', '0.99.4') - s.add_dependency('rabl', '~>0.6.13') + s.add_dependency('fastercsv')#, '~> 1.5.4') + s.add_dependency('formtastic')#, '~> 2.1.0') + s.add_dependency('uuidtools')#, '~> 2.1') + s.add_dependency('mustache')#, '0.99.4') + s.add_dependency('rabl')#, '~>0.6.13') + s.add_dependency('protected_attributes') # SMELL remove this to provide full Rails 4 support for Strong Parameters s.add_development_dependency('yard') - s.add_development_dependency('rake', '>= 0.9.2') - s.add_development_dependency('rspec-rails', '~> 2.9.0') - s.add_development_dependency('bundler', '~> 1.0', '>= 1.0.21') - s.add_development_dependency('factory_girl', '~> 2.1.2') + s.add_development_dependency('rake')#, '>= 0.9.2') + s.add_development_dependency('rspec-rails')#, '~> 2.9.0') + s.add_development_dependency('bundler')#, '~> 1.0', '>= 1.0.21') + s.add_development_dependency('factory_girl')#, '~> 2.1.2') s.add_development_dependency('sqlite3') - s.add_development_dependency('cucumber-rails', '~> 1.1.1') - s.add_development_dependency('database_cleaner', '~> 0.6.7') - s.add_development_dependency('launchy', '~> 2.0.5') - s.add_development_dependency('capybara', '~> 1.1.1') - s.add_development_dependency('ci_reporter', '1.6.6') - s.add_development_dependency('json_spec', '~> 1.0.3') + s.add_development_dependency('cucumber-rails')#, '~> 1.1.1') + s.add_development_dependency('database_cleaner')#, '~> 0.6.7') + s.add_development_dependency('launchy')#, '~> 2.0.5') + s.add_development_dependency('capybara')#, '~> 1.1.1') + s.add_development_dependency('ci_reporter')#, '1.6.6') + s.add_development_dependency('json_spec')#, '~> 1.0.3') end