validates_overlap 0.6.0 → 0.7.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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +5 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.rails50 +5 -0
  7. data/README.md +16 -2
  8. data/Rakefile +3 -3
  9. data/VERSION +1 -1
  10. data/lib/validates_overlap/locale/es.yml +4 -0
  11. data/lib/validates_overlap/overlap_validator.rb +42 -38
  12. data/spec/dummy/app/models/active_meeting.rb +2 -2
  13. data/spec/dummy/app/models/end_overlap_meeting.rb +2 -2
  14. data/spec/dummy/app/models/meeting.rb +1 -1
  15. data/spec/dummy/app/models/position.rb +4 -4
  16. data/spec/dummy/app/models/secure_meeting.rb +1 -1
  17. data/spec/dummy/app/models/shift.rb +1 -1
  18. data/spec/dummy/app/models/start_end_overlap_meeting.rb +2 -2
  19. data/spec/dummy/app/models/start_overlap_meeting.rb +1 -1
  20. data/spec/dummy/app/models/time_slot.rb +4 -4
  21. data/spec/dummy/app/models/user_meeting.rb +1 -1
  22. data/spec/dummy/config/application.rb +7 -7
  23. data/spec/dummy/config/boot.rb +1 -1
  24. data/spec/dummy/config/environments/development.rb +1 -2
  25. data/spec/dummy/config/environments/production.rb +1 -1
  26. data/spec/dummy/config/initializers/session_store.rb +1 -1
  27. data/spec/dummy/db/schema.rb +52 -54
  28. data/spec/dummy/spec/factories/position.rb +2 -2
  29. data/spec/dummy/spec/factories/user_meeting.rb +2 -2
  30. data/spec/dummy/spec/models/active_meetings_spec.rb +4 -10
  31. data/spec/dummy/spec/models/end_overlap_meeting_spec.rb +26 -29
  32. data/spec/dummy/spec/models/meeting_spec.rb +51 -47
  33. data/spec/dummy/spec/models/position_spec.rb +18 -28
  34. data/spec/dummy/spec/models/secure_meeting_spec.rb +5 -11
  35. data/spec/dummy/spec/models/shift_spec.rb +32 -33
  36. data/spec/dummy/spec/models/start_end_overlap_meeting_spec.rb +26 -29
  37. data/spec/dummy/spec/models/start_overlap_meeting_spec.rb +26 -29
  38. data/spec/dummy/spec/models/time_slot_spec.rb +21 -31
  39. data/spec/dummy/spec/models/user_meeting_spec.rb +16 -19
  40. data/spec/dummy/spec/models/user_spec.rb +3 -5
  41. data/spec/dummy/spec/overlap_validator_spec.rb +12 -14
  42. data/spec/spec_helper.rb +29 -20
  43. data/validates_overlap.gemspec +19 -16
  44. metadata +48 -2
@@ -2,42 +2,41 @@ require_relative '../../../spec_helper'
2
2
  require_relative '../factories/shift'
3
3
 
4
4
  describe Meeting do
5
-
6
- context "Validation" do
7
- before(:all) do
8
- Shift.delete_all
9
- end
10
-
11
- it "create meeting" do
12
- lambda {
5
+ context 'Validation' do
6
+ it 'create meeting' do
7
+ expect do
13
8
  FactoryGirl.create(:shift)
14
- }.should change(Shift, :count).by(1)
15
- end
16
-
17
- it "is not valid if exists shift within wider range" do
18
- shift = FactoryGirl.build(:shift, :starts_at => "2011-01-09".to_date, :ends_at => "2011-01-11".to_date)
19
- shift.should_not be_valid
20
- shift.errors[:starts_at].should_not be_empty
21
- shift.errors[:ends_at].should be_empty
22
-
23
- shift = FactoryGirl.build(:shift, :starts_at => "2011-01-01".to_date, :ends_at => "2011-01-04".to_date)
24
- shift.should_not be_valid
25
- shift.errors[:starts_at].should_not be_empty
26
- shift.errors[:ends_at].should be_empty
9
+ end.to change(Shift, :count).by(1)
27
10
  end
