diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..fdf66840 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,31 @@ +name: Tests +on: [push] + +jobs: + ruby: + name: Rspec + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: [2.5, 2.6, 2.7] + activerecord: ["5.0", "5.1", "5.2", "6.0"] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - name: Set ActiveRecord Version + env: + AR_VERSION: ${{ matrix.activerecord }} + run: echo "gem 'activerecord', '~> $AR_VERSION'" >> Gemfile + - name: Install Sqlite + run: sudo apt-get install libsqlite3-dev + - name: Bundle + run: | + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + - name: Tests + run: bundle exec rake spec diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e26f2a0b..00000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -branches: - only: - - master -gemfile: - - gemfiles/activerecord_3_0.gemfile - - gemfiles/activerecord_3_1.gemfile - - gemfiles/activerecord_3_2.gemfile - - gemfiles/activerecord_4_0.gemfile -language: ruby -matrix: - allow_failures: - - rvm: ruby-head - include: - - env: COVERAGE=1 - gemfile: Gemfile - rvm: 2.1.0 -rvm: - - 1.9.3 - - 2.0.0 - - 2.1.0 - - ruby-head -script: bundle exec rspec diff --git a/Gemfile b/Gemfile index 542779e2..4d0c043a 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,8 @@ gemspec group :test do gem 'coveralls', '~> 0.7', :require => false - gem 'rspec', '~> 2.0' + gem 'rspec' + gem 'rspec-its' gem 'sqlite3', '~> 1.0' end diff --git a/README.rdoc b/README.rdoc index 426ea6b8..4d8620ba 100644 --- a/README.rdoc +++ b/README.rdoc @@ -119,7 +119,7 @@ There are a handful of exciting new additions in version 1.0 of vestal_versi @user.update_attribute(:first_name, "Stephen") @user.first_name = "Steve" @user.save - @user.update_attributes(:last_name => "Jobs") + @user.update(:last_name => "Jobs") end @user.version # => 1 @@ -154,12 +154,12 @@ There are a handful of exciting new additions in version 1.0 of vestal_versi * Storing which user is responsible for a revision. Rather than introduce a lot of controller magic to guess what to store, you can simply update an additional attribute on your versioned model: updated_by. - @user.update_attributes(:last_name => "Jobs", :updated_by => "Tyler") + @user.update(:last_name => "Jobs", :updated_by => "Tyler") @user.versions.last.user # => "Tyler" Instead of passing a simple string to the updated_by setter, you can pass a model instance, such as an ActiveRecord user or administrator. The association will be saved polymorphically alongside the version. - @user.update_attributes(:last_name => "Jobs", :updated_by => current_user) + @user.update(:last_name => "Jobs", :updated_by => current_user) @user.versions.last.user # => # * Global configuration. The new vestal_versions Rails generator also writes an initializer with instructions on how to set application-wide options for the versioned method. diff --git a/gemfiles/activerecord_3_0.gemfile b/gemfiles/activerecord_3_0.gemfile deleted file mode 100644 index c1fd6983..00000000 --- a/gemfiles/activerecord_3_0.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -source 'https://rubygems.org' - -gem 'activerecord', '~> 3.0.0' - -gemspec :path => '..' - -group :test do - gem 'rspec', '~> 2.0' - gem 'sqlite3', '~> 1.0' -end diff --git a/gemfiles/activerecord_3_1.gemfile b/gemfiles/activerecord_3_1.gemfile deleted file mode 100644 index c1b35b05..00000000 --- a/gemfiles/activerecord_3_1.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -source 'https://rubygems.org' - -gem 'activerecord', '~> 3.1.0' - -gemspec :path => '..' - -group :test do - gem 'rspec', '~> 2.0' - gem 'sqlite3', '~> 1.0' -end diff --git a/gemfiles/activerecord_3_2.gemfile b/gemfiles/activerecord_3_2.gemfile deleted file mode 100644 index ef52df6c..00000000 --- a/gemfiles/activerecord_3_2.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -source 'https://rubygems.org' - -gem 'activerecord', '~> 3.2.0' - -gemspec :path => '..' - -group :test do - gem 'rspec', '~> 2.0' - gem 'sqlite3', '~> 1.0' -end diff --git a/gemfiles/activerecord_4_0.gemfile b/gemfiles/activerecord_4_0.gemfile deleted file mode 100644 index 5850015f..00000000 --- a/gemfiles/activerecord_4_0.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -source 'https://rubygems.org' - -gem 'activerecord', '~> 4.0.0' - -gemspec :path => '..' - -group :test do - gem 'rspec', '~> 2.0' - gem 'sqlite3', '~> 1.0' -end diff --git a/lib/vestal_versions/changes.rb b/lib/vestal_versions/changes.rb index cc4b9e08..ccc9d54a 100644 --- a/lib/vestal_versions/changes.rb +++ b/lib/vestal_versions/changes.rb @@ -48,7 +48,7 @@ def version_changes # creation. Incremental changes are reset when the record is saved because they represent # a subset of the dirty attribute changes, which are reset upon save. def incremental_version_changes - changes.slice(*versioned_columns) + previous_changes.slice(*versioned_columns) end # Simply resets the cumulative changes after version creation. @@ -118,4 +118,4 @@ def reverse_changes! end end end -end \ No newline at end of file +end diff --git a/lib/vestal_versions/control.rb b/lib/vestal_versions/control.rb index 78e9df58..0e0defc8 100644 --- a/lib/vestal_versions/control.rb +++ b/lib/vestal_versions/control.rb @@ -12,7 +12,7 @@ module Control # Control blocks are called on ActiveRecord::Base instances as to not cause any conflict with # other instances of the versioned class whose behavior could be inadvertently altered within # a control block. - + # The +skip_version+ block simply allows for updates to be made to an instance of a versioned # ActiveRecord model while ignoring all new version creation. The :if and # :unless conditions (if given) will not be evaulated inside a +skip_version+ block. @@ -55,7 +55,7 @@ def skip_version! # user = User.find_by_first_name("Steve") # user.version # => 1 # user.merge_version do - # user.update_attributes(:first_name => "Steven", :last_name => "Tyler") + # user.update(:first_name => "Steven", :last_name => "Tyler") # user.update_attribute(:first_name, "Stephen") # user.update_attribute(:last_name, "Richert") # end @@ -159,7 +159,7 @@ def create_version? def update_version? append_version? end - + module ClassMethods # The +skip_version+ block simply allows for updates to be made to an instance of a versioned # ActiveRecord model while ignoring all new version creation. The :if and diff --git a/lib/vestal_versions/users.rb b/lib/vestal_versions/users.rb index 167c930e..ef8a36b0 100644 --- a/lib/vestal_versions/users.rb +++ b/lib/vestal_versions/users.rb @@ -6,13 +6,13 @@ module Users included do attr_accessor :updated_by - Version.class_eval{ include VersionMethods } + Version.class_eval{ include UserVersionMethods } end # Methods added to versioned ActiveRecord::Base instances to enable versioning with additional # user information. - - + + private # Overrides the +version_attributes+ method to include user information passed into the # parent object, by way of a +updated_by+ attr_accessor. @@ -22,14 +22,19 @@ def version_attributes end # Instance methods added to VestalVersions::Version to accomodate incoming user information. - module VersionMethods + module UserVersionMethods extend ActiveSupport::Concern included do belongs_to :user, :polymorphic => true - alias_method_chain :user, :name - alias_method_chain :user=, :name + # alias_method_chain :user, :name + alias_method :user_without_name, :user + alias_method :user, :user_with_name + + # alias_method_chain :user=, :name + alias_method :user_without_name=, :user= + alias_method :user=, :user_with_name= end # Overrides the +user+ method created by the polymorphic +belongs_to+ user association. If diff --git a/lib/vestal_versions/version_tagging.rb b/lib/vestal_versions/version_tagging.rb index 962d1bd5..382ed4bb 100644 --- a/lib/vestal_versions/version_tagging.rb +++ b/lib/vestal_versions/version_tagging.rb @@ -23,7 +23,7 @@ def tag_version(tag) end # Instance methods included into VestalVersions::Version to enable version tagging. - module VersionMethods + module TaggingVersionMethods extend ActiveSupport::Concern included do @@ -46,6 +46,6 @@ def validate_tags? tagged? && tag != 'deleted' end - Version.class_eval{ include VersionMethods } + Version.class_eval{ include TaggingVersionMethods } end end diff --git a/spec/support/schema.rb b/spec/support/schema.rb index 650f6b3c..7446fda7 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -3,7 +3,7 @@ :database => File.expand_path('../../test.db', __FILE__) ) -class CreateSchema < ActiveRecord::Migration +class CreateSchema < ActiveRecord::Migration[4.2] def self.up create_table :users, :force => true do |t| t.string :first_name diff --git a/spec/vestal_versions/control_spec.rb b/spec/vestal_versions/control_spec.rb index 3ab76554..a8ddf94d 100644 --- a/spec/vestal_versions/control_spec.rb +++ b/spec/vestal_versions/control_spec.rb @@ -95,7 +95,7 @@ user.append_version{ user.update_attribute(:last_name, 'Jobs') } - other_last_version = user.versions(true).last + other_last_version = user.versions.reload.last other_last_version.id.should == original_id other_last_version.attributes.should_not == original_attrs end @@ -110,7 +110,7 @@ user.update_attribute(:first_name, 'Steve') end - other_last_version = user.versions(true).last + other_last_version = user.versions.reload.last other_last_version.id.should == original_id other_last_version.attributes.should_not == original_attrs end diff --git a/spec/vestal_versions/deletion_spec.rb b/spec/vestal_versions/deletion_spec.rb index f9d6fb8c..2ba867a8 100644 --- a/spec/vestal_versions/deletion_spec.rb +++ b/spec/vestal_versions/deletion_spec.rb @@ -60,7 +60,7 @@ it "restores even if the schema has changed" do new_mods = last_version.modifications.merge(:old_column => 'old') - last_version.update_attributes(:modifications => new_mods) + last_version.update(:modifications => new_mods) last_version.restore.should == subject end diff --git a/spec/vestal_versions/reset_spec.rb b/spec/vestal_versions/reset_spec.rb index 04a254e7..62075502 100644 --- a/spec/vestal_versions/reset_spec.rb +++ b/spec/vestal_versions/reset_spec.rb @@ -29,7 +29,7 @@ it 'dissociates all versions after the target' do versions.reverse.each do |version| subject.reset_to!(version) - subject.versions(true).after(version).count.should == 0 + subject.versions.reload.after(version).count.should == 0 end end diff --git a/spec/vestal_versions/reversion_spec.rb b/spec/vestal_versions/reversion_spec.rb index 7ec46bf3..faf9923c 100644 --- a/spec/vestal_versions/reversion_spec.rb +++ b/spec/vestal_versions/reversion_spec.rb @@ -73,7 +73,7 @@ it "does not store the reverted_from for subsequent saves" do subject.revert_to!(1) - subject.update_attributes(:name => 'Bill Gates') + subject.update(:name => 'Bill Gates') subject.versions.last.reverted_from.should be_nil end @@ -88,14 +88,14 @@ subject.revert_to(1) subject.name = "Reverted" subject.save - subject.update_attributes(:name => 'Bill Gates') + subject.update(:name => 'Bill Gates') subject.versions.last.reverted_from.should be_nil end it "clears the reverted_from if the model is reloaded after a revert_to without a save" do subject.revert_to(1) subject.reload - subject.update_attributes(:name => 'Bill Gates') + subject.update(:name => 'Bill Gates') subject.versions.last.reverted_from.should be_nil end diff --git a/spec/vestal_versions/users_spec.rb b/spec/vestal_versions/users_spec.rb index 6af0decb..f5cbebf9 100644 --- a/spec/vestal_versions/users_spec.rb +++ b/spec/vestal_versions/users_spec.rb @@ -5,17 +5,17 @@ let(:user){ User.create(:name => 'Steve Richert') } it 'defaults to nil' do - user.update_attributes(:first_name => 'Stephen') + user.update(:first_name => 'Stephen') user.versions.last.user.should be_nil end it 'accepts and returns an ActiveRecord user' do - user.update_attributes(:first_name => 'Stephen', :updated_by => updated_by) + user.update(:first_name => 'Stephen', :updated_by => updated_by) user.versions.last.user.should == updated_by end it 'accepts and returns a string user name' do - user.update_attributes(:first_name => 'Stephen', :updated_by => updated_by.name) + user.update(:first_name => 'Stephen', :updated_by => updated_by.name) user.versions.last.user.should == updated_by.name end end diff --git a/spec/vestal_versions/version_spec.rb b/spec/vestal_versions/version_spec.rb index 9cb89275..6646b72a 100644 --- a/spec/vestal_versions/version_spec.rb +++ b/spec/vestal_versions/version_spec.rb @@ -40,7 +40,7 @@ version.number.should == 1 version.should be_initial end - + it "sreturn the version number if it is not a revert" do user.version.should == user.versions.last.original_number end @@ -53,9 +53,9 @@ it "return the original version if it is a double revert" do user.revert_to!(2) version = user.version - user.update_attributes(:last_name => 'Gates') + user.update(:last_name => 'Gates') user.revert_to!(version) user.versions.last.original_number.should == 2 end - + end diff --git a/spec/vestal_versions/versions_spec.rb b/spec/vestal_versions/versions_spec.rb index c9db4c24..bf50c917 100644 --- a/spec/vestal_versions/versions_spec.rb +++ b/spec/vestal_versions/versions_spec.rb @@ -125,15 +125,15 @@ it 'provides a version number for any given numeric version value' do times.keys.each do |number| - subject.versions.number_at(number).should be_a(Fixnum) - subject.versions.number_at(number + 0.5).should be_a(Fixnum) + subject.versions.number_at(number).should be_a(Integer) + subject.versions.number_at(number + 0.5).should be_a(Integer) subject.versions.number_at(number).should == subject.versions.number_at(number + 0.5) end end it 'provides a version number for a valid tag' do times.keys.map{|n| [n, n.to_s] }.each do |number, tag| - subject.versions.number_at(tag).should be_a(Fixnum) + subject.versions.number_at(tag).should be_a(Integer) subject.versions.number_at(tag).should == number end end @@ -155,7 +155,7 @@ it "provides a version number for any time after the model's creation" do times.each do |number, time| - subject.versions.number_at(time + 30.minutes).should be_a(Fixnum) + subject.versions.number_at(time + 30.minutes).should be_a(Integer) subject.versions.number_at(time + 30.minutes).should == number end end diff --git a/vestal_versions.gemspec b/vestal_versions.gemspec index ed150d5a..e71078b2 100644 --- a/vestal_versions.gemspec +++ b/vestal_versions.gemspec @@ -1,8 +1,8 @@ # encoding: utf-8 Gem::Specification.new do |gem| - gem.name = 'vestal_versions' - gem.version = '2.0.0' + gem.name = 'houston-vestal_versions' + gem.version = '3.0.0' gem.authors = ['Steve Richert', "James O'Kelly", 'C. Jason Harrelson'] gem.email = ['steve.richert@gmail.com', 'dreamr.okelly@gmail.com', 'jason@lookforwardenterprises.com'] @@ -11,11 +11,11 @@ Gem::Specification.new do |gem| gem.homepage = 'http://github.com/laserlemon/vestal_versions' gem.license = 'MIT' - gem.add_dependency 'activerecord', '>= 3', '< 5' - gem.add_dependency 'activesupport', '>= 3', '< 5' + gem.add_dependency 'activerecord', '>= 5' + gem.add_dependency 'activesupport', '>= 5' - gem.add_development_dependency 'bundler', '~> 1.0' - gem.add_development_dependency 'rake', '~> 10.0' + gem.add_development_dependency 'bundler', '>= 1.0' + gem.add_development_dependency 'rake', '>= 10.0' gem.files = `git ls-files`.split($\) gem.test_files = gem.files.grep(/^spec/)