source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/line_item.rb | Ruby | mit | 3,920 | master | 214 | # frozen_string_literal: true
class LineItem
include Mongoid::Document
embedded_in :purchase
belongs_to :product, polymorphic: true
validates :product, presence: true, uniqueness: { scope: :product }
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/catalog.rb | Ruby | mit | 3,920 | master | 789 | # frozen_string_literal: true
class Catalog
include Mongoid::Document
field :array_field, type: Array
field :big_decimal_field, type: BigDecimal
field :boolean_field, type: Boolean
field :date_field, type: Date
field :date_time_field, type: DateTime
field :float_field, type: Float
field :hash_field, t... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/bus.rb | Ruby | mit | 3,920 | master | 222 | # frozen_string_literal: true
class Bus
include Mongoid::Document
field :saturday, type: Mongoid::Boolean, default: false
field :departure_time, type: Time
field :number, type: Integer
embedded_in :circuit
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/even.rb | Ruby | mit | 3,920 | master | 204 | # frozen_string_literal: true
class Even
include Mongoid::Document
field :name
belongs_to :parent, class_name: 'Odd', inverse_of: :evens
has_many :odds, inverse_of: :parent, autosave: true
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/image.rb | Ruby | mit | 3,920 | master | 276 | # frozen_string_literal: true
class Image
attr_reader :name
def initialize(name)
@name = name
end
def self.demongoize(value)
Image.new(value)
end
def mongoize
name
end
def hash_is_hash
{}.is_a?(Hash)
end
end
class Thumbnail < Image
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/shield.rb | Ruby | mit | 3,920 | master | 403 | # frozen_string_literal: true
class Shield
include Mongoid::Document
has_and_belongs_to_many :players
field :after_find_player
field :after_initialize_player
field :after_default_player, default: -> { players.first&._id }
after_find do |doc|
doc.after_find_player = players.first&._id
end
after_... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/player.rb | Ruby | mit | 3,920 | master | 832 | # frozen_string_literal: true
class Player
include Mongoid::Document
field :active, type: Mongoid::Boolean
field :frags, type: Integer
field :deaths, type: Integer
field :impressions, type: Integer, default: 0
field :status
scope :active, -> { where(active: true) } do
def extension
'extension... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/doctor.rb | Ruby | mit | 3,920 | master | 246 | # frozen_string_literal: true
class Doctor < Person
field :specialty, as: :spec
has_and_belongs_to_many :users, validate: false, inverse_of: nil
def specialty=(text)
users.push(User.new)
super
end
end
class Doktor < Person
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/message.rb | Ruby | mit | 3,920 | master | 271 | # frozen_string_literal: true
class Message
include Mongoid::Document
field :body, type: String
field :priority, type: Integer
embedded_in :person
has_and_belongs_to_many :receivers, class_name: 'Person', inverse_of: nil
has_one :post, as: :posteable
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/sandwich.rb | Ruby | mit | 3,920 | master | 244 | # frozen_string_literal: true
class Sandwich
include Mongoid::Document
has_and_belongs_to_many :meats
field :name, type: String
belongs_to :posteable, polymorphic: true
accepts_nested_attributes_for :posteable, autosave: true
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/student.rb | Ruby | mit | 3,920 | master | 255 | # frozen_string_literal: true
class Student
include Mongoid::Document
belongs_to :school
field :name, type: String
field :grade, type: Integer, default: 3
after_destroy do |_doc|
school.after_destroy_triggered = true if school
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/wiki_page.rb | Ruby | mit | 3,920 | master | 569 | # frozen_string_literal: true
class WikiPage
include Mongoid::Document
include Mongoid::Timestamps
field :title, type: String
field :transient_property, type: String
field :author, type: String
field :description, type: String, localize: true
embeds_many :edits, validate: false
# Must have dependent:... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/fruits.rb | Ruby | mit | 3,920 | master | 738 | # frozen_string_literal: true
module Fruits
class Apple
include Mongoid::Document
has_many :bananas, class_name: 'Fruits::Banana'
has_many :fruits_melons, class_name: 'Fruits::Melon'
recursively_embeds_many
end
class Banana
include Mongoid::Document
belongs_to :apple, class_name: 'Frui... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/oscar.rb | Ruby | mit | 3,920 | master | 297 | # frozen_string_literal: true
class Oscar
include Mongoid::Document
field :title, type: String
field :destroy_after_save, type: Mongoid::Boolean, default: false
before_save :complain
def complain
if destroy_after_save?
destroy
else
throw(:abort)
end
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/user.rb | Ruby | mit | 3,920 | master | 621 | # frozen_string_literal: true
class User
include Mongoid::Document
field :name
field :last_login, type: DateTime
field :account_expires, type: Date
has_one :account, foreign_key: :creator_id, validate: false
has_many :posts, foreign_key: :author_id, validate: false
has_many :descriptions
has_one :rol... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/game.rb | Ruby | mit | 3,920 | master | 584 | # frozen_string_literal: true
class Game
include Mongoid::Document
field :high_score, type: Integer, default: 500
field :score, type: Integer, default: 0
field :name
belongs_to :person, index: true, validate: true
belongs_to :parent, class_name: 'Game', foreign_key: 'parent-id'
has_one :video, validate... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/rating.rb | Ruby | mit | 3,920 | master | 276 | # frozen_string_literal: true
class Rating
include Mongoid::Document
field :value, type: Integer
belongs_to :ratable, polymorphic: true
has_many :comments
validates_numericality_of :value, less_than: 100, allow_nil: true
validates :ratable, associated: true
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/child_doc.rb | Ruby | mit | 3,920 | master | 520 | # frozen_string_literal: true
class ChildDoc
include Mongoid::Document
embedded_in :parent_doc
attr_writer :position
after_save :update_position
def position
existing_position = parent_doc.children_order.index(id)
existing_position ? existing_position + 1 : parent_doc.aspects.size
end
def up... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/country_code.rb | Ruby | mit | 3,920 | master | 264 | # frozen_string_literal: true
class CountryCode
include Mongoid::Document
field :_id, type: Integer, overwrite: true, default: -> { code }
field :code, type: Integer
field :iso, as: :iso_alpha2_code
embedded_in :phone_number, class_name: 'Phone'
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/writer.rb | Ruby | mit | 3,920 | master | 234 | # frozen_string_literal: true
class Writer
include Mongoid::Document
field :speed, type: Integer, default: 0
embedded_in :canvas
def write; end
end
require 'support/models/pdf_writer'
require 'support/models/html_writer' |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/appointment.rb | Ruby | mit | 3,920 | master | 256 | # frozen_string_literal: true
class Appointment
include Mongoid::Document
field :active, type: Mongoid::Boolean, default: true
field :timed, type: Mongoid::Boolean, default: true
embedded_in :person
default_scope -> { where(active: true) }
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/parent_doc.rb | Ruby | mit | 3,920 | master | 251 | # frozen_string_literal: true
class ParentDoc
include Mongoid::Document
field :statistic
field :children_order, type: Array, default: [] # hold all the children's id
embeds_many :children, class_name: 'ChildDoc', inverse_of: :parent_doc
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/description.rb | Ruby | mit | 3,920 | master | 235 | # frozen_string_literal: true
class Description
include Mongoid::Document
field :details
belongs_to :user
belongs_to :updater, class_name: 'User'
validates :user, associated: true
validates :details, presence: true
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/customer.rb | Ruby | mit | 3,920 | master | 246 | # frozen_string_literal: true
class Customer
include Mongoid::Document
field :name
embeds_one :home_address, class_name: 'CustomerAddress', as: :addressable
embeds_one :work_address, class_name: 'CustomerAddress', as: :addressable
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/ordered_post.rb | Ruby | mit | 3,920 | master | 251 | # frozen_string_literal: true
class OrderedPost
include Mongoid::Document
field :title, type: String
field :rating, type: Integer
belongs_to :person
after_destroy do
person.title = 'Minus one ordered post.'
person.save!
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/lat_lng.rb | Ruby | mit | 3,920 | master | 339 | # frozen_string_literal: true
class LatLng
attr_accessor :lat, :lng
def self.demongoize(object)
return if object.nil?
LatLng.new(object[1], object[0])
end
def initialize(lat, lng)
@lat, @lng = lat, lng
end
def mongoize
[ lng, lat ]
end
def ==(other)
lat == other.lat && lng == o... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/coding/pull_request.rb | Ruby | mit | 3,920 | master | 212 | # frozen_string_literal: true
module Coding
class PullRequest
include Mongoid::Document
field :title, type: String
has_many :reviews, class_name: 'Publication::Review', as: :reviewable
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/publication/review.rb | Ruby | mit | 3,920 | master | 241 | # frozen_string_literal: true
module Publication
class Review
include Mongoid::Document
field :summary
belongs_to :reviewable, polymorphic: true
belongs_to :reviewer, polymorphic: true
belongs_to :template
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/publication/encyclopedia.rb | Ruby | mit | 3,920 | master | 218 | # frozen_string_literal: true
module Publication
class Encyclopedia
include Mongoid::Document
field :title, type: String
has_many :reviews, class_name: 'Publication::Review', as: :reviewable
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/crypt/models.rb | Ruby | mit | 3,920 | master | 1,224 | module Crypt
class Patient
include Mongoid::Document
encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
field :code, type: String
field :medical_records, type: Array, encrypt: { deterministic: false }
field :blood_type, type: String, encrypt: {
deterministic: false,
key_name_field: :blo... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/shared/time.rb | Ruby | mit | 3,920 | master | 887 | # frozen_string_literal: true
shared_context 'setting ActiveSupport time zone' do
time_zone_override 'Tokyo'
end
shared_examples_for 'mongoizes to AS::TimeWithZone' do
it 'is an AS::TimeWithZone' do
expect(mongoized.class).to eq(ActiveSupport::TimeWithZone)
end
it 'is equal to expected time' do
expec... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/rails/mongoid_spec.rb | Ruby | mit | 3,920 | master | 1,444 | # frozen_string_literal: true
require 'spec_helper'
require 'support/feature_sandbox'
describe 'Rails::Mongoid' do
let(:model_root) do
File.absolute_path(
File.join(
File.dirname(__FILE__),
'../support/models/sandbox'
)
)
end
around do |example|
FeatureSandbox.quarantine... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/rails/controller_extension/controller_runtime_spec.rb | Ruby | mit | 3,920 | master | 3,092 | # frozen_string_literal: true
require 'spec_helper'
require 'mongoid/railties/controller_runtime'
describe 'Mongoid::Railties::ControllerRuntime' do
CONTROLLER_RUNTIME = Mongoid::Railties::ControllerRuntime
COLLECTOR = CONTROLLER_RUNTIME::Collector
def set_metric(value)
Mongoid::Threaded.set(COLLECTOR::VAR... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/touchable_spec.rb | Ruby | mit | 3,920 | master | 40,952 | # frozen_string_literal: true
require 'spec_helper'
require_relative 'touchable_spec_models'
describe Mongoid::Touchable do
describe '#touch' do
context 'when the document has no associations' do
let(:updatable) do
Updatable.create!
end
it 'responds to #touch' do
expect(updata... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/shardable_models.rb | Ruby | mit | 3,920 | master | 1,256 | class SmMovie
include Mongoid::Document
field :year, type: Integer
index year: 1
shard_key :year
end
class SmTrailer
include Mongoid::Document
index year: 1
shard_key 'year'
end
class SmActor
include Mongoid::Document
# This is not a usable shard configuration for the server.
# We just have it... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/document_persistence_context_spec.rb | Ruby | mit | 3,920 | master | 3,621 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Document do
let(:klass) do
Person
end
let(:person) do
Person.new
end
describe '.client_name' do
it 'returns client name' do
Person.client_name.should eq :default
end
end
describe '.database_name' do
it 're... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/loading_spec.rb | Ruby | mit | 3,920 | master | 2,927 | # frozen_string_literal: true
require 'ostruct'
require 'spec_helper'
require 'support/feature_sandbox'
describe Mongoid::Loadable do
let(:model_root) do
File.absolute_path(
File.join(
File.dirname(__FILE__),
'../support/models/sandbox'
)
)
end
let(:app_models_root) { File.j... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/fields_spec.rb | Ruby | mit | 3,920 | master | 57,664 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Fields do
describe "#\{field}_translations" do
let(:product) do
Product.new
end
context 'when the field is localized' do
context 'when translations exist' do
with_default_i18n_configs
before do
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/serializable_spec.rb | Ruby | mit | 3,920 | master | 25,162 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Serializable do
describe '#field_names' do
let(:guitar) do
Guitar.new
end
it 'does not duplicate fields' do
expect(guitar.send(:field_names, {})).to eq(guitar.fields.except('_type').keys.sort)
end
context 'when u... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/findable_spec.rb | Ruby | mit | 3,920 | master | 20,778 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Findable do
describe '.distinct' do
before do
Band.create!(name: 'Tool')
Band.create!(name: 'Photek')
end
it 'returns the distinct values for the field' do
expect(Band.distinct(:name).sort).to eq(%w[Photek Tool])
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/traversable_spec.rb | Ruby | mit | 3,920 | master | 37,231 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Traversable do
describe '#_children' do
let(:person) do
Person.new(title: 'King')
end
context 'with one level of embedding' do
let(:name) do
Name.new(first_name: 'Titus')
end
let(:address) do
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/document_fields_spec.rb | Ruby | mit | 3,920 | master | 5,608 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Document do
describe 'BSON::Binary field' do
context 'when assigned a BSON::Binary instance' do
let(:data) do
BSON::Binary.new('hello world')
end
let(:registry) do
Registry.new(data: data)
end
i... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/atomic_update_preparer_spec.rb | Ruby | mit | 3,920 | master | 2,285 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::AtomicUpdatePreparer do
describe '#prepare' do
let(:prepared) { described_class.prepare(hash, Band) }
context 'when the hash already contains $set' do
context 'when the $set is first' do
let(:hash) do
{ '$set' => ... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/validatable_spec.rb | Ruby | mit | 3,920 | master | 6,828 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Validatable do
let(:account) do
Account.new(name: 'Testing a really long name.')
end
describe '#read_attribute_for_validation' do
let(:person) do
Person.new(title: 'Mr')
end
let!(:address) do
person.addresses.bui... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/attributes_spec.rb | Ruby | mit | 3,920 | master | 66,029 | # frozen_string_literal: true
require 'spec_helper'
require_relative 'attributes/nested_spec_models'
describe Mongoid::Attributes do
describe "\#{attribute}" do
context 'when setting the value in the getter' do
let(:account) do
Account.new
end
it 'does not cause an infinite loop' do
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/indexable_spec.rb | Ruby | mit | 3,920 | master | 25,923 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Indexable do
after do
Person.collection.drop
end
describe '.included' do
let(:klass) do
Class.new do
include Mongoid::Indexable
end
end
it 'adds an index_specifications accessor' do
expect(klass).to... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/collection_configurable_spec.rb | Ruby | mit | 3,920 | master | 4,148 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::CollectionConfigurable do
before(:all) do
class CollectionConfigurableValidOptions
include Mongoid::Document
store_in collection_options: {
capped: true,
size: 2560
}
end
class CollectionConfigurabl... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/document_query_spec.rb | Ruby | mit | 3,920 | master | 2,839 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Document do
context 'when projecting with #only' do
before do
Person.create!(username: 'Dev', title: 'CEO')
end
let(:person) { Person.where(username: 'Dev').only(:_id, :username).first }
it 'populates specified fields only... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/warnings_spec.rb | Ruby | mit | 3,920 | master | 830 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Warnings do
describe '.warn_*' do
context 'when calling a warn_* method' do
let(:id) { :geo_haystack_deprecated }
let(:message) do
'The geoHaystack type is deprecated.'
end
before do
warn_id = id
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/interceptable_spec.rb | Ruby | mit | 3,920 | master | 75,725 | # frozen_string_literal: true
require 'spec_helper'
require_relative 'interceptable_spec_models'
describe Mongoid::Interceptable do
before do
# The find and initialize callbacks I added were causing failures
# because they were causing updates when we were asserting no updates
# happened.
Label.rese... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/loadable_spec.rb | Ruby | mit | 3,920 | master | 2,508 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Loadable do
let(:lib_dir) { Pathname.new('../../lib').realpath(__dir__) }
shared_context 'with ignore_patterns' do
around do |example|
saved = Mongoid.ignore_patterns
Mongoid.ignore_patterns = ignore_patterns
example.run
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/criteria_spec.rb | Ruby | mit | 3,920 | master | 85,814 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Criteria do
describe '#==' do
let(:criteria) do
Band.where(name: 'Depeche Mode')
end
context 'when the other is a criteria' do
context 'when the criteria are the same' do
let(:other) do
Band.where(name: ... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/document_spec.rb | Ruby | mit | 3,920 | master | 27,093 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Document do
let(:klass) do
Person
end
let(:person) do
Person.new
end
it 'defines a _destroy method' do
expect(Person.new).to respond_to(:_destroy)
end
describe '#_destroy' do
it 'default to false' do
expect(Pe... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable_spec.rb | Ruby | mit | 3,920 | master | 8,948 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable do
class PersistableSpecTestException < StandardError; end
describe '#atomically' do
let(:document) do
Band.create!(member_count: 0, likes: 60, origin: 'London')
end
context 'when providing a block' do
shar... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/selectable_spec.rb | Ruby | mit | 3,920 | master | 3,237 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Selectable do
describe '#atomic_selector' do
context 'when the document is a root document' do
context 'when the document has a shard key' do
let(:profile) do
Profile.create!(name: 'google')
end
let!(:... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/model_resolver_spec.rb | Ruby | mit | 3,920 | master | 5,373 | # frozen_string_literal: true
require 'spec_helper'
require 'support/feature_sandbox'
MONGOID_MODEL_RESOLVER_KEY__ = :__separate_instance_spec_key
Mongoid::ModelResolver.register_resolver Mongoid::ModelResolver.new, MONGOID_MODEL_RESOLVER_KEY__
def quarantine(context, &block)
state = {}
context.before(:context)... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/timestamps_spec.rb | Ruby | mit | 3,920 | master | 15,004 | # frozen_string_literal: true
require 'spec_helper'
require_relative 'timestamps_spec_models'
describe Mongoid::Timestamps do
describe '.included' do
let(:document) do
Dokument.new
end
let(:fields) do
Dokument.fields
end
let(:time_zone) { 'Pacific Time (US & Canada)' }
time_zo... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/positional_spec.rb | Ruby | mit | 3,920 | master | 5,315 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Positional do
describe '#positionally' do
let(:positionable) do
Class.new do
include Mongoid::Positional
end.new
end
let(:updates) do
{
'$set' => {
'field' => 'value',
'children.0... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/copyable_spec.rb | Ruby | mit | 3,920 | master | 31,295 | # frozen_string_literal: true
require 'spec_helper'
require_relative 'copyable_spec_models'
describe Mongoid::Copyable do
%i[clone dup].each do |method|
describe "##{method}" do
let(:person) do
Person.new(
title: 'Sir',
version: 4,
created_at: Time.now,
upd... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/config_spec.rb | Ruby | mit | 3,920 | master | 23,483 | # frozen_string_literal: true
require 'spec_helper'
require 'support/feature_sandbox'
describe Mongoid::Config do
after do
Mongoid.configure do |config|
config.load_configuration(CONFIG)
end
end
describe '#configured?' do
after do
described_class.connect_to(database_id, read: :primary)
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/timestamps_spec_models.rb | Ruby | mit | 3,920 | master | 1,834 | # frozen_string_literal: true
module TimestampsSpec
module Touch
class User
include Mongoid::Document
include Mongoid::Timestamps
has_and_belongs_to_many :addresses, class_name: 'TimestampsSpec::Touch::Address'
has_many :accounts, class_name: 'TimestampsSpec::Touch::Account'
has_on... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/reloadable_spec.rb | Ruby | mit | 3,920 | master | 20,146 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Reloadable do
describe '#reload' do
context 'when called during after_save' do
context 'when using non-sharded documents' do
class NonShardedProfile
include Mongoid::Document
attr_reader :after_save_count, :... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/association_spec.rb | Ruby | mit | 3,920 | master | 3,830 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Association do
before(:all) do
Person.field(
:_id,
type: BSON::ObjectId,
pre_processed: true,
default: -> { BSON::ObjectId.new },
overwrite: true
)
end
context 'when class_name references an unknown clas... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/touchable_spec_models.rb | Ruby | mit | 3,920 | master | 4,890 | # frozen_string_literal: true
module TouchableSpec
module Embedded
class Building
include Mongoid::Document
include Mongoid::Timestamps
field :title, type: String
embeds_many :entrances, class_name: 'TouchableSpec::Embedded::Entrance'
embeds_many :floors, class_name: 'TouchableSpe... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/search_indexable_spec.rb | Ruby | mit | 3,920 | master | 18,946 | # frozen_string_literal: true
require 'spec_helper'
class SearchIndexHelper
attr_reader :model
def initialize(model)
@model = model
model.collection.drop
model.collection.create
end
def collection
model.collection
end
# Wait for all of the indexes with the given names to be ready; then ... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/clients_spec.rb | Ruby | mit | 3,920 | master | 30,912 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Clients do
describe '#collection' do
shared_examples_for 'an overridden collection at the class level' do
it 'returns the collection for the model' do
expect(instance_collection).to be_a(Mongo::Collection)
end
it 's... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/inspectable_spec.rb | Ruby | mit | 3,920 | master | 3,619 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Inspectable do
describe '#inspect' do
context 'when not allowing dynamic fields' do
let(:person) do
Person.new(title: 'CEO')
end
let(:inspected) do
person.inspect
end
it 'includes the model type... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/criteria_projection_spec.rb | Ruby | mit | 3,920 | master | 10,811 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Criteria do
describe '#only' do
let!(:band) do
Band.create!(name: 'Depeche Mode', likes: 3, views: 10)
end
context 'when not using inheritance' do
context 'when passing splat args' do
let(:criteria) do
B... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/composable_spec.rb | Ruby | mit | 3,920 | master | 644 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Composable do
describe '.prohibited_methods' do
let(:methods) do
described_class.prohibited_methods
end
Mongoid::Composable::MODULES.each do |mod|
context "when checking in #{mod}" do
mod.instance_methods.each do ... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/equality_spec.rb | Ruby | mit | 3,920 | master | 4,667 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Equality do
let(:klass) do
Person
end
let(:person) do
Person.new
end
describe '#==' do
context 'when comparable is not a document' do
let(:other) do
'Document'
end
it 'returns false' do
exp... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/changeable_spec.rb | Ruby | mit | 3,920 | master | 51,528 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Changeable do
describe '#attribute_change' do
context 'when the attribute has changed from the persisted value' do
context 'when using the setter' do
let(:person) do
Person.new(title: 'Grand Poobah').tap(&:move_changes... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/atomic_spec.rb | Ruby | mit | 3,920 | master | 12,306 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Atomic do
describe '#add_atomic_pull' do
let!(:person) do
Person.create!
end
let(:address) do
person.addresses.create!
end
let(:location) do
address.locations.create!
end
before do
person.add... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/mongoizable_spec.rb | Ruby | mit | 3,920 | master | 7,894 | # frozen_string_literal: true
require 'spec_helper'
# This file is for testing the functionality of uncastable values for all
# mongoizable classes.
describe 'mongoize/demongoize/evolve methods' do
shared_examples 'handles unmongoizable values' do
context 'when passing an invalid value' do
context 'to mon... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/shardable_spec.rb | Ruby | mit | 3,920 | master | 8,541 | # frozen_string_literal: true
require 'spec_helper'
require_relative 'shardable_models'
describe Mongoid::Shardable do
describe '.included' do
let(:klass) do
Class.new do
include Mongoid::Shardable
end
end
it 'adds an shard_key_fields accessor' do
expect(klass).to respond_to(:... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/loggable_spec.rb | Ruby | mit | 3,920 | master | 362 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Loggable do
describe '#logger=' do
let(:logger) do
Logger.new($stdout).tap do |log|
log.level = Logger::INFO
end
end
before do
Mongoid.logger = logger
end
it 'sets the logger' do
expect(Mongoi... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/stateful_spec.rb | Ruby | mit | 3,920 | master | 5,522 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Stateful do
describe '#new_record?' do
context 'when calling new on the document' do
let(:person) do
Person.new('_id' => BSON::ObjectId.new)
end
it 'returns true' do
expect(person).to be_a_new_record
e... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/threaded_spec.rb | Ruby | mit | 3,920 | master | 7,369 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Threaded do
let(:object) do
double
end
describe '#begin' do
before do
described_class.begin_execution('load')
end
after do
described_class.stack('load').clear
end
it 'adds a boolean to the load stack' do... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/copyable_spec_models.rb | Ruby | mit | 3,920 | master | 703 | # frozen_string_literal: true
module CopyableSpec
class A
include Mongoid::Document
embeds_many :locations
embeds_many :influencers
end
class Location
include Mongoid::Document
embeds_many :buildings
end
class Building
include Mongoid::Document
end
class Influencer
includ... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/factory_spec.rb | Ruby | mit | 3,920 | master | 12,815 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Factory do
describe '.build' do
context 'when the type attribute is present' do
let(:attributes) do
{ '_type' => 'Person', 'title' => 'Sir' }
end
context 'when the type is a class' do
let(:person) do
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/scopable_spec.rb | Ruby | mit | 3,920 | master | 32,760 | # frozen_string_literal: true
require 'spec_helper'
# Retrieve the singleton class for the given class.
def singleton_class_for(klass)
class << klass; self; end
end
# Helper method for removing a declared scope
def remove_scope(klass, scope)
return unless klass._declared_scopes[scope]
singleton_class_for(klas... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistence_context_spec.rb | Ruby | mit | 3,920 | master | 19,374 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::PersistenceContext do
let(:persistence_context) do
described_class.new(object, options)
end
let(:object) do
Band
end
describe '.set' do
let(:options) do
{ collection: :other }
end
context 'when the persistence... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/interceptable_spec_models.rb | Ruby | mit | 3,920 | master | 5,766 | module InterceptableSpec
class CallbackRegistry
def initialize(only: [])
@calls = []
@only = only
end
def record_call(cls, cb)
return unless @only.empty? || @only.any? { |pat| pat == cb }
@calls << [ cls, cb ]
end
attr_reader :calls
end
module CallbackTracking
e... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/cacheable_spec.rb | Ruby | mit | 3,920 | master | 3,640 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Cacheable do
describe '.included' do
let(:klass) do
Class.new do
include Mongoid::Cacheable
end
end
it 'adds an cache_timestamp_format accessor' do
expect(klass).to respond_to(:cache_timestamp_format)
en... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/monkey_patches_spec.rb | Ruby | mit | 3,920 | master | 4,323 | # frozen_string_literal: true
require 'spec_helper'
# @note This test ensures that we do not inadvertently introduce new monkey patches
# to Mongoid. Existing monkey patch methods which are marked with +Mongoid.deprecated+
# are excluded from this test.
RSpec.describe('Do not add monkey patches') do
classes = [
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/pullable_spec.rb | Ruby | mit | 3,920 | master | 7,906 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Pullable do
describe '#pull' do
context 'when the document is a root document' do
shared_examples_for 'a pullable root document' do
it 'pulls the first value' do
expect(person.aliases).to eq([ 2, 3 ])
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/unsettable_spec.rb | Ruby | mit | 3,920 | master | 4,693 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Unsettable do
describe '#unset' do
context 'when the document is a root document' do
shared_examples_for 'an unsettable root document' do
it 'unsets the first field' do
expect(person.title).to be_nil
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/renamable_spec.rb | Ruby | mit | 3,920 | master | 4,447 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Renamable do
describe '#rename' do
context 'when the document is a root document' do
shared_examples_for 'a renamable root document' do
it 'renames the first field' do
expect(person.salutation).to eq('sir'... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/creatable_spec.rb | Ruby | mit | 3,920 | master | 16,923 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Creatable do
describe '.create' do
context 'when provided an array of attributes' do
context 'when no block is passed' do
let(:people) do
Person.create([ { title: 'sir' }, { title: 'madam' } ])
end... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/minable_spec.rb | Ruby | mit | 3,920 | master | 4,548 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Minable do
describe '#set_min' do
shared_examples_for 'a min-able interface' do
context 'when the document is a root document' do
let(:initial_name) { 'Manhattan Transfer' }
let(:initial_members) { 4 }
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/poppable_spec.rb | Ruby | mit | 3,920 | master | 3,911 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Poppable do
describe '#pop' do
context 'when the document is the root document' do
shared_examples_for 'a poppable root document' do
it 'pops for positive values' do
expect(person.array).to eq([ 1, 2, 3 ])... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/updatable_spec.rb | Ruby | mit | 3,920 | master | 18,099 | # frozen_string_literal: true
require 'spec_helper'
require 'support/immutable_ids'
describe Mongoid::Persistable::Updatable do
extend Mongoid::ImmutableIds
immutable_id_examples_as 'persisted _ids are immutable'
describe '#update_attribute' do
context 'when the field is aliased' do
let(:person) do
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/incrementable_spec.rb | Ruby | mit | 3,920 | master | 6,477 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Incrementable do
describe '#inc' do
context 'when the document is a root document' do
shared_examples_for 'an incrementable root document' do
it 'increments a positive value' do
expect(person.age).to eq(15... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/upsertable_spec.rb | Ruby | mit | 3,920 | master | 5,681 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Upsertable do
describe '#upsert' do
context 'when the document validates on upsert' do
let(:account) do
Account.new(name: 'testing')
end
context 'when the document is not valid in the upsert context' do... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/savable_spec.rb | Ruby | mit | 3,920 | master | 20,124 | # frozen_string_literal: true
require 'spec_helper'
require 'support/immutable_ids'
describe Mongoid::Persistable::Savable do
extend Mongoid::ImmutableIds
immutable_id_examples_as 'persisted _ids are immutable'
describe '#save' do
let(:person) do
Person.create!
end
let(:contextable_item) do... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/deletable_spec.rb | Ruby | mit | 3,920 | master | 13,799 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Deletable do
describe '#delete' do
let!(:person) do
Person.create!
end
context 'when deleting a readonly document' do
let(:from_db) do
Person.first.tap(&:readonly!)
end
it 'raises an erro... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/destroyable_spec.rb | Ruby | mit | 3,920 | master | 16,477 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Destroyable do
describe '#destroy' do
let!(:person) do
Person.create!
end
context 'when destroying a readonly document' do
let(:from_db) do
Person.first.tap(&:readonly!)
end
it 'raises an... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/pushable_spec.rb | Ruby | mit | 3,920 | master | 10,538 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Pushable do
describe '#add_to_set' do
context 'when the document is a top level document' do
shared_examples_for 'a unique pushable root document' do
it 'adds single values' do
expect(person.aliases).to eq... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/settable_spec.rb | Ruby | mit | 3,920 | master | 16,090 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Settable do
describe '#set' do
context 'when the document is a root document' do
shared_examples_for 'a settable root document' do
it 'sets the normal field to the new value' do
expect(person.title).to eq(... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/logical_spec.rb | Ruby | mit | 3,920 | master | 4,646 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Logical do
describe '#bit' do
context 'when the document is a root document' do
shared_examples_for 'a logical root document' do
it 'applies and operations' do
expect(person.age).to eq(12)
end
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/mongoid/persistable/multipliable_spec.rb | Ruby | mit | 3,920 | master | 5,209 | # frozen_string_literal: true
require 'spec_helper'
describe Mongoid::Persistable::Multipliable do
describe '#mul' do
context 'when the document is a root document' do
shared_examples_for 'a multipliable root document' do
it 'multiplies a positive value' do
expect(person.age).to eq(50)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.