28
11
 
29
- it " validate object which has not got overlap" do
30
- shift = FactoryGirl.build(:shift, :starts_at => "2011-01-10".to_date, :ends_at => "2011-01-11".to_date)
31
- shift.should be_valid
32
- shift.errors[:starts_at].should be_empty
33
- shift.errors[:ends_at].should be_empty
34
-
35
- shift = FactoryGirl.build(:shift, :starts_at => "2011-01-01".to_date, :ends_at => "2011-01-02".to_date)
36
- shift.should be_valid
37
- shift.errors[:starts_at].should be_empty
38
- shift.errors[:ends_at].should be_empty
12
+ context 'validation with shift configuration' do
13
+ before do
14
+ FactoryGirl.create(:shift)
15
+ end
16
+
17
+ it 'is not valid if exists shift within wider range' do
18
+ shift = FactoryGirl.build(:shift, starts_at: '2011-01-09'.to_date, ends_at: '2011-01-11'.to_date)
19
+ expect(shift).not_to be_valid
20
+ expect(shift.errors[:starts_at]).not_to be_empty
21
+ expect(shift.errors[:ends_at]).to be_empty
22
+
23
+ shift = FactoryGirl.build(:shift, starts_at: '2011-01-01'.to_date, ends_at: '2011-01-04'.to_date)
24
+ expect(shift).not_to be_valid
25
+ expect(shift.errors[:starts_at]).not_to be_empty
26
+ expect(shift.errors[:ends_at]).to be_empty
27
+ end
28
+
29
+ it ' validate object which has not got overlap' do
30
+ shift = FactoryGirl.build(:shift, starts_at: '2011-01-10'.to_date, ends_at: '2011-01-11'.to_date)
31
+ expect(shift).to be_valid
32
+ expect(shift.errors[:starts_at]).to be_empty
33
+ expect(shift.errors[:ends_at]).to be_empty
34
+
35
+ shift = FactoryGirl.build(:shift, starts_at: '2011-01-01'.to_date, ends_at: '2011-01-02'.to_date)
36
+ expect(shift).to be_valid
37
+ expect(shift.errors[:starts_at]).to be_empty
38
+ expect(shift.errors[:ends_at]).to be_empty
39
+ end
39
40
  end
40
-
41
41
  end
42
-
43
42
  end
@@ -2,51 +2,48 @@ require_relative '../../../spec_helper'
2
2
  require_relative '../factories/start_end_overlap_meeting'
3
3
 
4
4
  describe StartEndOverlapMeeting do
5
-
6
- before(:all) do
7
- StartEndOverlapMeeting.delete_all
5
+ it 'create meeting' do
6
+ expect do
7
+ FactoryGirl.create(:start_end_overlap_meeting)
8
+ end.to change(StartEndOverlapMeeting, :count).by(1)
8
9
  end
9
10
 
10
- it "create meeting" do
11
- lambda {
11
+ context 'Validation with exclude edges starts_at, ends_at' do
12
+ before do
12
13
  FactoryGirl.create(:start_end_overlap_meeting)
13
- }.should change(StartEndOverlapMeeting, :count).by(1)
14
- end
14
+ end
15
15
 
