Sha256: 31bb9a5de50d95c391044851c90208f65484fbf04ec3901e767d5245ff9bf5e7

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

gem 'mongoid'
require 'mongoid'
require 'stringex'
# Reload adapters to make sure ActsAsUrl sees the ORM
Stringex::ActsAsUrl::Adapter.load_available

puts "-------------------------------------------------"
puts "Running ActsAsUrl tests with Mongoid adapter"
puts "-------------------------------------------------"

Mongoid.configure do |config|
  config.connect_to('acts_as_url')
end

class Document
  include Mongoid::Document
  field :title,   type: String
  field :other,   type: String
  field :another, type: String
  field :url,     type: String

  acts_as_url :title
end

begin
  # Let's make sure we can connect to mongodb before we run our tests!
  Mongoid::Sessions.default.databases
rescue Moped::Errors::ConnectionFailure => err
  puts 'Cannot connect to mongodb. Aborting.'
  exit
end

class STIBaseDocument
  include Mongoid::Document
  field :title,   type: String
  field :other,   type: String
  field :another, type: String
  field :url,     type: String
  field :type,    type: String

  # This gets redefined in the only test that uses it but I want to be uniform
  # in setting configuration details in the tests themselves
  acts_as_url :title
end

class STIChildDocument < STIBaseDocument
end

class AnotherSTIChildDocument < STIBaseDocument
end

module AdapterSpecificTestBehaviors
  def setup
    # No setup tasks at present
  end

  def teardown
    [Document, STIBaseDocument].each do |klass|
      klass.delete_all
      # Reset behavior to default
      klass.class_eval do
        acts_as_url :title
      end
    end
  end

  def add_validation_on_document_title
    Document.class_eval do
      validates_presence_of :title
    end
  end

  def remove_validation_on_document_title
    Document.class_eval do
      _validators.delete :title
    end
  end

  def adapter_specific_update(instance, hash)
    instance.send :update!, hash
  end
end

Version data entries

3 entries across 2 versions & 2 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/stringex-2.8.6/test/unit/acts_as_url/adapter/mongoid.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/stringex-2.8.6/test/unit/acts_as_url/adapter/mongoid.rb
stringex-2.8.6 test/unit/acts_as_url/adapter/mongoid.rb