validates_overlap 1.0.0 → 1.1.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.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/CONTRIBUTORS.md +26 -0
  4. data/MIT-LICENSE +2 -1
  5. data/README.md +33 -7
  6. data/lib/validates_overlap/overlap_validator.rb +1 -1
  7. data/lib/validates_overlap/version.rb +5 -0
  8. data/lib/validates_overlap.rb +2 -1
  9. metadata +54 -135
  10. data/.gitignore +0 -11
  11. data/.rspec +0 -2
  12. data/.rubocop.yml +0 -5
  13. data/.travis.yml +0 -6
  14. data/Gemfile +0 -3
  15. data/Gemfile.rails60 +0 -5
  16. data/Rakefile +0 -39
  17. data/VERSION +0 -1
  18. data/spec/dummy/Rakefile +0 -7
  19. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  20. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  21. data/spec/dummy/app/models/active_meeting.rb +0 -4
  22. data/spec/dummy/app/models/document_with_enum.rb +0 -26
  23. data/spec/dummy/app/models/end_overlap_meeting.rb +0 -3
  24. data/spec/dummy/app/models/meeting.rb +0 -3
  25. data/spec/dummy/app/models/position.rb +0 -9
  26. data/spec/dummy/app/models/secure_meeting.rb +0 -3
  27. data/spec/dummy/app/models/shift.rb +0 -3
  28. data/spec/dummy/app/models/start_end_overlap_meeting.rb +0 -3
  29. data/spec/dummy/app/models/start_overlap_meeting.rb +0 -3
  30. data/spec/dummy/app/models/time_slot.rb +0 -8
  31. data/spec/dummy/app/models/user.rb +0 -2
  32. data/spec/dummy/app/models/user_meeting.rb +0 -3
  33. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  34. data/spec/dummy/config/application.rb +0 -45
  35. data/spec/dummy/config/boot.rb +0 -10
  36. data/spec/dummy/config/database.yml +0 -22
  37. data/spec/dummy/config/environment.rb +0 -5
  38. data/spec/dummy/config/environments/development.rb +0 -25
  39. data/spec/dummy/config/environments/production.rb +0 -49
  40. data/spec/dummy/config/environments/test.rb +0 -35
  41. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  42. data/spec/dummy/config/initializers/inflections.rb +0 -10
  43. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  44. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  45. data/spec/dummy/config/initializers/session_store.rb +0 -8
  46. data/spec/dummy/config/locales/en.yml +0 -5
  47. data/spec/dummy/config/routes.rb +0 -58
  48. data/spec/dummy/config.ru +0 -4
  49. data/spec/dummy/db/migrate/20110406082020_create_meetings.rb +0 -13
  50. data/spec/dummy/db/migrate/20110406082053_create_users.rb +0 -13
  51. data/spec/dummy/db/migrate/20110407060725_create_user_meetings.rb +0 -15
  52. data/spec/dummy/db/migrate/20120509130956_create_end_overlap_meetings.rb +0 -13
  53. data/spec/dummy/db/migrate/20120509131012_create_start_overlap_meetings.rb +0 -13
  54. data/spec/dummy/db/migrate/20120509131032_create_start_end_overlap_meetings.rb +0 -13
  55. data/spec/dummy/db/migrate/20121207162212_create_time_slot.rb +0 -20
  56. data/spec/dummy/db/migrate/20130826155107_create_active_meetings.rb +0 -14
  57. data/spec/dummy/db/migrate/20150707155107_create_secure_meetings.rb +0 -14
  58. data/spec/dummy/db/migrate/20151203153132_create_shifts.rb +0 -13
  59. data/spec/dummy/db/migrate/20170102162952_add_documents_with_enum.rb +0 -14
  60. data/spec/dummy/db/schema.rb +0 -101
  61. data/spec/dummy/public/404.html +0 -26
  62. data/spec/dummy/public/422.html +0 -26
  63. data/spec/dummy/public/500.html +0 -26
  64. data/spec/dummy/public/favicon.ico +0 -0
  65. data/spec/dummy/public/javascripts/application.js +0 -2
  66. data/spec/dummy/public/javascripts/controls.js +0 -965
  67. data/spec/dummy/public/javascripts/dragdrop.js +0 -974
  68. data/spec/dummy/public/javascripts/effects.js +0 -1123
  69. data/spec/dummy/public/javascripts/prototype.js +0 -6001
  70. data/spec/dummy/public/javascripts/rails.js +0 -191
  71. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  72. data/spec/dummy/script/rails +0 -6
  73. data/spec/dummy/spec/factories/active_meeting.rb +0 -7
  74. data/spec/dummy/spec/factories/document_with_enum.rb +0 -7
  75. data/spec/dummy/spec/factories/end_overlap_meeting.rb +0 -6
  76. data/spec/dummy/spec/factories/meeting.rb +0 -6
  77. data/spec/dummy/spec/factories/position.rb +0 -6
  78. data/spec/dummy/spec/factories/secure_meeting.rb +0 -6
  79. data/spec/dummy/spec/factories/shift.rb +0 -6
  80. data/spec/dummy/spec/factories/start_end_overlap_meeting.rb +0 -6
  81. data/spec/dummy/spec/factories/start_overlap_meeting.rb +0 -6
  82. data/spec/dummy/spec/factories/time_slot.rb +0 -6
  83. data/spec/dummy/spec/factories/user.rb +0 -5
  84. data/spec/dummy/spec/factories/user_meeting.rb +0 -13
  85. data/spec/dummy/spec/models/active_meetings_spec.rb +0 -11
  86. data/spec/dummy/spec/models/document_with_enum_spec.rb +0 -53
  87. data/spec/dummy/spec/models/end_overlap_meeting_spec.rb +0 -48
  88. data/spec/dummy/spec/models/meeting_spec.rb +0 -68
  89. data/spec/dummy/spec/models/position_spec.rb +0 -31
  90. data/spec/dummy/spec/models/secure_meeting_spec.rb +0 -14
  91. data/spec/dummy/spec/models/shift_spec.rb +0 -41
  92. data/spec/dummy/spec/models/start_end_overlap_meeting_spec.rb +0 -48
  93. data/spec/dummy/spec/models/start_overlap_meeting_spec.rb +0 -48
  94. data/spec/dummy/spec/models/time_slot_spec.rb +0 -38
  95. data/spec/dummy/spec/models/user_meeting_spec.rb +0 -34
  96. data/spec/dummy/spec/models/user_spec.rb +0 -9
  97. data/spec/dummy/spec/overlap_validator_spec.rb +0 -32
  98. data/spec/spec_helper.rb +0 -58
  99. data/validates_overlap.gemspec +0 -30
