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/integration/associations/has_and_belongs_to_many_spec.rb | Ruby | mit | 3,920 | master | 3,969 | # frozen_string_literal: true
require 'spec_helper'
module HabtmSpec
class Page
include Mongoid::Document
embeds_many :blocks, class_name: 'HabtmSpec::Block'
end
class Block
include Mongoid::Document
embedded_in :page, class_name: 'HabtmSpec::Page'
end
class ImageBlock < Block
has_an... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/integration/associations/reverse_population_spec.rb | Ruby | mit | 3,920 | master | 1,062 | # frozen_string_literal: true
require 'spec_helper'
require_relative 'reverse_population_spec_models'
describe 'Association reverse population' do
describe 'has_many/belongs_to' do
it 'populates child in parent' do
company = ReversePopulationSpec::Company.create!
email = ReversePopulationSpec::Email... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/integration/associations/reverse_population_spec_models.rb | Ruby | mit | 3,920 | master | 810 | # frozen_string_literal: true
module ReversePopulationSpec
class Company
include Mongoid::Document
has_many :emails, class_name: 'ReversePopulationSpec::Email'
has_one :founder, class_name: 'ReversePopulationSpec::Founder'
end
class Email
include Mongoid::Document
belongs_to :company, clas... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/integration/associations/embeds_many_spec.rb | Ruby | mit | 3,920 | master | 9,507 | # frozen_string_literal: true
require 'spec_helper'
module EmbedsManySpec
class Post
include Mongoid::Document
field :title, type: String
embeds_many :comments, class_name: 'EmbedsManySpec::Comment', as: :container
accepts_nested_attributes_for :comments
end
class Comment
include Mongoid::... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/integration/criteria/logical_spec.rb | Ruby | mit | 3,920 | master | 3,319 | require 'spec_helper'
describe 'Criteria logical operations' do
let!(:ap) { Band.create!(name: 'Astral Projection', origin: 'SFX', genres: %w[Goa Psy]) }
let!(:im) { Band.create!(name: 'Infected Mushroom', origin: 'Computers', genres: [ 'Psy' ]) }
let!(:sp) { Band.create!(name: 'Sun Project', genres: [ 'Goa' ]) ... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/integration/criteria/alias_query_spec.rb | Ruby | mit | 3,920 | master | 1,738 | # frozen_string_literal: true
require 'spec_helper'
describe 'distinct on aliased fields' do
let(:client) { Person.collection.client }
let(:event) do
subscriber.single_command_started_event('distinct')
end
let(:command) { event.command }
let(:subscriber) do
Mrss::EventSubscriber.new
end
before... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/integration/criteria/time_with_zone_spec.rb | Ruby | mit | 3,920 | master | 4,668 | # frozen_string_literal: true
require 'spec_helper'
describe 'TimeWithZone in queries' do
let(:now_utc) { Time.now.utc }
let(:now_in_zone) { now_utc.in_time_zone(time_zone) }
shared_examples_for 'time zone queries' do
let!(:book_earlier) { Book.create!(updated_at: now_utc - 20.minutes, dynamic_time: now_ut... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/integration/criteria/range_spec.rb | Ruby | mit | 3,920 | master | 12,314 | # frozen_string_literal: true
require 'spec_helper'
describe 'Queries with Range criteria' do
let(:now_utc) { Time.utc(2020, 1, 1, 16, 0, 0, 0) }
let(:now_in_zone) { now_utc.in_time_zone('Asia/Tokyo') }
let(:today) { Date.new(2020, 1, 1) }
let(:labels) do
[ Label.new(age: 12), Label.new(age: 16) ]
end
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/integration/criteria/date_field_spec.rb | Ruby | mit | 3,920 | master | 888 | # frozen_string_literal: true
require 'spec_helper'
describe 'Queries on Date fields' do
let(:query) do
Band.where(founded: arg)
end
let(:selector) { query.selector }
shared_examples 'converts to beginning of day in UTC' do
it 'converts to beginning of day in UTC' do
selector['founded'].should... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/integration/criteria/raw_value_spec.rb | Ruby | mit | 3,920 | master | 18,381 | # frozen_string_literal: true
require 'spec_helper'
describe 'Queries with Mongoid::RawValue criteria' do
let(:now_utc) { Time.utc(2020, 1, 1, 16, 0, 0, 0) }
let(:today) { Date.new(2020, 1, 1) }
let(:labels) do
[ Label.new(age: 12), Label.new(age: 16) ]
end
let!(:band1) do
Band.create!(name: '1', ... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/integration/criteria/default_scope_spec.rb | Ruby | mit | 3,920 | master | 1,809 | require 'spec_helper'
describe 'Criteria and default scope' do
context 'order in query' do
let(:query) do
Acolyte.order(status: :desc)
end
let(:sort_options) do
query.options[:sort]
end
it 'is added after order of default scope' do
sort_options.should eq({ 'status' => -1, 'nam... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/authorization.rb | Ruby | mit | 3,920 | master | 478 | # frozen_string_literal: true
# Set up a root user so we can set up authentication on a database level.
MONGOID_ROOT_USER = Mongo::Auth::User.new(
database: Mongo::Database::ADMIN,
user: 'mongoid-user',
password: 'password',
roles: [
Mongo::Auth::Roles::USER_ADMIN_ANY_DATABASE,
Mongo::Auth::Roles::DATA... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/constraints.rb | Ruby | mit | 3,920 | master | 2,053 | # frozen_string_literal: true
module Constraints
RAILS_VERSION = ActiveSupport.version.to_s.split('.')[0..1].join('.').freeze
def min_driver_version(version)
required_version = version.split('.').map(&:to_i)
actual_version = driver_version(required_version.length)
before(:all) do
skip "Driver ve... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/rails_mock.rb | Ruby | mit | 3,920 | master | 559 | # A simplistic mock object to stand in for Rails, instead of adding an
# otherwise unnecessary dependency on Rails itself.
require 'ostruct'
module Rails
extend self
attr_accessor :env, :root, :logger, :application
module Application
extend self
attr_accessor :config
def eager_load!; end
end
e... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/feature_sandbox.rb | Ruby | mit | 3,920 | master | 2,029 | # frozen_string_literal: true
# A helper utility for allowing features to be loaded and constants defined
# inside a sandbox, where they can be unloaded and undefined when finished.
#
# @example Quarantining a block of code.
# FeatureSandbox.quarantine do
# require "support/rails_mock"
# expect(defined?(Ra... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/crypt.rb | Ruby | mit | 3,920 | master | 1,899 | # frozen_string_literal: true
module Mongoid
# This module includes helpers for testing encryption.
module Crypt
shared_context 'with encryption' do
let(:mongocryptd_port) do
if ENV['MONGO_RUBY_DRIVER_MONGOCRYPTD_PORT'] &&
!ENV['MONGO_RUBY_DRIVER_MONGOCRYPTD_PORT'].empty?
ENV... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/immutable_ids.rb | Ruby | mit | 3,920 | master | 4,100 | module Mongoid
module ImmutableIds
def immutable_id_examples_as(name)
shared_examples_for name do
shared_examples 'a persisted document' do
it 'disallows _id to be updated' do
expect { invoke_operation! }
.to raise_error(Mongoid::Errors::ImmutableAttribute)
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/helpers.rb | Ruby | mit | 3,920 | master | 267 | module Helpers
# Reloads the specified model class.
#
# @param [ String | Symbol ] name Class name to reload.
def reload_model(name)
Object.class_eval do
remove_const(name)
end
load "spec/support/models/#{name.to_s.underscore}.rb"
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/expectations.rb | Ruby | mit | 3,920 | master | 1,460 | # frozen_string_literal: true
module Mongoid
module Expectations
# Previously this method used RSpec::Mocks with .exactly.times(n).and_call_original,
# which stopped working reliably in Ruby 3.3. Now we directly wrap the target method.
def expect_query(number, &test_block)
count_queries_and_verify(... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/macros.rb | Ruby | mit | 3,920 | master | 3,038 | # frozen_string_literal: true
module Mongoid
module Macros
def use_spec_mongoid_config
around do |example|
config_path = File.join(File.dirname(__FILE__), '..', 'config', 'mongoid.yml')
Mongoid::Clients.clear
Mongoid.load!(config_path, :test)
begin
example.run
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/spec_config.rb | Ruby | mit | 3,920 | master | 1,984 | # frozen_string_literal: true
require 'singleton'
class SpecConfig
include Singleton
DEFAULT_MONGODB_URI = 'mongodb://127.0.0.1:27017'
def initialize
if ENV['MONGODB_URI']
@uri_str = ENV['MONGODB_URI']
else
warn "Environment variable 'MONGODB_URI' is not set, so the default url will be use... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/seat.rb | Ruby | mit | 3,920 | master | 322 | # frozen_string_literal: true
class Seat
include Mongoid::Document
embedded_in :vehicle
field :rating, type: Integer
embeds_many :armrests
before_create :set_rating
before_update :update_rating
private
def set_rating
self.rating ||= 100
end
def update_rating
self.rating += 1
end
en... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/article.rb | Ruby | mit | 3,920 | master | 394 | # frozen_string_literal: true
class Article
include Mongoid::Document
field :author_id, type: Integer
field :public, type: Mongoid::Boolean
field :title, type: String
field :is_rss, type: Mongoid::Boolean, default: false
field :user_login, type: String
has_and_belongs_to_many :tags, validate: false
h... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/note.rb | Ruby | mit | 3,920 | master | 376 | # frozen_string_literal: true
class Note
include Mongoid::Document
field :text, type: String
field :saved, type: Mongoid::Boolean, default: false
embedded_in :noteable, polymorphic: true
after_save :update_saved
scope :permanent, -> { where(saved: true) }
def update_saved
self.saved = true
end
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/login.rb | Ruby | mit | 3,920 | master | 218 | # frozen_string_literal: true
class Login
include Mongoid::Document
field :_id, type: String, overwrite: true, default: -> { username }
field :username, type: String
field :application_id, type: Integer
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/division.rb | Ruby | mit | 3,920 | master | 218 | # frozen_string_literal: true
class Division
include Mongoid::Document
field :name, type: String
embedded_in :league
before_destroy :update_parent
def update_parent
league.name = 'Destroyed'
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/vertex.rb | Ruby | mit | 3,920 | master | 237 | # frozen_string_literal: true
class Vertex
include Mongoid::Document
has_and_belongs_to_many :parents, inverse_of: :children, class_name: 'Vertex'
has_and_belongs_to_many :children, inverse_of: :parents, class_name: 'Vertex'
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/tag.rb | Ruby | mit | 3,920 | master | 281 | # frozen_string_literal: true
class Tag
include Mongoid::Document
field :text, type: String
has_and_belongs_to_many :actors
has_and_belongs_to_many :articles
has_and_belongs_to_many :posts
has_and_belongs_to_many :related, class_name: 'Tag', inverse_of: :related
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/hole.rb | Ruby | mit | 3,920 | master | 354 | # frozen_string_literal: true
class Hole
include Mongoid::Document
has_one :bolt, dependent: :destroy
has_one :threadlocker, dependent: :delete_all
has_one :sealer, dependent: :restrict_with_exception
has_many :nuts, dependent: :destroy
has_many :washers, dependent: :delete_all
has_many :spacers, depend... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/system_role.rb | Ruby | mit | 3,920 | master | 237 | class SystemRole
include Mongoid::Document
# NOTE: this model is for test purposes only. It is not recommended that you
# store Mongoid documents in system collections.
store_in collection: 'system.roles', database: 'admin'
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/shop.rb | Ruby | mit | 3,920 | master | 209 | # frozen_string_literal: true
class Shop
include Mongoid::Document
field :title, type: String
has_and_belongs_to_many :followers, inverse_of: :followed_shops, class_name: 'User'
belongs_to :user
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/mop.rb | Ruby | mit | 3,920 | master | 883 | # frozen_string_literal: true
# This class is used for embedded matcher testing.
class Mop
include Mongoid::Document
# The dynamic attributes are used so that the tests can use various
# field names as makes sense for the particular operator.
include Mongoid::Attributes::Dynamic
# We need some fields of sp... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/address.rb | Ruby | mit | 3,920 | master | 1,947 | # frozen_string_literal: true
class Address
include Mongoid::Document
field :_id, type: String, overwrite: true, default: -> { street.try(:parameterize) }
attr_accessor :mode
field :address_type
field :number, type: Integer
field :no, type: Integer
field :h, as: :house, type: Integer
field :street
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/event.rb | Ruby | mit | 3,920 | master | 614 | # frozen_string_literal: true
class Event
include Mongoid::Document
field :title
field :date, type: Date
has_and_belongs_to_many \
:administrators,
class_name: 'Person',
inverse_of: :administrated_events,
dependent: :nullify
belongs_to :owner
def self.each_day(start_date, end_date)
gr... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/album.rb | Ruby | mit | 3,920 | master | 299 | # frozen_string_literal: true
class Album
include Mongoid::Document
belongs_to :artist
before_destroy :set_parent_name
attr_accessor :before_add_called
private
def set_parent_name
artist.name = 'destroyed' if artist
end
def set_parent_name_fail
throw(:abort)
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/artist.rb | Ruby | mit | 3,920 | master | 2,126 | # frozen_string_literal: true
class Artist
include Mongoid::Document
attr_accessor :before_add_called, :after_add_called, :before_add_referenced_called, :after_add_referenced_called,
:before_remove_embedded_called, :after_remove_embedded_called, :before_remove_referenced_called, :after_remove_refe... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/survey.rb | Ruby | mit | 3,920 | master | 207 | # frozen_string_literal: true
class Survey
include Mongoid::Document
embeds_many :questions
accepts_nested_attributes_for :questions, reject_if: ->(a) { a[:content].blank? }, allow_destroy: true
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/movie.rb | Ruby | mit | 3,920 | master | 324 | # frozen_string_literal: true
class Movie
include Mongoid::Document
include Mongoid::Attributes::Dynamic
field :title, type: String
field :poster, type: Image
field :poster_thumb, type: Thumbnail
has_many :ratings, as: :ratable, dependent: :nullify
has_many :comments
def global_set
Set.new
end
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/location.rb | Ruby | mit | 3,920 | master | 205 | # frozen_string_literal: true
class Location
include Mongoid::Document
field :name
field :info, type: Hash
field :occupants, type: Array
field :number, type: Integer
embedded_in :address
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/item.rb | Ruby | mit | 3,920 | master | 229 | # frozen_string_literal: true
class Item
include Mongoid::Document
field :title, type: String
field :is_rss, type: Mongoid::Boolean, default: false
field :user_login, type: String
end
require 'support/models/sub_item' |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/record.rb | Ruby | mit | 3,920 | master | 1,310 | # frozen_string_literal: true
class Record
include Mongoid::Document
field :name, type: String
field :producers, type: Array
field :before_create_called, type: Mongoid::Boolean, default: false
field :before_save_called, type: Mongoid::Boolean, default: false
field :before_update_called, type: Mongoid::Bo... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/powerup.rb | Ruby | mit | 3,920 | master | 478 | # frozen_string_literal: true
class Powerup
include Mongoid::Document
field :name
belongs_to :player, inverse_of: :powerup
after_build do
self.name = "Quad Damage (#{player.frags})"
end
field :after_find_player
field :after_initialize_player
field :after_default_player, default: -> { player&._i... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/weapon.rb | Ruby | mit | 3,920 | master | 483 | # frozen_string_literal: true
class Weapon
include Mongoid::Document
field :name
belongs_to :player, inverse_of: :weapons
after_build do
self.name = "Holy Hand Grenade (#{player.frags})"
end
field :after_find_player
field :after_initialize_player
field :after_default_player, default: -> { playe... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/eye_bowl.rb | Ruby | mit | 3,920 | master | 259 | # frozen_string_literal: true
class EyeBowl
include Mongoid::Document
has_many :blue_eyes, class_name: 'Eye', as: :eyeable
has_many :brown_eyes, class_name: 'Eye', as: :eyeable
has_one :face, as: :suspended_in
has_one :eye, as: :suspended_in
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/delegating_patient.rb | Ruby | mit | 3,920 | master | 267 | # frozen_string_literal: true
class DelegatingPatient
include Mongoid::Document
embeds_one :email
# Instance level delegation
delegate :address, to: :email
class << self
# Class level delegation
delegate :default_client, to: ::Mongoid
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/modifier_models.rb | Ruby | mit | 3,920 | master | 553 | # frozen_string_literal: true
module ModifierModels
class Library
include Mongoid::Document
field :name, type: String
embeds_many :books, class_name: 'ModifierModels::Book'
end
class Book
include Mongoid::Document
embedded_in :library, class_name: 'ModifierModels::Library'
field :title... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/name.rb | Ruby | mit | 3,920 | master | 802 | # frozen_string_literal: true
class Name
include Mongoid::Document
include Mongoid::Attributes::Dynamic
validate :is_not_jamis
field :_id, type: String, overwrite: true, default: lambda {
"#{first_name}-#{last_name}"
}
field :first_name, type: String
field :last_name, type: String
field :parent_... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/princess.rb | Ruby | mit | 3,920 | master | 249 | # frozen_string_literal: true
class Princess
include Mongoid::Document
field :primary_color
field :name, type: String
def color
primary_color.to_s
end
validates_presence_of :color
validates :name, presence: true, on: :update
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/server.rb | Ruby | mit | 3,920 | master | 398 | # frozen_string_literal: true
class Server
include Mongoid::Document
field :name, type: String
field :after, type: Mongoid::Boolean, default: false
belongs_to :node
embeds_many :filesystems, validate: false
accepts_nested_attributes_for :filesystems
validates :name, presence: { allow_blank: false }
a... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/implant.rb | Ruby | mit | 3,920 | master | 563 | # frozen_string_literal: true
class Implant
include Mongoid::Document
field :name
field :impressions, type: Integer, default: 0
embedded_in :player, inverse_of: :implants
after_build do |doc|
doc.name = "Cochlear Implant (#{player.frags})"
end
field :after_find_player
field :after_initialize_pl... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/validation_callback.rb | Ruby | mit | 3,920 | master | 284 | # frozen_string_literal: true
class ValidationCallback
include Mongoid::Document
field :history, type: Array, default: []
validate do
history << :validate
end
before_validation { history << :before_validation }
after_validation { history << :after_validation }
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/question.rb | Ruby | mit | 3,920 | master | 245 | # frozen_string_literal: true
class Question
include Mongoid::Document
field :content
embedded_in :survey
embeds_many :answers
accepts_nested_attributes_for :answers, reject_if: ->(a) { a[:content].blank? }, allow_destroy: true
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/animal.rb | Ruby | mit | 3,920 | master | 637 | # frozen_string_literal: true
class Animal
include Mongoid::Document
field :_id, type: String, overwrite: true, default: -> { name.try(:parameterize) }
field :name
field :height, type: Integer
field :weight, type: Integer
field :tags, type: Array
embedded_in :person
embedded_in :circus, class_name: ... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/acolyte.rb | Ruby | mit | 3,920 | master | 399 | # frozen_string_literal: true
class Acolyte
include Mongoid::Document
include Mongoid::Attributes::Dynamic
field :status
field :name
embeds_many :versions, as: :memorable
belongs_to :church
default_scope -> { asc(:name) }
scope :active, -> { where(status: 'active') }
scope :named, -> { where(:name... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/profile.rb | Ruby | mit | 3,920 | master | 258 | # frozen_string_literal: true
class Profile
include Mongoid::Document
field :name, type: String
embeds_one :profile_image
shard_key :name
end
class ProfileImage
include Mongoid::Document
field :url, type: String
embedded_in :profile
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/pizza.rb | Ruby | mit | 3,920 | master | 213 | # frozen_string_literal: true
class Pizza
include Mongoid::Document
field :name, type: String
has_one :topping, autosave: true
validates_presence_of :topping
accepts_nested_attributes_for :topping
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/augmentation.rb | Ruby | mit | 3,920 | master | 486 | # frozen_string_literal: true
class Augmentation
include Mongoid::Document
field :name
embedded_in :player, inverse_of: :augmentation
after_build do
self.name = "Infolink (#{player.frags})"
end
field :after_find_player
field :after_initialize_player
field :after_default_player, default: -> { pl... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/phone.rb | Ruby | mit | 3,920 | master | 272 | # frozen_string_literal: true
class Phone
include Mongoid::Document
field :_id, type: String, overwrite: true, default: -> { number }
field :number
field :ext, as: :extension
field :landline, type: Boolean
embeds_one :country_code
embedded_in :person
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/service.rb | Ruby | mit | 3,920 | master | 613 | # frozen_string_literal: true
class Service
include Mongoid::Document
field :sid
field :before_destroy_called, type: Mongoid::Boolean, default: false
field :after_destroy_called, type: Mongoid::Boolean, default: false
field :after_initialize_called, type: Mongoid::Boolean, default: false
embedded_in :pers... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/user_account.rb | Ruby | mit | 3,920 | master | 406 | # frozen_string_literal: true
class UserAccount
include Mongoid::Document
field :username, type: String
field :name, type: String
field :email, type: String
validates_uniqueness_of :username, message: 'is not unique'
validates_uniqueness_of :email, message: 'is not unique', case_sensitive: false
validat... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/word.rb | Ruby | mit | 3,920 | master | 417 | # frozen_string_literal: true
class Word
include Mongoid::Document
field :name, type: String
field :origin, type: String
belongs_to :dictionary
embeds_many :definitions, validate: false
embeds_many :word_origins, validate: false
embeds_one :pronunciation, validate: false
accepts_nested_attributes_f... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/actor.rb | Ruby | mit | 3,920 | master | 461 | # frozen_string_literal: true
class Actor
include Mongoid::Document
field :name
field :after_custom_count, type: Integer, default: 0
has_and_belongs_to_many :tags
embeds_many :things, validate: false, cascade_callbacks: true
accepts_nested_attributes_for :things, allow_destroy: true
define_model_callba... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/product.rb | Ruby | mit | 3,920 | master | 656 | # frozen_string_literal: true
class Product
include Mongoid::Document
field :description, localize: true
field :name, localize: true, default: 'no translation'
field :price, type: Integer
field :brand_name
field :stores, type: Array
field :website, localize: true
field :sku, as: :stock_keeping_unit
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/page.rb | Ruby | mit | 3,920 | master | 338 | # frozen_string_literal: true
class Page
include Mongoid::Document
embedded_in :quiz
embeds_many :page_questions
embedded_in :book, touch: true
embeds_many :notes
field :content, type: String
after_initialize do
if self[:content]
self[:text] = self[:content]
remove_attribute(:content)
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/canvas.rb | Ruby | mit | 3,920 | master | 528 | # frozen_string_literal: true
class Canvas
include Mongoid::Document
field :name
embeds_many :shapes
embeds_one :writer
embeds_one :palette
field :foo, type: String, default: -> { 'original' }
has_many :comments, as: :commentable
accepts_nested_attributes_for :shapes
accepts_nested_attributes_for... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/school.rb | Ruby | mit | 3,920 | master | 273 | # frozen_string_literal: true
class School
include Mongoid::Document
has_many :students
field :district, type: String
field :team, type: String
field :after_destroy_triggered, default: false
accepts_nested_attributes_for :students, allow_destroy: true
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/dog.rb | Ruby | mit | 3,920 | master | 235 | # frozen_string_literal: true
class Dog
include Mongoid::Document
field :name, type: String
has_and_belongs_to_many :breeds
has_and_belongs_to_many :fire_hydrants, primary_key: :location
default_scope -> { asc(:name) }
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/customer_address.rb | Ruby | mit | 3,920 | master | 220 | # frozen_string_literal: true
class CustomerAddress
include Mongoid::Document
field :street, type: String
field :city, type: String
field :state, type: String
embedded_in :addressable, polymorphic: true
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/bar.rb | Ruby | mit | 3,920 | master | 259 | # frozen_string_literal: true
class Bar
include Mongoid::Document
include Mongoid::Attributes::Dynamic
field :name, type: String
field :location, type: Array
field :lat_lng, type: LatLng
has_one :rating, as: :ratable
index location: '2d'
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/comment.rb | Ruby | mit | 3,920 | master | 351 | # frozen_string_literal: true
class Comment
include Mongoid::Document
field :title, type: String
field :text, type: String
belongs_to :account
belongs_to :movie
belongs_to :rating
belongs_to :wiki_page
belongs_to :commentable, polymorphic: true
validates :title, presence: true
validates :movie,... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/league.rb | Ruby | mit | 3,920 | master | 285 | # frozen_string_literal: true
class League
include Mongoid::Document
field :name, type: String
embeds_many :divisions
accepts_nested_attributes_for :divisions, allow_destroy: true
before_destroy :destroy_children
def destroy_children
divisions.destroy_all
end
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/dictionary.rb | Ruby | mit | 3,920 | master | 425 | # frozen_string_literal: true
class Dictionary
include Mongoid::Document
field :name, type: String
field :publisher, type: String
field :year, type: Integer
# This field must be a Time
field :published, type: Time
# This field must be a Date
field :submitted_on, type: Date
field :description, typ... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/patient.rb | Ruby | mit | 3,920 | master | 282 | # frozen_string_literal: true
class Patient
include Mongoid::Document
field :title, type: String
store_in collection: 'inpatient'
embeds_many :addresses, as: :addressable
embeds_one :email
embeds_one :name, as: :namable
validates_presence_of :title, on: :create
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/passport.rb | Ruby | mit | 3,920 | master | 493 | # frozen_string_literal: true
class Passport
include Mongoid::Document
field :number, type: String
field :country, type: String
field :exp, as: :expiration_date, type: Date
field :name, localize: true
field :bp, as: :birthplace, localize: true
field :localized_translations, localize: true
embedded_in... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/code.rb | Ruby | mit | 3,920 | master | 245 | # frozen_string_literal: true
class Code
include Mongoid::Document
field :name, type: String
embedded_in :address
embeds_one :deepest
end
class Deepest
include Mongoid::Document
embedded_in :code
field :array, type: Array
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/post.rb | Ruby | mit | 3,920 | master | 1,547 | # frozen_string_literal: true
class Post
include Mongoid::Document
include Mongoid::Attributes::Dynamic
field :title, type: String
field :content, type: String
field :rating, type: Integer
field :person_title, type: String, default: -> { person.title if ivar(:person) }
attr_accessor :before_add_called,... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/word_origin.rb | Ruby | mit | 3,920 | master | 268 | # frozen_string_literal: true
class WordOrigin
include Mongoid::Document
field :_id, type: Integer, overwrite: true, default: -> { origin_id }
field :origin_id, type: Integer
field :country, type: String
field :city, type: String
embedded_in :word
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/definition.rb | Ruby | mit | 3,920 | master | 342 | # frozen_string_literal: true
class Definition
include Mongoid::Document
field :description, type: String
field :p, as: :part, type: String
field :regular, type: Mongoid::Boolean
field :syn, as: :synonyms, localize: true, type: String
field :active, type: Mongoid::Boolean, localize: true, default: true
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/seo.rb | Ruby | mit | 3,920 | master | 283 | # frozen_string_literal: true
class Seo
include Mongoid::Document
include Mongoid::Timestamps
field :title, type: String
field :name, type: String, localize: true
field :desc, as: :description, type: String, localize: true
embedded_in :seo_tags, polymorphic: true
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/order.rb | Ruby | mit | 3,920 | master | 296 | # frozen_string_literal: true
class Order
include Mongoid::Document
field :status, type: Mongoid::StringifiedSymbol
# This is a dummy field that verifies the Mongoid::Fields::StringifiedSymbol
# alias.
field :saved_status, type: StringifiedSymbol
embeds_many :purchased_items
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/book.rb | Ruby | mit | 3,920 | master | 468 | # frozen_string_literal: true
class Book
include Mongoid::Document
include Mongoid::Attributes::Dynamic
include Mongoid::Timestamps
field :title, type: String
field :chapters, type: Integer
belongs_to :series
belongs_to :person, autobuild: true
has_one :rating, as: :ratable, dependent: :nullify
aft... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/tool.rb | Ruby | mit | 3,920 | master | 204 | # frozen_string_literal: true
class Tool
include Mongoid::Document
embedded_in :palette
accepts_nested_attributes_for :palette
end
require 'support/models/eraser'
require 'support/models/pencil' |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/fire_hydrant.rb | Ruby | mit | 3,920 | master | 218 | # frozen_string_literal: true
class FireHydrant
include Mongoid::Document
field :location, type: String
has_and_belongs_to_many :dogs, primary_key: :name
has_and_belongs_to_many :cats, primary_key: :name
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/label.rb | Ruby | mit | 3,920 | master | 1,205 | # frozen_string_literal: true
class Label
include Mongoid::Document
include Mongoid::Timestamps::Updated::Short
field :name, type: String
field :sales, type: BigDecimal
field :age, type: Integer
field :after_create_called, type: Mongoid::Boolean, default: false
field :after_save_called, type: Mongoid::... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/jar.rb | Ruby | mit | 3,920 | master | 200 | # frozen_string_literal: true
class Jar
include Mongoid::Document
include Mongoid::Timestamps::Updated
field :_id, type: Integer, overwrite: true
has_many :cookies, class_name: 'Cookie'
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/person.rb | Ruby | mit | 3,920 | master | 6,113 | # frozen_string_literal: true
class Person
include Mongoid::Document
include Mongoid::Attributes::Dynamic
attr_accessor :mode
class_attribute :somebody_elses_important_class_options
self.somebody_elses_important_class_options = { keep_me_around: true }
field :username, default: -> { "arthurnn#{rand(0..1... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/tree.rb | Ruby | mit | 3,920 | master | 215 | # frozen_string_literal: true
class Tree
include Mongoid::Document
field :name
field :evergreen, type: Mongoid::Boolean
scope :verdant, -> { where(evergreen: true) }
default_scope -> { asc(:name) }
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/vehicle.rb | Ruby | mit | 3,920 | master | 395 | # frozen_string_literal: true
class Vehicle
include Mongoid::Document
belongs_to :shipping_container
belongs_to :driver
embeds_many :crates
embeds_many :seats, cascade_callbacks: true
accepts_nested_attributes_for :driver
accepts_nested_attributes_for :shipping_container
accepts_nested_attributes_fo... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/band.rb | Ruby | mit | 3,920 | master | 1,286 | # frozen_string_literal: true
class Band
include Mongoid::Document
include Mongoid::Attributes::Dynamic
field :name, type: String
field :active, type: Mongoid::Boolean, default: true
field :origin, type: String
field :genres, type: Array
field :member_count, type: Integer
field :mems, as: :members, ty... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/birthday.rb | Ruby | mit | 3,920 | master | 342 | # frozen_string_literal: true
class Birthday
include Mongoid::Document
field :title
field :date, type: Date
embedded_in :owner, inverse_of: :birthdays
def self.each_day(start_date, end_date, &block)
groups = only(:date).asc(:date).where(:date.gte => start_date, :date.lte => end_date).group
groups.e... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/favorite.rb | Ruby | mit | 3,920 | master | 524 | # frozen_string_literal: true
class Favorite
include Mongoid::Document
field :title
validates_uniqueness_of :title, case_sensitive: false
# See MONGOID-5016. The default for `touch` is now `true` for embedded_in
# associations, which causes the referenced class to be loaded eagerly so
# the relevant call... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/pet.rb | Ruby | mit | 3,920 | master | 450 | # frozen_string_literal: true
class Pet
include Mongoid::Document
field :name
field :weight, type: Float, default: 0.0
embeds_many :vet_visits
embedded_in :pet_owner
after_destroy :set_destroy_flag
attr_writer :destroy_flag
def set_destroy_flag
@destroy_flag = true
end
def destroy_flag
... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/track.rb | Ruby | mit | 3,920 | master | 1,019 | # frozen_string_literal: true
class Track
include Mongoid::Document
field :name, type: String
field :before_create_called, type: Mongoid::Boolean, default: false
field :before_save_called, type: Mongoid::Boolean, default: false
field :before_update_called, type: Mongoid::Boolean, default: false
field :be... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/shape.rb | Ruby | mit | 3,920 | master | 259 | # frozen_string_literal: true
class Shape
include Mongoid::Document
field :x, type: Integer, default: 0
field :y, type: Integer, default: 0
embedded_in :canvas
def render; end
end
require 'support/models/circle'
require 'support/models/square' |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/face.rb | Ruby | mit | 3,920 | master | 229 | # frozen_string_literal: true
class Face
include Mongoid::Document
has_one :left_eye, class_name: 'Eye', as: :eyeable
has_one :right_eye, class_name: 'Eye', as: :eyeable
belongs_to :suspended_in, polymorphic: true
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/video.rb | Ruby | mit | 3,920 | master | 294 | # frozen_string_literal: true
class Video
include Mongoid::Document
field :title, type: String
field :year, type: Integer
field :release_dates, type: Set
field :genres, type: Array
embedded_in :person
belongs_to :post
belongs_to :game
default_scope -> { asc(:title) }
end |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/agent.rb | Ruby | mit | 3,920 | master | 466 | # frozen_string_literal: true
class Agent
include Mongoid::Document
include Mongoid::Timestamps::Updated
field :title, type: String
field :number, type: String
field :dob, type: Time
embeds_many :names, as: :namable
embeds_one :address
belongs_to :game
belongs_to :agency, touch: true, autobuild: tru... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/account.rb | Ruby | mit | 3,920 | master | 1,052 | # frozen_string_literal: true
class Account
include Mongoid::Document
field :_id, type: String, overwrite: true, default: -> { name.try(:parameterize) }
field :number, type: String
field :balance, type: Integer
field :nickname, type: String
field :name, type: String
field :balanced, type: Mongoid::Bool... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/preference.rb | Ruby | mit | 3,920 | master | 337 | # frozen_string_literal: true
class Preference
include Mongoid::Document
field :name, type: String
field :value, type: String
field :ranking, type: Integer
has_and_belongs_to_many :people, validate: false
validates_length_of :name, minimum: 2, allow_nil: true
scope :posting, -> { where(:value.in => [ 'P... |
github | mongodb/mongoid | https://github.com/mongodb/mongoid | spec/support/models/eye.rb | Ruby | mit | 3,920 | master | 202 | # frozen_string_literal: true
class Eye
include Mongoid::Document
field :pupil_dilation, type: Integer
belongs_to :eyeable, polymorphic: true
belongs_to :suspended_in, polymorphic: true
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.