mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Basic mongoid integration spec
This commit is contained in:
parent
4d0181fb9c
commit
8b0150317d
6 changed files with 105 additions and 10 deletions
6
Gemfile
6
Gemfile
|
@ -14,10 +14,16 @@ end
|
||||||
case ENV["RAILS_VERSION"]
|
case ENV["RAILS_VERSION"]
|
||||||
when "master"
|
when "master"
|
||||||
gem "rails", github: "rails/rails"
|
gem "rails", github: "rails/rails"
|
||||||
|
gem "mongoid", github: "mongoid/mongoid", branch: "4.0.0-dev"
|
||||||
|
|
||||||
when "3.2", nil
|
when "3.2", nil
|
||||||
gem "rails", "~> 3.2.0"
|
gem "rails", "~> 3.2.0"
|
||||||
|
gem "mongoid", "~> 3.0.0"
|
||||||
|
|
||||||
when "3.1"
|
when "3.1"
|
||||||
gem "rails", "~> 3.1.0"
|
gem "rails", "~> 3.1.0"
|
||||||
|
gem "mongoid", "~> 3.0.0"
|
||||||
|
|
||||||
when "3.0"
|
when "3.0"
|
||||||
gem "rails", "~> 3.0.0"
|
gem "rails", "~> 3.0.0"
|
||||||
end
|
end
|
||||||
|
|
5
spec/dummy/app/models/mongoid_post.rb
Normal file
5
spec/dummy/app/models/mongoid_post.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
if defined?(Mongoid)
|
||||||
|
class MongoidPost
|
||||||
|
include Mongoid::Document
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,9 +1,8 @@
|
||||||
require File.expand_path('../boot', __FILE__)
|
require File.expand_path('../boot', __FILE__)
|
||||||
|
|
||||||
require 'rails/all'
|
require 'rails/all'
|
||||||
|
require 'draper'
|
||||||
Bundler.require
|
require 'mongoid' if Rails.version.to_f >= 3.1
|
||||||
require "draper"
|
|
||||||
|
|
||||||
module Dummy
|
module Dummy
|
||||||
class Application < Rails::Application
|
class Application < Rails::Application
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
|
|
||||||
|
|
||||||
if File.exist?(gemfile)
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
|
||||||
ENV['BUNDLE_GEMFILE'] = gemfile
|
|
||||||
require 'bundler'
|
|
||||||
Bundler.setup
|
|
||||||
end
|
|
||||||
|
|
||||||
$:.unshift File.expand_path('../../../../lib', __FILE__)
|
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||||
|
|
80
spec/dummy/config/mongoid.yml
Normal file
80
spec/dummy/config/mongoid.yml
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
development:
|
||||||
|
# Configure available database sessions. (required)
|
||||||
|
sessions:
|
||||||
|
# Defines the default session. (required)
|
||||||
|
default:
|
||||||
|
# Defines the name of the default database that Mongoid can connect to.
|
||||||
|
# (required).
|
||||||
|
database: dummy_development
|
||||||
|
# Provides the hosts the default session can connect to. Must be an array
|
||||||
|
# of host:port pairs. (required)
|
||||||
|
hosts:
|
||||||
|
- localhost:27017
|
||||||
|
options:
|
||||||
|
# Change whether the session persists in safe mode by default.
|
||||||
|
# (default: false)
|
||||||
|
# safe: false
|
||||||
|
|
||||||
|
# Change the default consistency model to :eventual or :strong.
|
||||||
|
# :eventual will send reads to secondaries, :strong sends everything
|
||||||
|
# to master. (default: :eventual)
|
||||||
|
# consistency: :eventual
|
||||||
|
|
||||||
|
# How many times Moped should attempt to retry an operation after
|
||||||
|
# failure. (default: 30)
|
||||||
|
# max_retries: 30
|
||||||
|
|
||||||
|
# The time in seconds that Moped should wait before retrying an
|
||||||
|
# operation on failure. (default: 1)
|
||||||
|
# retry_interval: 1
|
||||||
|
# Configure Mongoid specific options. (optional)
|
||||||
|
options:
|
||||||
|
# Configuration for whether or not to allow access to fields that do
|
||||||
|
# not have a field definition on the model. (default: true)
|
||||||
|
# allow_dynamic_fields: true
|
||||||
|
|
||||||
|
# Enable the identity map, needed for eager loading. (default: false)
|
||||||
|
# identity_map_enabled: false
|
||||||
|
|
||||||
|
# Includes the root model name in json serialization. (default: false)
|
||||||
|
# include_root_in_json: false
|
||||||
|
|
||||||
|
# Include the _type field in serializaion. (default: false)
|
||||||
|
# include_type_for_serialization: false
|
||||||
|
|
||||||
|
# Preload all models in development, needed when models use
|
||||||
|
# inheritance. (default: false)
|
||||||
|
# preload_models: false
|
||||||
|
|
||||||
|
# Protect id and type from mass assignment. (default: true)
|
||||||
|
# protect_sensitive_fields: true
|
||||||
|
|
||||||
|
# Raise an error when performing a #find and the document is not found.
|
||||||
|
# (default: true)
|
||||||
|
# raise_not_found_error: true
|
||||||
|
|
||||||
|
# Raise an error when defining a scope with the same name as an
|
||||||
|
# existing method. (default: false)
|
||||||
|
# scope_overwrite_exception: false
|
||||||
|
|
||||||
|
# Skip the database version check, used when connecting to a db without
|
||||||
|
# admin access. (default: false)
|
||||||
|
# skip_version_check: false
|
||||||
|
|
||||||
|
# User Active Support's time zone in conversions. (default: true)
|
||||||
|
# use_activesupport_time_zone: true
|
||||||
|
|
||||||
|
# Ensure all times are UTC in the app side. (default: false)
|
||||||
|
# use_utc: false
|
||||||
|
test:
|
||||||
|
sessions:
|
||||||
|
default:
|
||||||
|
database: dummy_test
|
||||||
|
hosts:
|
||||||
|
- localhost:27017
|
||||||
|
options:
|
||||||
|
consistency: :strong
|
||||||
|
# In the test environment we lower the retries and retry interval to
|
||||||
|
# low amounts for fast failures.
|
||||||
|
max_retries: 1
|
||||||
|
retry_interval: 0
|
10
spec/dummy/spec/models/mongoid_post_spec.rb
Normal file
10
spec/dummy/spec/models/mongoid_post_spec.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
if defined?(Mongoid)
|
||||||
|
describe MongoidPost do
|
||||||
|
it "is decoratable" do
|
||||||
|
expect(MongoidPost).to respond_to :decorator_class
|
||||||
|
expect(MongoidPost.new).to respond_to :decorate
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue