From 26c97844129a54015a45625fae987bdf3fb4670b Mon Sep 17 00:00:00 2001 From: Robin Bortlik Date: Fri, 15 Nov 2019 08:25:20 +0100 Subject: [PATCH] Rails 6 only support - supporting multiple versions of rails required some hacks especially in the tests. As I do not expect any new features to be implemented, I will rather avoid additional hacks and just update the code to be fully working on newest version of rails. --- .travis.yml | 10 +++------- Gemfile.rails30 | 5 ----- Gemfile.rails32 | 5 ----- Gemfile.rails40 | 5 ----- Gemfile.rails41 | 5 ----- Gemfile.rails42 | 5 ----- Gemfile.rails50 => Gemfile.rails60 | 2 +- README.md | 19 ++----------------- VERSION | 2 +- spec/dummy/app/models/position.rb | 2 +- spec/dummy/app/models/time_slot.rb | 2 +- .../migrate/20110406082020_create_meetings.rb | 2 +- .../db/migrate/20110406082053_create_users.rb | 2 +- .../20110407060725_create_user_meetings.rb | 2 +- ...20509130956_create_end_overlap_meetings.rb | 2 +- ...509131012_create_start_overlap_meetings.rb | 2 +- ...31032_create_start_end_overlap_meetings.rb | 2 +- .../20121207162212_create_time_slot.rb | 2 +- .../20130826155107_create_active_meetings.rb | 2 +- .../20150707155107_create_secure_meetings.rb | 2 +- .../migrate/20151203153132_create_shifts.rb | 2 +- .../20170102162952_add_documents_with_enum.rb | 2 +- spec/spec_helper.rb | 4 +++- validates_overlap.gemspec | 9 ++++----- 24 files changed, 27 insertions(+), 70 deletions(-) delete mode 100644 Gemfile.rails30 delete mode 100644 Gemfile.rails32 delete mode 100644 Gemfile.rails40 delete mode 100644 Gemfile.rails41 delete mode 100644 Gemfile.rails42 rename Gemfile.rails50 => Gemfile.rails60 (64%) diff --git a/.travis.yml b/.travis.yml index 43972ac..af02776 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,6 @@ language: ruby rvm: - - 2.2.2 + - 2.5.0 gemfile: - - Gemfile.rails30 - - Gemfile.rails32 - - Gemfile.rails40 - - Gemfile.rails41 - - Gemfile.rails42 - - Gemfile.rails50 + - Gemfile.rails60 +script: bundle exec rspec diff --git a/Gemfile.rails30 b/Gemfile.rails30 deleted file mode 100644 index f1e5172..0000000 --- a/Gemfile.rails30 +++ /dev/null @@ -1,5 +0,0 @@ -source "https://rubygems.org" - -gemspec - -gem 'rails', '~> 3.0.0' \ No newline at end of file diff --git a/Gemfile.rails32 b/Gemfile.rails32 deleted file mode 100644 index 1df150e..0000000 --- a/Gemfile.rails32 +++ /dev/null @@ -1,5 +0,0 @@ -source "https://rubygems.org" - -gemspec - -gem 'rails', '~> 3.2.0' diff --git a/Gemfile.rails40 b/Gemfile.rails40 deleted file mode 100644 index 1cf271e..0000000 --- a/Gemfile.rails40 +++ /dev/null @@ -1,5 +0,0 @@ -source "https://rubygems.org" - -gemspec - -gem 'rails', '~> 4.0.0' diff --git a/Gemfile.rails41 b/Gemfile.rails41 deleted file mode 100644 index 919f386..0000000 --- a/Gemfile.rails41 +++ /dev/null @@ -1,5 +0,0 @@ -source "https://rubygems.org" - -gemspec - -gem 'rails', '~> 4.1.0.rc1' diff --git a/Gemfile.rails42 b/Gemfile.rails42 deleted file mode 100644 index 29db7c7..0000000 --- a/Gemfile.rails42 +++ /dev/null @@ -1,5 +0,0 @@ -source "https://rubygems.org" - -gemspec - -gem 'rails', '~> 4.2.0.beta4' diff --git a/Gemfile.rails50 b/Gemfile.rails60 similarity index 64% rename from Gemfile.rails50 rename to Gemfile.rails60 index aae1a1a..d9784c9 100644 --- a/Gemfile.rails50 +++ b/Gemfile.rails60 @@ -2,4 +2,4 @@ source "https://rubygems.org" gemspec -gem 'rails', '~> 5.0' +gem 'rails', '~> 6.0' diff --git a/README.md b/README.md index 53501d0..6d4fc36 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This project rocks and uses MIT-LICENSE. -#### This gem is compatible with Rails 3, 4, 5. +#### This gem is compatible with Rails 6. If you are looking for version compatible with Rails 3,4,5 please use version 0.8.6 . #### When this gem should be helpful for you? Ideal solution for booking applications where you want to make sure, that one place can be booked only once in specific time period. @@ -62,7 +62,7 @@ class Position < ActiveRecord::Base belongs_to :user validates "time_slots.starts_at", "time_slots.ends_at", :overlap => { - :query_options => {:includes => :time_slot}, + :query_options => {:joins => :time_slot}, :scope => { "positions.user_id" => proc{|position| position.user_id} } } end @@ -90,18 +90,3 @@ class ActiveMeeting < ActiveRecord::Base end ``` - -## Rails 4.1 update - -If you just upgraded your application to rails 4.1 you can discover some issue with custom scopes. In older versions we suggest to use definition like - -```ruby - {:overlap => {:query_options => {:active => true}}} -``` - -but this code is not longer working. Currently please change your code to - -```ruby - {:overlap => {:query_options => {:active => nil}}} -``` -Thanks @supertinou for discovering and fix of this bug. diff --git a/VERSION b/VERSION index 7fc2521..3eefcb9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.8.6 +1.0.0 diff --git a/spec/dummy/app/models/position.rb b/spec/dummy/app/models/position.rb index 9163a31..b4b085d 100644 --- a/spec/dummy/app/models/position.rb +++ b/spec/dummy/app/models/position.rb @@ -3,7 +3,7 @@ class Position < ActiveRecord::Base belongs_to :user validates :"time_slots.starts_at", :"time_slots.ends_at", overlap: { - query_options: { includes: :time_slot }, + query_options: { joins: :time_slot }, scope: { 'positions.user_id' => proc { |position| position.user_id } } } end diff --git a/spec/dummy/app/models/time_slot.rb b/spec/dummy/app/models/time_slot.rb index e9658ef..c383464 100644 --- a/spec/dummy/app/models/time_slot.rb +++ b/spec/dummy/app/models/time_slot.rb @@ -2,7 +2,7 @@ class TimeSlot < ActiveRecord::Base has_many :positions validates :"time_slots.starts_at", :"time_slots.ends_at", overlap: { - query_options: { includes: :positions }, + query_options: { joins: :positions }, scope: { 'positions.user_id' => proc { |time_slot| time_slot.positions.map(&:user_id) } } } end diff --git a/spec/dummy/db/migrate/20110406082020_create_meetings.rb b/spec/dummy/db/migrate/20110406082020_create_meetings.rb index 00fa801..ae73e4c 100644 --- a/spec/dummy/db/migrate/20110406082020_create_meetings.rb +++ b/spec/dummy/db/migrate/20110406082020_create_meetings.rb @@ -1,4 +1,4 @@ -class CreateMeetings < ActiveRecord::Migration +class CreateMeetings < ActiveRecord::Migration[6.0] def self.up create_table :meetings do |t| t.date :starts_at diff --git a/spec/dummy/db/migrate/20110406082053_create_users.rb b/spec/dummy/db/migrate/20110406082053_create_users.rb index d3fe73e..2dae541 100644 --- a/spec/dummy/db/migrate/20110406082053_create_users.rb +++ b/spec/dummy/db/migrate/20110406082053_create_users.rb @@ -1,4 +1,4 @@ -class CreateUsers < ActiveRecord::Migration +class CreateUsers < ActiveRecord::Migration[6.0] def self.up create_table :users do |t| t.string :name diff --git a/spec/dummy/db/migrate/20110407060725_create_user_meetings.rb b/spec/dummy/db/migrate/20110407060725_create_user_meetings.rb index 94fe623..ce18593 100644 --- a/spec/dummy/db/migrate/20110407060725_create_user_meetings.rb +++ b/spec/dummy/db/migrate/20110407060725_create_user_meetings.rb @@ -1,4 +1,4 @@ -class CreateUserMeetings < ActiveRecord::Migration +class CreateUserMeetings < ActiveRecord::Migration[6.0] def self.up create_table :user_meetings do |t| t.integer :user_id diff --git a/spec/dummy/db/migrate/20120509130956_create_end_overlap_meetings.rb b/spec/dummy/db/migrate/20120509130956_create_end_overlap_meetings.rb index c4db711..e818b57 100644 --- a/spec/dummy/db/migrate/20120509130956_create_end_overlap_meetings.rb +++ b/spec/dummy/db/migrate/20120509130956_create_end_overlap_meetings.rb @@ -1,4 +1,4 @@ -class CreateEndOverlapMeetings < ActiveRecord::Migration +class CreateEndOverlapMeetings < ActiveRecord::Migration[6.0] def self.up create_table :end_overlap_meetings do |t| t.date :starts_at diff --git a/spec/dummy/db/migrate/20120509131012_create_start_overlap_meetings.rb b/spec/dummy/db/migrate/20120509131012_create_start_overlap_meetings.rb index 39c6689..775325a 100644 --- a/spec/dummy/db/migrate/20120509131012_create_start_overlap_meetings.rb +++ b/spec/dummy/db/migrate/20120509131012_create_start_overlap_meetings.rb @@ -1,4 +1,4 @@ -class CreateStartOverlapMeetings < ActiveRecord::Migration +class CreateStartOverlapMeetings < ActiveRecord::Migration[6.0] def self.up create_table :start_overlap_meetings do |t| t.date :starts_at diff --git a/spec/dummy/db/migrate/20120509131032_create_start_end_overlap_meetings.rb b/spec/dummy/db/migrate/20120509131032_create_start_end_overlap_meetings.rb index b74fa5c..377936b 100644 --- a/spec/dummy/db/migrate/20120509131032_create_start_end_overlap_meetings.rb +++ b/spec/dummy/db/migrate/20120509131032_create_start_end_overlap_meetings.rb @@ -1,4 +1,4 @@ -class CreateStartEndOverlapMeetings < ActiveRecord::Migration +class CreateStartEndOverlapMeetings < ActiveRecord::Migration[6.0] def self.up create_table :start_end_overlap_meetings do |t| t.date :starts_at diff --git a/spec/dummy/db/migrate/20121207162212_create_time_slot.rb b/spec/dummy/db/migrate/20121207162212_create_time_slot.rb index 136a32e..e380549 100644 --- a/spec/dummy/db/migrate/20121207162212_create_time_slot.rb +++ b/spec/dummy/db/migrate/20121207162212_create_time_slot.rb @@ -1,4 +1,4 @@ -class CreateTimeSlot < ActiveRecord::Migration +class CreateTimeSlot < ActiveRecord::Migration[6.0] def self.up create_table :time_slots do |t| t.date :starts_at diff --git a/spec/dummy/db/migrate/20130826155107_create_active_meetings.rb b/spec/dummy/db/migrate/20130826155107_create_active_meetings.rb index a05639c..c2f4b77 100644 --- a/spec/dummy/db/migrate/20130826155107_create_active_meetings.rb +++ b/spec/dummy/db/migrate/20130826155107_create_active_meetings.rb @@ -1,4 +1,4 @@ -class CreateActiveMeetings < ActiveRecord::Migration +class CreateActiveMeetings < ActiveRecord::Migration[6.0] def self.up create_table :active_meetings do |t| t.date :starts_at diff --git a/spec/dummy/db/migrate/20150707155107_create_secure_meetings.rb b/spec/dummy/db/migrate/20150707155107_create_secure_meetings.rb index 33e6ae5..8597f72 100644 --- a/spec/dummy/db/migrate/20150707155107_create_secure_meetings.rb +++ b/spec/dummy/db/migrate/20150707155107_create_secure_meetings.rb @@ -1,4 +1,4 @@ -class CreateSecureMeetings < ActiveRecord::Migration +class CreateSecureMeetings < ActiveRecord::Migration[6.0] def self.up create_table :secure_meetings, id: false do |t| t.primary_key :id diff --git a/spec/dummy/db/migrate/20151203153132_create_shifts.rb b/spec/dummy/db/migrate/20151203153132_create_shifts.rb index 8bf951b..3e316a7 100644 --- a/spec/dummy/db/migrate/20151203153132_create_shifts.rb +++ b/spec/dummy/db/migrate/20151203153132_create_shifts.rb @@ -1,4 +1,4 @@ -class CreateShifts < ActiveRecord::Migration +class CreateShifts < ActiveRecord::Migration[6.0] def self.up create_table :shifts do |t| t.date :starts_at diff --git a/spec/dummy/db/migrate/20170102162952_add_documents_with_enum.rb b/spec/dummy/db/migrate/20170102162952_add_documents_with_enum.rb index daf4606..4cea0ac 100644 --- a/spec/dummy/db/migrate/20170102162952_add_documents_with_enum.rb +++ b/spec/dummy/db/migrate/20170102162952_add_documents_with_enum.rb @@ -1,4 +1,4 @@ -class AddDocumentsWithEnum < ActiveRecord::Migration +class AddDocumentsWithEnum < ActiveRecord::Migration[6.0] def self.up create_table :documents_with_enum do |t| t.date :valid_from diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ae0e81d..50649b8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,7 +15,7 @@ Rails.backtrace_cleaner.remove_silencers! # Run any available migration -ActiveRecord::Migrator.migrate File.expand_path('../dummy/db/migrate/', __FILE__) +ActiveRecord::MigrationContext.new(File.expand_path('../dummy/db/migrate/', __FILE__), ActiveRecord::SchemaMigration).migrate # Load support files FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), '/dummy/spec/factories') @@ -43,6 +43,8 @@ end end + + OVERLAP_TIME_RANGES = { 'has same starts_at and ends_at' => ['2011-01-05'.to_date, '2011-01-08'.to_date], 'starts before starts_at and ends after ends_at' => ['2011-01-04'.to_date, '2011-01-09'.to_date], diff --git a/validates_overlap.gemspec b/validates_overlap.gemspec index 88bc4d5..37b1b17 100644 --- a/validates_overlap.gemspec +++ b/validates_overlap.gemspec @@ -18,14 +18,13 @@ Gem::Specification.new do |s| s.licenses = ['MIT'] s.require_paths = ['lib'] s.summary = 'This gem helps validate records with time overlap.' - s.add_dependency 'rails', '>= 3.0.0' + s.add_dependency 'rails', '>= 6.0.0' s.add_development_dependency 'sqlite3' - s.add_development_dependency 'rspec-rails', '~>2.12' - s.add_development_dependency 'factory_girl_rails', '~>4.2' - s.add_development_dependency 'bundler', '~>1.2' + s.add_development_dependency 'rspec-rails' + s.add_development_dependency 'factory_girl_rails' + s.add_development_dependency 'bundler' s.add_development_dependency 'pry' s.add_development_dependency 'rb-readline' s.add_development_dependency 'database_cleaner' s.add_development_dependency 'rubocop' - s.add_development_dependency 'test-unit' end