@@ -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
- })();
File without changes
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
- require 'rails/commands'
@@ -1,7 +0,0 @@
1
- FactoryGirl.define do
2
- factory :active_meeting do |u|
3
- u.starts_at '2011-01-05'.to_date
4
- u.ends_at '2011-01-08'.to_date
5
- u.is_active true
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- FactoryGirl.define do
2
- factory :document_with_enum do |d|
3
- d.valid_from '2011-01-05'.to_date
4
- d.valid_until '2011-01-08'.to_date
5
- d.kind :draft
6
- end
7
- end
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- factory :end_overlap_meeting do |u|
3
- u.starts_at '2011-01-05'.to_date
4
- u.ends_at '2011-01-08'.to_date
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- factory :meeting do |u|
3
- u.starts_at '2011-01-05'.to_date
4
- u.ends_at '2011-01-08'.to_date
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- factory :position do |u|
3
- u.association(:user, factory: :user)
4
- u.association(:time_slot, factory: :time_slot)
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- factory :secure_meeting do |u|
3
- u.starts_at '2010-11-05'.to_date
4
- u.ends_at '2010-11-08'.to_date
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- factory :shift do |u|
3
- u.starts_at '2011-01-05'.to_date
4
- u.ends_at '2011-01-08'.to_date
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- factory :start_end_overlap_meeting do |u|
3
- u.starts_at '2011-01-05'.to_date
4
- u.ends_at '2011-01-08'.to_date
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- factory :start_overlap_meeting do |u|
3
- u.starts_at '2011-01-05'.to_date
4
- u.ends_at '2011-01-08'.to_date
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- factory :time_slot do |u|
3
- u.starts_at '2011-01-05'.to_date
4
- u.ends_at '2011-01-08'.to_date
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- FactoryGirl.define do
2
- factory :user do |u|
3
- u.name 'John'
4
- end
5
- end
@@ -1,13 +0,0 @@
1
- FactoryGirl.define do
2
- factory :johns_meeting, class: UserMeeting do |u|
3
- u.starts_at '2011-01-05'.to_date
4
- u.ends_at '2011-01-08'.to_date
5
- u.user_id 1
6
- end
7
-
8
- factory :peters_meeting, class: UserMeeting do |u|
9
- u.starts_at '2011-01-05'.to_date
10
- u.ends_at '2011-01-08'.to_date
11
- u.user_id 2
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../../spec_helper"
2
-
3
- describe ActiveMeeting do
4
- context 'scoping' do
5
- it 'should apply scope' do
6
- expect(ActiveMeeting).to receive(:active).and_call_original
7
- active_meeting = ActiveMeeting.new
8
- expect(active_meeting).to be_valid
9
- end
10
- end
11
- end
@@ -1,53 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../../spec_helper"
2
-
3
- describe DocumentWithEnum do
4
- context '2 overlapping documents with same kind' do
5
- it 'are invalid' do
6
-
7
- document_1 = FactoryGirl.create(
8
- :document_with_enum,
9
- kind: :draft,
10
- valid_from: '2011-01-05'.to_date,
11
- valid_until: '2011-01-08'.to_date
12
- )
13
-
14
- document_2 = FactoryGirl.build(
15
- :document_with_enum,
16
- kind: :draft,
17
- valid_from: '2011-01-06'.to_date,
18
- valid_until: '2011-01-07'.to_date
19
- )
20
-
21
- expect(document_2).not_to be_valid
22
- expect(document_2.errors[:valid_from]).to eq ["overlaps with another record"]
23
- end
24
- end
25
-
26
- context '2 overlapping documents with different kind' do
27
- it 'are valid' do
28
- document_1 = FactoryGirl.create(
29
- :document_with_enum,
30
- kind: :draft,
31
- valid_from: '2011-01-05'.to_date,
32
- valid_until: '2011-01-08'.to_date
33
- )
34
-
35
- document_2 = FactoryGirl.build(
36
- :document_with_enum,
37
- kind: :contract,
38
- valid_from: '2011-01-06'.to_date,
39
- valid_until: '2011-01-07'.to_date
40
- )
41
-
42
- expect(document_2).to be_valid
43
- end
44
- end
45
-
46
- describe '#kind' do
47
- it 'save and read attribute properly' do
48
- docuemnt = FactoryGirl.create(:document_with_enum, kind: :contract)
49
- docuemnt.reload
50
- expect(docuemnt.kind.to_s).to eq "contract"
51
- end
52
- end
53
- end
@@ -1,48 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../../spec_helper"
2
-
3
- describe EndOverlapMeeting do
4
- it 'create meeting' do
5
- expect do
6
- FactoryGirl.create(:end_overlap_meeting)
7
- end.to change(EndOverlapMeeting, :count).by(1)
8
- end
9
-
10
- context 'Validation with exclude edges ends_at' do
11
- before do
12
- FactoryGirl.create(:end_overlap_meeting)
13
- end
14
-
15
- @valid_times = {
16
- 'starts at time of end and ends after' => ['2011-01-08'.to_date, '2011-01-19'.to_date]
17
- }
18
-
19
- @not_valid_times = {
20
- 'has same starts_at and ends_at' => ['2011-01-05'.to_date, '2011-01-08'.to_date],
21
- 'starts before starts_at and ends after ends_at' => ['2011-01-04'.to_date, '2011-01-09'.to_date],
22
- 'starts before starts_at and ends inside' => ['2011-01-04'.to_date, '2011-01-06'.to_date],
23
- 'starts inside and ends after ends_at' => ['2011-01-06'.to_date, '2011-01-09'.to_date],
24
- 'starts inside and ends inside' => ['2011-01-06'.to_date, '2011-01-07'.to_date],
25
- 'starts at same time and ends inside' => ['2011-01-05'.to_date, '2011-01-07'.to_date],
26
- 'starts inside and ends at same time' => ['2011-01-06'.to_date, '2011-01-08'.to_date],
27
- 'starts before and ends at time of start' => ['2011-01-03'.to_date, '2011-01-05'.to_date]
28
- }
29
-
30
- @not_valid_times.each do |description, time_range|
31
- it "is not valid if exists meeting which #{description}" do
32
- meeting = FactoryGirl.build(:end_overlap_meeting, starts_at: time_range.first, ends_at: time_range.last)
33
- expect(meeting).not_to be_valid
34
- expect(meeting.errors[:starts_at]).not_to be_empty
35
- expect(meeting.errors[:ends_at]).to be_empty
36
- end
37
- end
38
-
39
- @valid_times.each do |description, time_range|
40
- it "is valid if exists meeting which #{description}" do
41
- meeting = FactoryGirl.build(:end_overlap_meeting, starts_at: time_range.first, ends_at: time_range.last)
42
- expect(meeting).to be_valid
43
- expect(meeting.errors[:starts_at]).to be_empty
44
- expect(meeting.errors[:ends_at]).to be_empty
45
- end
46
- end
47
- end
48
- end
@@ -1,68 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../../spec_helper"
2
-
3
- describe Meeting do
4
- context 'Validation' do
5
- it 'create meeting' do
6
- expect do
7
- FactoryGirl.create(:meeting)
8
- end.to change(Meeting, :count).by(1)
9
- end
10
-
11
- context 'simple validation' do
12
- let!(:existing_meeting) { FactoryGirl.create(:meeting) }
13
-
14
- OVERLAP_TIME_RANGES.each do |description, time_range|
15
- it "is not valid if exists meeting which #{description}" do
16
- meeting = FactoryGirl.build(:meeting, starts_at: time_range.first, ends_at: time_range.last)
17
- expect(meeting).not_to be_valid
18
- expect(meeting.errors[:starts_at]).not_to be_empty
19
- expect(meeting.errors[:ends_at]).to be_empty
20
- end
21
- end
22
-
23
- it 'validate object which has not got overlap' do
24
- meeting = FactoryGirl.build(:meeting, starts_at: '2011-01-09'.to_date, ends_at: '2011-01-11'.to_date)
25
- expect(meeting).to be_valid
26
- expect(meeting.errors[:starts_at]).to be_empty
27
- expect(meeting.errors[:ends_at]).to be_empty
28
-
29
- meeting = FactoryGirl.build(:meeting, starts_at: '2011-01-01'.to_date, ends_at: '2011-01-02'.to_date)
30
- expect(meeting).to be_valid
31
- expect(meeting.errors[:starts_at]).to be_empty
32
- expect(meeting.errors[:ends_at]).to be_empty
33
- end
34
-
35
- describe '@overlapped_records' do
36
- it 'store the overlapped records' do
37
- meeting = FactoryGirl.build(:meeting, starts_at: '2011-01-05'.to_date, ends_at: '2011-01-08'.to_date)
38
- expect(meeting).not_to be_valid
39
- expect(meeting.instance_variable_get(:@overlapped_records)).to eq [existing_meeting]
40
- end
41
- end
42
- end
43
-
44
-
45
- context 'Validation of endless objects' do
46
- xit 'with overlap object' do
47
- FactoryGirl.create(:meeting)
48
- meeting = FactoryGirl.build(:meeting, starts_at: '2011-01-05'.to_date, ends_at: '2011-01-08'.to_date)
49
- expect(meeting).not_to be_valid
50
- meeting = FactoryGirl.build(:meeting, starts_at: '2012-01-05'.to_date, ends_at: '2012-01-08'.to_date)
51
- expect(meeting).not_to be_valid
52
- meeting = FactoryGirl.build(:meeting, starts_at: '2010-01-05'.to_date, ends_at: '2010-01-08'.to_date)
53
- expect(meeting).to be_valid
54
- end
55
-
56
- it 'with another endless object' do
57
- FactoryGirl.create(:meeting)
58
-
59
- meeting = FactoryGirl.build(:meeting, starts_at: '2010-01-05'.to_date, ends_at: nil)
60
- expect(meeting).not_to be_valid
61
- meeting = FactoryGirl.build(:meeting, starts_at: nil, ends_at: '2010-01-05'.to_date)
62
- expect(meeting).to be_valid
63
- meeting = FactoryGirl.build(:meeting, starts_at: nil, ends_at: nil)
64
- expect(meeting).not_to be_valid
65
- end
66
- end
67
- end
68
- end
@@ -1,31 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../../spec_helper"
2
-
3
- describe Position do
4
- it 'create position' do
5
- expect do
6
- FactoryGirl.create(:position)
7
- end.to change(Position, :count).by(1)
8
- end
9
-
10
- context 'Validation with scope and association' do
11
- it 'is not valid if exists time slot which have position with same person' do
12
- time_slot1 = FactoryGirl.create(:time_slot, starts_at: '2012-10-11'.to_date, ends_at: '2012-10-13'.to_date)
13
- time_slot2 = FactoryGirl.create(:time_slot, starts_at: '2012-10-12'.to_date, ends_at: '2012-10-13'.to_date)
14
- user = FactoryGirl.create(:user)
15
- position1 = FactoryGirl.create(:position, time_slot: time_slot1, user: user)
16
- position2 = FactoryGirl.build(:position, time_slot: time_slot2, user: user)
17
- expect(position2).not_to be_valid
18
- expect(position2.errors[:base]).not_to be_empty
19
- end
20
-
21
- it 'is be valid if exists time slot which have position with same person' do
22
- time_slot1 = FactoryGirl.create(:time_slot, starts_at: '2012-10-11'.to_date, ends_at: '2012-10-13'.to_date)
23
- time_slot2 = FactoryGirl.create(:time_slot, starts_at: '2012-10-14'.to_date, ends_at: '2012-10-15'.to_date)
24
- user = FactoryGirl.create(:user)
25
- position1 = FactoryGirl.create(:position, time_slot: time_slot1, user: user)
26
- position2 = FactoryGirl.build(:position, time_slot: time_slot2, user: user)
27
- expect(position2).to be_valid
28
- expect(position2.errors[:base]).to be_empty
29
- end
30
- end
31
- end
@@ -1,14 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../../spec_helper"
2
-
3
- describe SecureMeeting do
4
- context 'A model with a UUID as a primary key' do
5
- it 'updates the relevant record' do
6
- securemeeting = FactoryGirl.create(:secure_meeting)
7
- securemeeting.starts_at = '2012-01-05'.to_date
8
- securemeeting.ends_at = '2012-02-05'.to_date
9
- expect(securemeeting).to be_valid
10
- expect(securemeeting.errors[:starts_at]).to be_empty
11
- expect(securemeeting.errors[:ends_at]).to be_empty
12
- end
13
- end
14
- end
@@ -1,41 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../../spec_helper"
2
-
3
- describe Meeting do
4
- context 'Validation' do
5
- it 'create meeting' do
6
- expect do
7
- FactoryGirl.create(:shift)
8
- end.to change(Shift, :count).by(1)
9
- end
10
-
11
- context 'validation with shift configuration' do
12
- before do
13
- FactoryGirl.create(:shift)
14
- end
15
-
16
- it 'is not valid if exists shift within wider range' do
17
- shift = FactoryGirl.build(:shift, starts_at: '2011-01-09'.to_date, ends_at: '2011-01-11'.to_date)
18
- expect(shift).not_to be_valid
19
- expect(shift.errors[:starts_at]).not_to be_empty
20
- expect(shift.errors[:ends_at]).to be_empty
21
-
22
- shift = FactoryGirl.build(:shift, starts_at: '2011-01-01'.to_date, ends_at: '2011-01-04'.to_date)
23
- expect(shift).not_to be_valid
24
- expect(shift.errors[:starts_at]).not_to be_empty
25
- expect(shift.errors[:ends_at]).to be_empty
26
- end
27
-
28
- it ' validate object which has not got overlap' do
29
- shift = FactoryGirl.build(:shift, starts_at: '2011-01-10'.to_date, ends_at: '2011-01-11'.to_date)
30
- expect(shift).to be_valid
31
- expect(shift.errors[:starts_at]).to be_empty
32
- expect(shift.errors[:ends_at]).to be_empty
33
-
34
- shift = FactoryGirl.build(:shift, starts_at: '2011-01-01'.to_date, ends_at: '2011-01-02'.to_date)
35
- expect(shift).to be_valid
36
- expect(shift.errors[:starts_at]).to be_empty
37
- expect(shift.errors[:ends_at]).to be_empty
38
- end
39
- end
40
- end
41
- end
@@ -1,48 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../../spec_helper"
2
-
3
- describe StartEndOverlapMeeting do
4
- it 'create meeting' do
5
- expect do
6
- FactoryGirl.create(:start_end_overlap_meeting)
7
- end.to change(StartEndOverlapMeeting, :count).by(1)
8
- end
9
-
10
- context 'Validation with exclude edges starts_at, ends_at' do
11
- before do
12
- FactoryGirl.create(:start_end_overlap_meeting)
13
- end
14
-
15
- @valid_times = {
16
- 'starts before and ends at time of start' => ['2011-01-03'.to_date, '2011-01-05'.to_date],
17
- 'starts at time of end and ends after' => ['2011-01-08'.to_date, '2011-01-19'.to_date]
18
- }
19
-
20
- @not_valid_times = {
21
- 'has same starts_at and ends_at' => ['2011-01-05'.to_date, '2011-01-08'.to_date],
22
- 'starts before starts_at and ends after ends_at' => ['2011-01-04'.to_date, '2011-01-09'.to_date],
23
- 'starts before starts_at and ends inside' => ['2011-01-04'.to_date, '2011-01-06'.to_date],
24
- 'starts inside and ends after ends_at' => ['2011-01-06'.to_date, '2011-01-09'.to_date],
25
- 'starts inside and ends inside' => ['2011-01-06'.to_date, '2011-01-07'.to_date],
26
- 'starts at same time and ends inside' => ['2011-01-05'.to_date, '2011-01-07'.to_date],
27
- 'starts inside and ends at same time' => ['2011-01-06'.to_date, '2011-01-08'.to_date]
28
- }
29
-
30
- @not_valid_times.each do |description, time_range|
31
- it "is not valid if exists meeting which #{description}" do
32
- meeting = FactoryGirl.build(:start_end_overlap_meeting, starts_at: time_range.first, ends_at: time_range.last)
33
- expect(meeting).not_to be_valid
34
- expect(meeting.errors[:starts_at]).not_to be_empty
35
- expect(meeting.errors[:ends_at]).to be_empty
36
- end
37
- end
38
-
39
- @valid_times.each do |description, time_range|
40
- it "is valid if exists meeting which #{description}" do
41
- meeting = FactoryGirl.build(:start_end_overlap_meeting, starts_at: time_range.first, ends_at: time_range.last)
42
- expect(meeting).to be_valid
43
- expect(meeting.errors[:starts_at]).to be_empty
44
- expect(meeting.errors[:ends_at]).to be_empty
45
- end
46
- end
47
- end
48
- end