limesurvey_rails 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2QwZWVmM2Y4YTRkMTExNTA3NGFiYmI3ZGE0YzY0OTFiYTdjMWM2ZA==
5
- data.tar.gz: !binary |-
6
- NTIyNTA1MDdjOTA3YzQ3ZjFkMTg4ZTZiZmI4YTA4NDhjMDUxMWZmNg==
2
+ SHA1:
3
+ metadata.gz: 351602763701027dc6e423683355a693202c5e9b
4
+ data.tar.gz: 5f1e7ed4ac34354d4e40d0aed5a64c731b13b1f8
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YzFhMTkyZWY5YTY5Y2Q5NzQ4Mzc2ODJhMmM0Yjk0ZjdlY2YyMDcxYWY4OWMw
10
- M2JkZDUxZmVlMGQxZDhlZDdiZTVkMzJiZTZjYTY3YWUzYWQ0MjU5ZTIyYjEz
11
- NGNlZmU3NTVhODY5YmZmYWU5NWJhMWNjMzIyNzQzNDM3ZTdjMzE=
12
- data.tar.gz: !binary |-
13
- OGI1ZmFkZDU1MDA5NDlkMTM4YWZiODFmZDg3NjlhYzJlMTJmZjlkZjIwM2Y2
14
- ZDI5ZTRmMDM4M2I5MDgxODJhZWNmYzI0YjI3YjBjY2FmNmZmNTkzMzUxOTVm
15
- Yzc3YTFjMjAzZTg1YzA0N2MzMTY1YjVkNGU5N2FiMzk1NTA5ZWE=
6
+ metadata.gz: 662be940c3c502bd8b0182faa73f030c0a5f64900603760c16bb76f896c54bbbf5936c852171f4b011176c47721afbcd52aa5afc76eb69ba007f15101c97ed33
7
+ data.tar.gz: 7f8a2623bb2f34e3629c71d6c1e394f1f6f924fbf36dec0f3eb4cf31af06f8a4e4ef8985935a6bd3cf4ac455a27f06adbb8687b83d7124563e086a2e1db5baef
data/.gitignore CHANGED
@@ -21,3 +21,6 @@ tmp
21
21
  *.a
22
22
  mkmf.log
23
23
  .ruby-version
24
+ spec/dummy/db/test.sqlite3
25
+ spec/dummy/log/development.log
26
+ spec/dummy/log/test.log
data/README.md CHANGED
@@ -22,12 +22,26 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- In your participant model simply add
25
+ In your participant model simply execute from your model class
26
26
 
27
- is_a_limesurvey_participant
27
+ is_a_limesurvey_participant
28
28
 
29
29
  but there are many options ..
30
30
 