16
- context "Validation with exclude edges starts_at, ends_at" do
17
- @valid_times = {
18
- "starts before and ends at time of start" => ['2011-01-03'.to_date, '2011-01-05'.to_date],
19
- "starts at time of end and ends after" => ['2011-01-08'.to_date, '2011-01-19'.to_date]
16
+ @valid_times = {
17
+ 'starts before and ends at time of start' => ['2011-01-03'.to_date, '2011-01-05'.to_date],
18
+ 'starts at time of end and ends after' => ['2011-01-08'.to_date, '2011-01-19'.to_date]
20
19
  }
21
20
 
22
21
  @not_valid_times = {
23
- "has same starts_at and ends_at" => ['2011-01-05'.to_date, '2011-01-08'.to_date],
24
- "starts before starts_at and ends after ends_at" => ['2011-01-04'.to_date, '2011-01-09'.to_date],
25
- "starts before starts_at and ends inside" => ['2011-01-04'.to_date, '2011-01-06'.to_date],
26
- "starts inside and ends after ends_at" => ['2011-01-06'.to_date, '2011-01-09'.to_date],
27
- "starts inside and ends inside" => ['2011-01-06'.to_date, '2011-01-07'.to_date],
28
- "starts at same time and ends inside" => ['2011-01-05'.to_date, '2011-01-07'.to_date],
29
- "starts inside and ends at same time" => ['2011-01-06'.to_date, '2011-01-08'.to_date],
30
- }
22
+ 'has same starts_at and ends_at' => ['2011-01-05'.to_date, '2011-01-08'.to_date],
23
+ 'starts before starts_at and ends after ends_at' => ['2011-01-04'.to_date, '2011-01-09'.to_date],
24
+ 'starts before starts_at and ends inside' => ['2011-01-04'.to_date, '2011-01-06'.to_date],
25
+ 'starts inside and ends after ends_at' => ['2011-01-06'.to_date, '2011-01-09'.to_date],
26
+ 'starts inside and ends inside' => ['2011-01-06'.to_date, '2011-01-07'.to_date],
27
+ 'starts at same time and ends inside' => ['2011-01-05'.to_date, '2011-01-07'.to_date],
28
+ 'starts inside and ends at same time' => ['2011-01-06'.to_date, '2011-01-08'.to_date]
29
+ }
31
30
 
32
31
  @not_valid_times.each do |description, time_range|
33
32
  it "is not valid if exists meeting which #{description}" do
34
- meeting = FactoryGirl.build(:start_end_overlap_meeting, :starts_at => time_range.first, :ends_at => time_range.last)
35
- meeting.should_not be_valid
36
- meeting.errors[:starts_at].should_not be_empty
37
- meeting.errors[:ends_at].should be_empty
33
+ meeting = FactoryGirl.build(:start_end_overlap_meeting, starts_at: time_range.first, ends_at: time_range.last)
34
+ expect(meeting).not_to be_valid
35
+ expect(meeting.errors[:starts_at]).not_to be_empty
36
+ expect(meeting.errors[:ends_at]).to be_empty
38
37
  end
39
38
  end
40
39
 
41
40
  @valid_times.each do |description, time_range|
42
41
  it "is valid if exists meeting which #{description}" do
43
- meeting = FactoryGirl.build(:start_end_overlap_meeting, :starts_at => time_range.first, :ends_at => time_range.last)
44
- meeting.should be_valid
45
- meeting.errors[:starts_at].should be_empty
46
- meeting.errors[:ends_at].should be_empty
42
+ meeting = FactoryGirl.build(:start_end_overlap_meeting, starts_at: time_range.first, ends_at: time_range.last)
43
+ expect(meeting).to be_valid
44
+ expect(meeting.errors[:starts_at]).to be_empty
45
+ expect(meeting.errors[:ends_at]).to be_empty
47
46
  end
48
47
  end
49
-
50
48
  end
51
-
52
49
  end
@@ -2,51 +2,48 @@ require_relative '../../../spec_helper'
2
2
  require_relative '../factories/start_overlap_meeting'
3
3
 
4
4
  describe StartOverlapMeeting do
5
-
6
- before(:all) do
7
- StartOverlapMeeting.delete_all
5
+ it 'create meeting' do
6
+ expect do
7
+ FactoryGirl.create(:start_overlap_meeting)
8
+ end.to change(StartOverlapMeeting, :count).by(1)
8
9
  end
9
10
 
10
- it "create meeting" do
11
- lambda {
11
+ context 'Validation with exclude edge starts_at' do
12
+ before do
12
13
  FactoryGirl.create(:start_overlap_meeting)
13
- }.should change(StartOverlapMeeting, :count).by(1)
14
- end
14
+ end
15
15
 
16
- context "Validation with exclude edge starts_at" do
17
- @valid_times = {
18
- "starts before and ends at time of start" => ['2011-01-03'.to_date, '2011-01-05'.to_date],
16
+ @valid_times = {
17
+ 'starts before and ends at time of start' => ['2011-01-03'.to_date, '2011-01-05'.to_date]
19
18
  }
20
19
 
21
20
  @not_valid_times = {
22
- "has same starts_at and ends_at" => ['2011-01-05'.to_date, '2011-01-08'.to_date],
23
- "starts before starts_at and ends after ends_at" => ['2011-01-04'.to_date, '2011-01-09'.to_date],
24
- "starts before starts_at and ends inside" => ['2011-01-04'.to_date, '2011-01-06'.to_date],
25
- "starts inside and ends after ends_at" => ['2011-01-06'.to_date, '2011-01-09'.to_date],
26
- "starts inside and ends inside" => ['2011-01-06'.to_date, '2011-01-07'.to_date],
27
- "starts at same time and ends inside" => ['2011-01-05'.to_date, '2011-01-07'.to_date],
28
- "starts inside and ends at same time" => ['2011-01-06'.to_date, '2011-01-08'.to_date],
29
- "starts at time of end and ends after" => ['2011-01-08'.to_date, '2011-01-19'.to_date]
30
- }
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
+ 'starts at time of end and ends after' => ['2011-01-08'.to_date, '2011-01-19'.to_date]
29
+ }
31
30
 
32
31
  @not_valid_times.each do |description, time_range|
33
32
  it "is not valid if exists meeting which #{description}" do
34
- meeting = FactoryGirl.build(:start_overlap_meeting, :starts_at => time_range.first, :ends_at => time_range.last)
35
- meeting.should_not be_valid
36
- meeting.errors[:starts_at].should_not be_empty
37
- meeting.errors[:ends_at].should be_empty
33
+ meeting = FactoryGirl.build(:start_overlap_meeting, starts_at: time_range.first, ends_at: time_range.last)
34
+ expect(meeting).not_to be_valid
35
+ expect(meeting.errors[:starts_at]).not_to be_empty
36
+ expect(meeting.errors[:ends_at]).to be_empty
38
37
  end
39
38
  end
40
39
 
41
40
  @valid_times.each do |description, time_range|
42
41
  it "is valid if exists meeting which #{description}" do
43
- meeting = FactoryGirl.build(:start_overlap_meeting, :starts_at => time_range.first, :ends_at => time_range.last)
44
- meeting.should be_valid
45
- meeting.errors[:starts_at].should be_empty
46
- meeting.errors[:ends_at].should be_empty
42
+ meeting = FactoryGirl.build(:start_overlap_meeting, starts_at: time_range.first, ends_at: time_range.last)
43
+ expect(meeting).to be_valid
44
+ expect(meeting.errors[:starts_at]).to be_empty
45
+ expect(meeting.errors[:ends_at]).to be_empty
47
46
  end
48
47
  end
49
-
50
48
  end
51
-
52
49
  end
@@ -4,48 +4,38 @@ require_relative '../factories/time_slot'
4
4
  require_relative '../factories/user'
5
5
 
6
6
  describe TimeSlot do
7
-
8
- before(:all) do
9
- Position.delete_all
10
- TimeSlot.delete_all
11
- User.delete_all
12
- end
13
-
14
- it "create time_slot" do
15
- lambda {
7
+ it 'create time_slot' do
8
+ expect do
16
9
  FactoryGirl.create(:time_slot)
17
- }.should change(TimeSlot, :count).by(1)
10
+ end.to change(TimeSlot, :count).by(1)
18
11
  end
19
12
 
20
- context "Validation with scope and association" do
21
-
22
- it "is not valid if exists time slot which have position with same person" do
23
- time_slot1 = FactoryGirl.create(:time_slot, :starts_at => "2012-10-11".to_date, :ends_at => "2012-10-13".to_date)
24
- time_slot2 = FactoryGirl.create(:time_slot, :starts_at => "2012-10-15".to_date, :ends_at => "2012-10-16".to_date)
13
+ context 'Validation with scope and association' do
14
+ it 'is not valid if exists time slot which have position with same person' do
15
+ time_slot1 = FactoryGirl.create(:time_slot, starts_at: '2012-10-11'.to_date, ends_at: '2012-10-13'.to_date)
16
+ time_slot2 = FactoryGirl.create(:time_slot, starts_at: '2012-10-15'.to_date, ends_at: '2012-10-16'.to_date)
25
17
  user = FactoryGirl.create(:user)
26
18
  user_2 = FactoryGirl.create(:user)
27
- position1 = FactoryGirl.create(:position, :time_slot => time_slot1, :user => user)
28
- position2 = FactoryGirl.create(:position, :time_slot => time_slot2, :user => user)
29
- position3 = FactoryGirl.create(:position, :time_slot => time_slot2, :user => user_2)
19
+ position1 = FactoryGirl.create(:position, time_slot: time_slot1, user: user)
20
+ position2 = FactoryGirl.create(:position, time_slot: time_slot2, user: user)
21
+ position3 = FactoryGirl.create(:position, time_slot: time_slot2, user: user_2)
30
22
  time_slot2.reload
31
- time_slot2.starts_at = "2012-10-12".to_date
32
- time_slot2.should_not be_valid
23
+ time_slot2.starts_at = '2012-10-12'.to_date
24
+ expect(time_slot2).not_to be_valid
33
25
 
34
- time_slot2.errors[:base].should_not be_empty
26
+ expect(time_slot2.errors[:base]).not_to be_empty
35
27
  end
36
28
 
37
- it "is valid if exists time slot which have position with same person" do
38
- time_slot1 = FactoryGirl.create(:time_slot, :starts_at => "2012-10-11".to_date, :ends_at => "2012-10-13".to_date)
39
- time_slot2 = FactoryGirl.create(:time_slot, :starts_at => "2012-10-14".to_date, :ends_at => "2012-10-16".to_date)
29
+ it 'is valid if exists time slot which have position with same person' do
30
+ time_slot1 = FactoryGirl.create(:time_slot, starts_at: '2012-10-11'.to_date, ends_at: '2012-10-13'.to_date)
31
+ time_slot2 = FactoryGirl.create(:time_slot, starts_at: '2012-10-14'.to_date, ends_at: '2012-10-16'.to_date)
40
32
  user = FactoryGirl.create(:user)
41
- position1 = FactoryGirl.create(:position, :time_slot => time_slot1, :user => user)
42
- position2 = FactoryGirl.build(:position, :time_slot => time_slot2, :user => user)
33
+ position1 = FactoryGirl.create(:position, time_slot: time_slot1, user: user)
34
+ position2 = FactoryGirl.build(:position, time_slot: time_slot2, user: user)
43
35
 
44
- time_slot2.starts_at = "2012-10-15".to_date
45
- time_slot2.should be_valid
46
- time_slot2.errors[:base].should be_empty
36
+ time_slot2.starts_at = '2012-10-15'.to_date
37
+ expect(time_slot2).to be_valid
38
+ expect(time_slot2.errors[:base]).to be_empty
47
39
  end
48
-
49
40
  end
50
-
51
41
  end
@@ -2,37 +2,34 @@ require_relative '../../../spec_helper'
2
2
  require_relative '../factories/user_meeting'
3
3
 
4
4
  describe UserMeeting do
5
-
6
- before(:all) do
7
- UserMeeting.delete_all
8
- end
9
-
10
- it "create johns meeting" do
11
- lambda {
5
+ it 'create johns meeting' do
6
+ expect do
12
7
  FactoryGirl.create(:johns_meeting)
13
- }.should change(UserMeeting, :count).by(1)
8
+ end.to change(UserMeeting, :count).by(1)
14
9
  end
15
10
 
16
- context "Validation with scope" do
11
+ context 'Validation with scope' do
12
+ before do
13
+ FactoryGirl.create(:johns_meeting)
14
+ end
17
15
 
