Sha256: 3ba90df30144446dff27945626496feeaf2d6146f2a12855cf83a4c10504f7d5

Contents?: true

Size: 1.14 KB

Versions: 19

Compression:

Stored size: 1.14 KB

Contents

module AuditedSpecHelpers
  def create_user(attrs = {})
    Models::ActiveRecord::User.create({name: "Brandon", username: "brandon", password: "password", favourite_device: "Android Phone"}.merge(attrs))
  end

  def build_user(attrs = {})
    Models::ActiveRecord::User.new({name: "darth", username: "darth", password: "noooooooo"}.merge(attrs))
  end

  def create_versions(n = 2, attrs = {})
    Models::ActiveRecord::User.create(name: "Foobar 1", **attrs).tap do |u|
      (n - 1).times do |i|
        u.update_attribute :name, "Foobar #{i + 2}"
      end
      u.reload
    end
  end

  def run_migrations(direction, migrations_paths, target_version = nil)
    if rails_below?("5.2.0.rc1")
      ActiveRecord::Migrator.send(direction, migrations_paths, target_version)
    elsif rails_below?("6.0.0.rc1")
      ActiveRecord::MigrationContext.new(migrations_paths).send(direction, target_version)
    else
      ActiveRecord::MigrationContext.new(migrations_paths, ActiveRecord::SchemaMigration).send(direction, target_version)
    end
  end

  def rails_below?(rails_version)
    Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new(rails_version)
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
audited-5.4.2 spec/audited_spec_helpers.rb
audited-5.4.1 spec/audited_spec_helpers.rb
audited-5.4.0 spec/audited_spec_helpers.rb
audited-5.3.3 spec/audited_spec_helpers.rb
audited-5.3.2 spec/audited_spec_helpers.rb
audited-5.3.1 spec/audited_spec_helpers.rb
audited-5.3.0 spec/audited_spec_helpers.rb
audited-5.2.0 spec/audited_spec_helpers.rb
audited-5.1.0 spec/audited_spec_helpers.rb
velocity_audited-6.0.4 spec/audited_spec_helpers.rb
velocity_audited-6.0.3 spec/audited_spec_helpers.rb
velocity_audited-6.0.1 spec/audited_spec_helpers.rb
velocity_audited-5.1.6 spec/audited_spec_helpers.rb
velocity_audited-5.1.5 spec/audited_spec_helpers.rb
velocity_audited-5.1.4 spec/audited_spec_helpers.rb
velocity_audited-5.1.3 spec/audited_spec_helpers.rb
audited-5.0.2 spec/audited_spec_helpers.rb
audited-5.0.1 spec/audited_spec_helpers.rb
audited-5.0.0 spec/audited_spec_helpers.rb