31
+ ## Test
32
+
33
+ Because of [this](http://stackoverflow.com/posts/27786703) it's better run test separately (in a real scenario the *participant model* is expected to be initialized only once):
34
+
35
+ rake spec[main]
36
+ rake spec[survey]
37
+ rake spec[participant]
38
+ rake spec[participation]
39
+
40
+ Reminder for further bug investigation:
41
+
42
+ rake spec[,25280] #failing test
43
+ rake spec[survey,25280] #passing test
44
+
31
45
  ## Contributing
32
46
 
33
47
  1. Fork it ( https://github.com/[my-github-username]/limesurvey_rails/fork )
data/Rakefile CHANGED
@@ -27,6 +27,7 @@ RSpec::Core::RakeTask.new(:spec, :tag, :seed) do |t, task_args|
27
27
  t.rspec_opts = ''
28
28
  t.rspec_opts += " --tag #{task_args[:tag]}" unless task_args[:tag].blank?
29
29
  t.rspec_opts += " --seed #{task_args[:seed]}" unless task_args[:seed].blank?
30
+ t.rspec_opts += " --no-fail-fast"
30
31
  end
31
32
 
32
33
  desc "Run specfiles specified by pattern with optional seed"
@@ -2,6 +2,40 @@ module LimesurveyRails
2
2
 
3
3
  module Participant
4
4
 
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ # I put this here because I want limesurvey_participant class attribute to be available as soon as you include the gem
9
+ class_attribute :limesurvey_participant
10
+ self.limesurvey_participant = false
11
+ # instance methods
12
+ def add_to_survey(survey)
13
+ if survey.is_a? Survey
14
+ survey.add_participant(self)
15
+ else
16
+ raise WrongArgumentError, "expexted Survey object, got #{survey.class}"
17
+ end
18
+ end
19
+
20
+ def remove_from_survey(survey)
21
+ if survey.is_a? Survey
22
+ survey.remove_participant(self)
23
+ else
24
+ raise WrongArgumentError, "expexted Survey object, got #{survey.class}"
25
+ end
26
+ end
27
+
28
+ def surveys
29
+ survey_participations.map(&:survey)
30
+ end
31
+
32
+ def available_surveys
33
+ ids = surveys.map(&:id).map(&:to_s)
34
+ Survey.all.delete_if{|s| ids.include? s.id }
35
+ end
36
+
37
+ end
38
+
5
39
  module ClassMethods
6
40
 
7
41
  def is_a_limesurvey_participant(opts = {})
@@ -19,7 +53,7 @@ module LimesurveyRails
19
53
 
20
54
  has_many :survey_participations, :class_name => "LimesurveyRails::SurveyParticipation", :foreign_key => "participant_id", :dependent => limesurvey_participant_dependent_participations do
21
55
  def for_survey(survey_id)
22
- res = where("survey_id == #{survey_id}")
56
+ res = where("survey_id = #{survey_id}")
23
57
  raise MultipleParticipationsToSurveyError if res.size > 1
24
58
  res.first
25
59
  end
@@ -41,46 +75,7 @@ module LimesurveyRails
41
75
  limesurvey_participant
42
76
  end
43
77
  end
44
-
45
- module InstanceMethods
46
-
47
- def add_to_survey(survey)
48
- if survey.is_a? Survey
49
- survey.add_participant(self)
50
- else
51
- raise WrongArgumentError, "expexted Survey object, got #{survey.class}"
52
- end
53
- end
54
-
55
- def remove_from_survey(survey)
56
- if survey.is_a? Survey
57
- survey.remove_participant(self)
58
- else
59
- raise WrongArgumentError, "expexted Survey object, got #{survey.class}"
60
- end
61
- end
62
-
63
- def surveys
64
- survey_participations.map(&:survey)
65
- end
66
-
67
- def available_surveys
68
- ids = surveys.map(&:id).map(&:to_s)
69
- Survey.all.delete_if{|s| ids.include? s.id }
70
- end
71
-
72
- end
73
-
74
- def self.included(receiver)
75
78
 
76
- # I put this here because I want limesurvey_participant class attribute to be available as soon as you include the gem
77
- receiver.class_attribute :limesurvey_participant
78
- receiver.limesurvey_participant = false
79
-
80
- receiver.extend ClassMethods
81
- receiver.send :include, InstanceMethods
82
- end
83
-
84
79
  end
85
80
 
86
81
  ActiveRecord::Base.send :include, Participant
@@ -1,3 +1,3 @@
1
1
  module LimesurveyRails
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -19,12 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency(%q<rails>, ["~> 3.2.16"])
22
- spec.add_runtime_dependency(%q<limesurvey>, [">= 0"])
22
+ spec.add_runtime_dependency(%q<limesurvey>, ["~> 1.0"])
23
23
 
24
- spec.add_development_dependency(%q<rspec-rails>, [">= 0"])
25
- spec.add_development_dependency(%q<rspec-its>, [">= 0"])
24
+ spec.add_development_dependency(%q<rspec-rails>, ["~> 3.0"])
25
+ spec.add_development_dependency(%q<rspec-its>, ["~> 1.0"])
26
26
  spec.add_development_dependency(%q<factory_girl_rails>, [">= 0"])
27
27
  spec.add_development_dependency(%q<sqlite3>, [">= 0"])
28
- spec.add_development_dependency(%q<debugger>, [">= 0"])
29
- spec.add_development_dependency(%q<awesome_print>, [">= 0"])
28
+ spec.add_development_dependency(%q<byebug>, [">= 3.0"])
29
+ spec.add_development_dependency('gem-release')
30
30
  end
@@ -1,12 +1,12 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  module LimesurveyRails
4
- describe TestModel, :participant do
4
+ describe TestModel, :participant do
5
5
 
6
6
  before(:all) do
7
7
  configure_and_connect
8
8
  remove_all_test_surveys
9
- reset_models
9
+ # reset_models # uncomment to run all suite test in one single run
10
10
  @test_survey_id = get_brand_new_test_survey_id(:activate_tokens => true)
11
11
  end
12
12
  after(:all) { remove_all_test_surveys }
@@ -21,10 +21,10 @@ module LimesurveyRails
21
21
  its(:is_a_limesurvey_participant_class?) { is_expected.to be false }
22
22
  end
23
23
 
24
- describe ".is_a_limesurvey_participant" do
25
- before(:each) { reset_models }
24
+ describe ".is_a_limesurvey_participant", :wip do
26
25
  context "with no options" do
27
- before(:each) do
26
+ before(:all) do
27
+ reset_models
28
28
  TestModel.is_a_limesurvey_participant
29
29
  end
30
30
  it "has many survey_participations" do
@@ -37,19 +37,22 @@ module LimesurveyRails
37
37
  its(:limesurvey_participant_lastname_attr) { is_expected.to be_nil }
38
38
  end
39
39
  context "with options :attribute_1_attr => 'other_id' " do
40
- before(:each) do
40
+ before(:all) do
41
+ reset_models
41
42
  TestModel.is_a_limesurvey_participant(:attribute_1_attr => 'other_id')
42
43
  end
43
44
  its(:is_a_limesurvey_participant_class?) { is_expected.to be true }
44
45
  its(:limesurvey_participant_attribute_1_attr) { is_expected.to eq 'other_id' }
45
46
  end
46
47
  context "with options :email_attr => 'email_address', :firstname_attr => 'name', :lastname_attr => 'surname' " do
47
- before(:each) do
48
+ before(:all) do
49
+ reset_models
48
50
  TestModel.is_a_limesurvey_participant(:email_attr => 'email_address', :firstname_attr => 'name', :lastname_attr => 'surname')
49
51
  end
50
52
  its(:limesurvey_participant_email_attr) { is_expected.to eq 'email_address' }
51
53
  its(:limesurvey_participant_firstname_attr) { is_expected.to eq 'name' }
52
54
  its(:limesurvey_participant_lastname_attr) { is_expected.to eq 'surname' }
55
+ its(:limesurvey_participant_attribute_1_attr) { is_expected.to eq 'id' }
53
56
  end
54
57
  end
55
58
 
@@ -1,14 +1,14 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  module LimesurveyRails
4
- describe SurveyParticipation, :participation => true do
4
+ describe SurveyParticipation, :participation do
5
5
 
6
6
  subject { SurveyParticipation }
7
7
 
8
8
  before(:all) do
9
9
  configure_and_connect
10
10
  @test_survey_id = get_brand_new_test_survey_id(:activate_tokens => true)
11
- reset_models
11
+ # reset_models # uncomment to run all suite test in one single run
12
12
  TestModel.is_a_limesurvey_participant :attribute_1_attr => "extra_id", :email_attr => 'email_address', :firstname_attr => 'name', :lastname_attr => 'surname'
13
13
  end
14
14
  after(:all) { remove_all_test_surveys }
@@ -2,10 +2,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  module LimesurveyRails
4
4
 
5
- describe Survey, :survey => true do
5
+ describe Survey, :survey do
6
6
  before(:all) do
7
7
  configure_and_connect
8
- reset_models
8
+ # reset_models # uncomment to run all suite test in one single run
9
9
  TestModel.is_a_limesurvey_participant :attribute_1_attr => "extra_id", :email_attr => 'email_address', :firstname_attr => 'name', :lastname_attr => 'surname'
10
10
  end
11
11
  after(:all) { remove_all_test_surveys }
@@ -90,7 +90,7 @@ module LimesurveyRails
90
90
  FactoryGirl.create_list(:test_model,3)
91
91
  TestModel.all.each{ |tm| FactoryGirl.create(:limesurvey_rails_survey_participation, :survey_id => test_survey.id, :participant_id => tm.id ) }
92
92
  end
93
- it "its survey participations are deleted", :wip do
93
+ it "its survey participations are deleted" do
94
94
  test_survey.destroy
95
95
  expect(SurveyParticipation.for_survey(test_survey.id)).to be_empty
96
96
  end
@@ -98,11 +98,6 @@ module LimesurveyRails
98
98
  end
99
99
 
100
100
  describe "participants instance methods" do
101
- # before(:all) { reset_models; TestModel.is_a_limesurvey_participant :attribute_1_attr => "extra_id", :email_attr => 'email_address', :firstname_attr => 'name', :lastname_attr => 'surname'}
102
- # before(:each) do
103
- # instances = FactoryGirl.create_list(:test_model,3)
104
- # instances.each{ |tm| FactoryGirl.create(:limesurvey_rails_survey_participation, :survey_id => test_survey.id, :participant_id => tm.id ) }
105
- # end
106
101
 
107
102
  let(:a_participant) { FactoryGirl.create(:test_model) }
108
103
 
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
4
  require 'rspec/rails'
5
5
  require 'rspec/its'
6
6
  require 'factory_girl_rails'
7
+ require 'byebug'
7
8
 
8
9
  Rails.backtrace_cleaner.remove_silencers!
9
10
 
@@ -22,26 +22,41 @@ end
22
22
  # reload test model to reuse it among tests (mostly to reset variable classes...)
23
23
  # http://stackoverflow.com/questions/14063395/rspec-class-variable-testing
24
24
  def reset_models
25
- # puts "resetting TestModel ..."
26
-
25
+ # puts "resetting constants ..."
26
+ if LimesurveyRails.const_defined? :Participant
27
+ LimesurveyRails.send(:remove_const,:Participant)
28
+ load File.join(ENGINE_RAILS_ROOT,'lib','limesurvey_rails','participant.rb')
29
+ end
30
+
27
31
  if Object.const_defined? :TestModel
28
- Object.constants Object.send(:remove_const,:TestModel)
32
+ Object.send(:remove_const,:TestModel)
29
33
  load File.join(ENGINE_RAILS_ROOT,'spec','dummy','app','models','test_model.rb')
30
34
  # puts ">>>> TestModel.object_id: #{TestModel.object_id}"
31
35
  end
32
36
 
33
-
34
- # if LimesurveyRails.const_defined? :Participant
35
- # LimesurveyRails.send(:remove_const,:Participant)
36
- # load File.join(ENGINE_RAILS_ROOT,'lib','limesurvey_rails','participant.rb')
37
- # end
38
-
39
37
  if LimesurveyRails.const_defined? :SurveyParticipation
40
38
  LimesurveyRails.send(:remove_const,:SurveyParticipation)
41
39
  load File.join(ENGINE_RAILS_ROOT,'app','models','limesurvey_rails','survey_participation.rb')
42
40
  # puts ">>>> LimesurveyRails::SurveyParticipation.object_id: #{LimesurveyRails::SurveyParticipation.object_id}"
43
41
  end
44
42
 
43
+
44
+ # puts "before LimesurveyRails::Participant #{LimesurveyRails::Participant.object_id}"
45
+ # puts "before TestModel #{TestModel.object_id}"
46
+ # puts "before LimesurveyRails::SurveyParticipation #{LimesurveyRails::SurveyParticipation.object_id}"
47
+ # ActiveSupport::Dependencies.remove_constant("LimesurveyRails::Participant")
48
+ # ActiveSupport::Dependencies.remove_constant("LimesurveyRails::SurveyParticipation")
49
+ # ActiveSupport::Dependencies.remove_constant("TestModel")
50
+ # load File.join(ENGINE_RAILS_ROOT,'lib','limesurvey_rails','participant.rb')
51
+ # load File.join(ENGINE_RAILS_ROOT,'app','models','limesurvey_rails','survey_participation.rb')
52
+ # load File.join(ENGINE_RAILS_ROOT,'spec','dummy','app','models','test_model.rb')
53
+ # puts "after LimesurveyRails::Participant #{LimesurveyRails::Participant.object_id}"
54
+ # puts "after TestModel #{TestModel.object_id}"
55
+ # puts "after LimesurveyRails::SurveyParticipation #{LimesurveyRails::SurveyParticipation.object_id}"
56
+
45
57
  FactoryGirl.reload
58
+
59
+ # puts "constants resetted"
60
+
46
61
  end
47
62
 
metadata CHANGED
@@ -1,125 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: limesurvey_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - masciugo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
11
+ date: 2015-01-06 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.16
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.16
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: limesurvey
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.0'
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
- version: '0'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.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
- version: '0'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-its
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.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
- version: '0'
68
+ version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: factory_girl_rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '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
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3
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
- name: debugger
98
+ name: byebug
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '3.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
- version: '0'
110
+ version: '3.0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: awesome_print
112
+ name: gem-release
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
  description: An ORM-like layer to Limesurvey
@@ -129,7 +129,7 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
- - .gitignore
132
+ - ".gitignore"
133
133
  - Gemfile
134
134
  - LICENSE.txt
135
135
  - README.md
@@ -222,17 +222,17 @@ require_paths:
222
222
  - lib
223
223
  required_ruby_version: !ruby/object:Gem::Requirement
224
224
  requirements:
225
- - - ! '>='
225
+ - - ">="
226
226
  - !ruby/object:Gem::Version
227
227
  version: '0'
228
228
  required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  requirements:
230
- - - ! '>='
230
+ - - ">="
231
231
  - !ruby/object:Gem::Version
232
232
  version: '0'
233
233
  requirements: []
234
234
  rubyforge_project:
235
- rubygems_version: 2.3.0
235
+ rubygems_version: 2.2.2
236
236
  signing_key:
237
237
  specification_version: 4
238
238
  summary: An ORM-like layer to Limesurvey