18
16
  OVERLAP_TIME_RANGES.each do |description, time_range|
19
17
  it "is not valid if exists johns meeting which #{description}" do
20
- meeting = FactoryGirl.build(:johns_meeting, :starts_at => time_range.first, :ends_at => time_range.last)
21
- meeting.should_not be_valid
22
- meeting.errors[:starts_at].should_not be_empty
23
- meeting.errors[:ends_at].should be_empty
18
+ meeting = FactoryGirl.build(:johns_meeting, starts_at: time_range.first, ends_at: time_range.last)
19
+ expect(UserMeeting.count).to eq 1
20
+ expect(meeting).not_to be_valid
21
+ expect(meeting.errors[:starts_at]).not_to be_empty
22
+ expect(meeting.errors[:ends_at]).to be_empty
24
23
  end
25
24
  end
26
25
 
27
26
  OVERLAP_TIME_RANGES.each do |description, time_range|
28
27
  it "is valid if exists johns meeting which #{description}" do
29
- meeting = FactoryGirl.build(:peters_meeting, :starts_at => time_range.first, :ends_at => time_range.last)
30
- meeting.should be_valid
31
- meeting.errors[:starts_at].should be_empty
32
- meeting.errors[:ends_at].should be_empty
28
+ meeting = FactoryGirl.build(:peters_meeting, starts_at: time_range.first, ends_at: time_range.last)
29
+ expect(meeting).to be_valid
30
+ expect(meeting.errors[:starts_at]).to be_empty
31
+ expect(meeting.errors[:ends_at]).to be_empty
33
32
  end
34
33
  end
35
-
36
34
  end
37
-
38
35
  end
@@ -2,11 +2,9 @@ require_relative '../../../spec_helper'
2
2
  require_relative '../factories/user'
3
3
 
4
4
  describe User do
5
-
6
- it "create user" do
7
- lambda{
5
+ it 'create user' do
6
+ expect do
8
7
  FactoryGirl.create(:user)
9
- }.should change(User, :count).by(1)
8
+ end.to change(User, :count).by(1)
10
9
  end
11
-
12
10
  end
@@ -1,24 +1,22 @@
1
- describe OverlapValidator do
2
-
3
-
4
- context "validation message" do
1
+ require 'spec_helper'
5
2
 
6
- it "should have default message" do
7
- subject = OverlapValidator.new({:attributes => [:starts_at, :ends_at]})
3
+ describe OverlapValidator do
4
+ context 'validation message' do
5
+ it 'should have default message' do
6
+ subject = OverlapValidator.new(attributes: [:starts_at, :ends_at])
8
7
  meeting = Meeting.new
9
- subject.stub(:find_crossed){true}
8
+ expect(subject).to receive(:overlapped_exists?) { true }
10
9
  subject.validate(meeting)
11
- meeting.errors[:starts_at].should eq ["overlaps with another record"]
10
+ expect(meeting.errors[:starts_at]).to eq ['overlaps with another record']
12
11
  end
13
12
 
14
- it "should be possible to configure message" do
15
- subject = OverlapValidator.new({:attributes => [:starts_at, :ends_at]})
13
+ it 'should be possible to configure message' do
14
+ subject = OverlapValidator.new(attributes: [:starts_at, :ends_at])
16
15
  meeting = Meeting.new
17
- subject.stub(:find_crossed){true}
18
- subject.stub(:options){ {:message_title => :optional_key, :message_content => "Message content"} }
16
+ expect(subject).to receive(:overlapped_exists?) { true }
17
+ allow(subject).to receive(:options) { { message_title: :optional_key, message_content: 'Message content' } }
19
18
  subject.validate(meeting)
20
- meeting.errors[:optional_key].should eq ["Message content"]
19
+ expect(meeting.errors[:optional_key]).to eq ['Message content']
21
20
  end
22
-
23
21
  end
24
22
  end
data/spec/spec_helper.rb CHANGED
@@ -1,29 +1,26 @@
1
1
  # Configure Rails Envinronment
2
- ENV["RAILS_ENV"] = "test"
2
+ ENV['RAILS_ENV'] = 'test'
3
3
 
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
- require "rails/test_help"
6
- require "rspec/rails"
7
- require "factory_girl_rails"
4
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
+ require 'rails/test_help'
6
+ require 'rspec/rails'
7
+ require 'factory_girl_rails'
8
+ require 'database_cleaner'
8
9
  require 'pry'
9
10
 
10
-
11
11
  ActionMailer::Base.delivery_method = :test
12
12
  ActionMailer::Base.perform_deliveries = false
13
- ActionMailer::Base.default_url_options[:host] = "test.com"
13
+ ActionMailer::Base.default_url_options[:host] = 'test.com'
14
14
 
15
15
  Rails.backtrace_cleaner.remove_silencers!
16
16
 
17
-
18
17
  # Run any available migration
19
- ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
18
+ ActiveRecord::Migrator.migrate File.expand_path('../dummy/db/migrate/', __FILE__)
20
19
 
21
20
  # Load support files
22
21
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
23
22
 
24
23
  RSpec.configure do |config|
25
-
26
-
27
24
  # Remove this line if you don't want RSpec's should and should_not
28
25
  # methods or matchers
29
26
  require 'rspec/expectations'
@@ -31,16 +28,28 @@ RSpec.configure do |config|
31
28
 
32
29
  # == Mock Framework
33
30
  config.mock_with :rspec
31
+ config.infer_spec_type_from_file_location!
32
+
33
+ config.before(:suite) do
34
+ DatabaseCleaner.strategy = :transaction
35
+ DatabaseCleaner.clean_with(:truncation)
36
+ end
37
+
38
+ config.around(:each) do |example|
39
+ DatabaseCleaner.cleaning do
40
+ example.run
41
+ end
42
+ end
34
43
  end
35
44
 
36
45
  OVERLAP_TIME_RANGES = {
37
- "has same starts_at and ends_at" => ['2011-01-05'.to_date, '2011-01-08'.to_date],
38
- "starts before starts_at and ends after ends_at" => ['2011-01-04'.to_date, '2011-01-09'.to_date],
39
- "starts before starts_at and ends inside" => ['2011-01-04'.to_date, '2011-01-06'.to_date],
40
- "starts inside and ends after ends_at" => ['2011-01-06'.to_date, '2011-01-09'.to_date],
41
- "starts inside and ends inside" => ['2011-01-06'.to_date, '2011-01-07'.to_date],
42
- "starts at same time and ends inside" => ['2011-01-05'.to_date, '2011-01-07'.to_date],
43
- "starts inside and ends at same time" => ['2011-01-06'.to_date, '2011-01-08'.to_date],
44
- "starts before and ends at time of start" => ['2011-01-03'.to_date, '2011-01-05'.to_date],
45
- "starts at time of end and ends after" => ['2011-01-08'.to_date, '2011-01-19'.to_date]
46
+ 'has same starts_at and ends_at' => ['2011-01-05'.to_date, '2011-01-08'.to_date],
47
+ 'starts before starts_at and ends after ends_at' => ['2011-01-04'.to_date, '2011-01-09'.to_date],
48
+ 'starts before starts_at and ends inside' => ['2011-01-04'.to_date, '2011-01-06'.to_date],
49
+ 'starts inside and ends after ends_at' => ['2011-01-06'.to_date, '2011-01-09'.to_date],
50
+ 'starts inside and ends inside' => ['2011-01-06'.to_date, '2011-01-07'.to_date],
51
+ 'starts at same time and ends inside' => ['2011-01-05'.to_date, '2011-01-07'.to_date],
52
+ 'starts inside and ends at same time' => ['2011-01-06'.to_date, '2011-01-08'.to_date],
53
+ 'starts before and ends at time of start' => ['2011-01-03'.to_date, '2011-01-05'.to_date],
54
+ 'starts at time of end and ends after' => ['2011-01-08'.to_date, '2011-01-19'.to_date]
46
55
  }