blueprints_boy 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +20 -0
- data/Appraisals +37 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +26 -0
- data/Rakefile +76 -0
- data/blueprints_boy.gemspec +27 -0
- data/gemfiles/ar3.1.gemfile +8 -0
- data/gemfiles/ar3.2.gemfile +8 -0
- data/gemfiles/ar4.0.gemfile +8 -0
- data/gemfiles/ar4.1.gemfile +8 -0
- data/gemfiles/mongoid2.gemfile +8 -0
- data/gemfiles/mongoid3.gemfile +8 -0
- data/gemfiles/mongoid4.gemfile +8 -0
- data/gemfiles/noorm.gemfile +5 -0
- data/integration/active_record/active_record_spec.rb +38 -0
- data/integration/active_record/active_record_truncation_spec.rb +26 -0
- data/integration/active_record/blueprints.rb +1 -0
- data/integration/active_record/setup.rb +8 -0
- data/integration/cucumber/blueprints.feature +20 -0
- data/integration/cucumber/step_definitions/blueprints_steps.rb +17 -0
- data/integration/cucumber/support/env.rb +11 -0
- data/integration/minitest/blueprints.rb +11 -0
- data/integration/minitest/test_minispec.rb +41 -0
- data/integration/minitest/test_minitest.rb +28 -0
- data/integration/mongoid/blueprints.rb +1 -0
- data/integration/mongoid/mongoid_spec.rb +50 -0
- data/integration/rspec/blueprints.rb +13 -0
- data/integration/rspec/rspec_spec.rb +113 -0
- data/integration/shared.rb +9 -0
- data/lib/blueprints_boy/blueprint.rb +59 -0
- data/lib/blueprints_boy/configuration.rb +48 -0
- data/lib/blueprints_boy/context.rb +53 -0
- data/lib/blueprints_boy/dependency.rb +23 -0
- data/lib/blueprints_boy/errors.rb +10 -0
- data/lib/blueprints_boy/factories.rb +18 -0
- data/lib/blueprints_boy/helper.rb +47 -0
- data/lib/blueprints_boy/integration/active_record.rb +11 -0
- data/lib/blueprints_boy/integration/cucumber.rb +9 -0
- data/lib/blueprints_boy/integration/minitest.rb +23 -0
- data/lib/blueprints_boy/integration/mongoid.rb +11 -0
- data/lib/blueprints_boy/integration/rspec.rb +20 -0
- data/lib/blueprints_boy/manager.rb +87 -0
- data/lib/blueprints_boy/railtie.rb +24 -0
- data/lib/blueprints_boy/registry.rb +28 -0
- data/lib/blueprints_boy/version.rb +3 -0
- data/lib/blueprints_boy.rb +62 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/empty_file.rb +0 -0
- data/spec/support/fixtures.rb +41 -0
- data/spec/support/manager_fixture.rb +3 -0
- data/spec/unit/blueprint_spec.rb +102 -0
- data/spec/unit/blueprints_boy_spec.rb +15 -0
- data/spec/unit/configuration_spec.rb +41 -0
- data/spec/unit/context_spec.rb +145 -0
- data/spec/unit/dependency_spec.rb +56 -0
- data/spec/unit/factories_spec.rb +27 -0
- data/spec/unit/manager_spec.rb +122 -0
- data/spec/unit/registry_spec.rb +47 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a3ca13ff47fec410475c77e1185dbb93aad17785
|
4
|
+
data.tar.gz: 24d8f27acfd26e20dec56e97b5d9aebcaf84d854
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be15bd8f770fec456edf7f999c52d4fe88546a798f45d6a9d4cf96a0ec2282b6dbbc868fc4b2973144d6909f68196d450148cfb2c71b748087960549aa3b80e2
|
7
|
+
data.tar.gz: 3edd975c2a024aab7720c9e6253b9b2d31c93d4705cf56e3109e5dcb898d7415dd3df8b7de11c6a588dd105a77502b2128a87946298fbeeb8f563fbfbbceaf37
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.3
|
6
|
+
- rbx
|
7
|
+
gemfile:
|
8
|
+
- Gemfile
|
9
|
+
- gemfiles/ar3.1.gemfile
|
10
|
+
- gemfiles/ar3.2.gemfile
|
11
|
+
- gemfiles/ar4.0.gemfile
|
12
|
+
- gemfiles/ar4.1.gemfile
|
13
|
+
- gemfiles/mongoid2.gemfile
|
14
|
+
- gemfiles/mongoid3.gemfile
|
15
|
+
- gemfiles/mongoid4.gemfile
|
16
|
+
- gemfiles/noorm.gemfile
|
17
|
+
services:
|
18
|
+
- mongodb
|
19
|
+
before_script:
|
20
|
+
- mysql -e 'create database blueprints_boy_test;'
|
data/Appraisals
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
appraise "ar3.1" do
|
2
|
+
gem "activerecord", "~> 3.1.12"
|
3
|
+
gem 'mysql2'
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise "ar3.2" do
|
7
|
+
gem "activerecord", "~> 3.2.15"
|
8
|
+
gem 'mysql2'
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise "ar4.0" do
|
12
|
+
gem "activerecord", "~> 4.0.0"
|
13
|
+
gem 'mysql2'
|
14
|
+
end
|
15
|
+
|
16
|
+
appraise "ar4.1" do
|
17
|
+
gem "activerecord", "~> 4.1.0"
|
18
|
+
gem 'mysql2'
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise "mongoid2" do
|
22
|
+
gem "mongoid", "~> 2.0"
|
23
|
+
gem 'bson_ext'
|
24
|
+
end
|
25
|
+
|
26
|
+
appraise "mongoid3" do
|
27
|
+
gem "mongoid", "~> 3.0"
|
28
|
+
gem 'bson_ext'
|
29
|
+
end
|
30
|
+
|
31
|
+
appraise "mongoid4" do
|
32
|
+
gem "mongoid", "~> 4.0"
|
33
|
+
gem 'bson_ext'
|
34
|
+
end
|
35
|
+
|
36
|
+
appraise "noorm" do
|
37
|
+
end
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Andrius Chamentauskas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
BlueprintsBoy
|
2
|
+
========
|
3
|
+
|
4
|
+
[](https://travis-ci.org/andriusch/blueprints_boy)
|
5
|
+
[](https://codeclimate.com/repos/52744bde13d6377312003e29/feed)
|
6
|
+
|
7
|
+
The ultimate DRY and fast solution to loading test data in Ruby and Rails. Blueprints allows you to create and manage
|
8
|
+
data for tests in simple but powerful ways.
|
9
|
+
|
10
|
+
Documentation
|
11
|
+
-------------
|
12
|
+
|
13
|
+
For documentation please visit [andriusch.github.com/blueprints_boy](http://andriusch.github.com/blueprints_boy)
|
14
|
+
|
15
|
+
Credits
|
16
|
+
-------
|
17
|
+
|
18
|
+
Andrius Chamentauskas <andrius.chamentauskas@gmail.com>
|
19
|
+
|
20
|
+
Some ideas are based on hornsby scenario plugin by Lachie Cox, which was based on code found on
|
21
|
+
[errtheblog.com/posts/61-fixin-fixtures](http://errtheblog.com/posts/61-fixin-fixtures)
|
22
|
+
|
23
|
+
License
|
24
|
+
-------
|
25
|
+
|
26
|
+
MIT, see LICENCE
|
data/Rakefile
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require 'appraisal'
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'rake/testtask'
|
7
|
+
require 'cucumber/rake/task'
|
8
|
+
|
9
|
+
namespace :spec do
|
10
|
+
RSpec::Core::RakeTask.new(:unit) do |t|
|
11
|
+
t.pattern = "spec/unit/**/*_spec.rb"
|
12
|
+
end
|
13
|
+
RSpec::Core::RakeTask.new(:rspec) do |t|
|
14
|
+
t.pattern = "integration/rspec/rspec_spec.rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec::Core::RakeTask.new(:active_record => 'prepare:active_record') do |t|
|
18
|
+
t.pattern = "integration/active_record/active_record_spec.rb"
|
19
|
+
end
|
20
|
+
RSpec::Core::RakeTask.new(:active_record_truncation => 'prepare:active_record') do |t|
|
21
|
+
t.pattern = "integration/active_record/active_record_truncation_spec.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec::Core::RakeTask.new(:mongoid) do |t|
|
25
|
+
t.pattern = "integration/mongoid/mongoid_spec.rb"
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::TestTask.new(:minitest) do |t|
|
29
|
+
t.pattern = "integration/minitest/test_*.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
Cucumber::Rake::Task.new(:cucumber) do |t|
|
33
|
+
t.cucumber_opts = "integration/cucumber --format pretty"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
namespace :prepare do
|
38
|
+
desc "Prepare database schema for active record"
|
39
|
+
task :active_record do
|
40
|
+
require_relative 'integration/active_record/setup'
|
41
|
+
ActiveRecord::Schema.define(:version => 0) do
|
42
|
+
create_table :fruits, :force => true do |t|
|
43
|
+
t.string :species
|
44
|
+
t.integer :size
|
45
|
+
t.belongs_to :parent
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'Run all specs'
|
52
|
+
task :spec do
|
53
|
+
def find_gem(name)
|
54
|
+
Bundler.setup.specs.find { |spec| spec.name == name }
|
55
|
+
end
|
56
|
+
|
57
|
+
def run(task)
|
58
|
+
puts "Running #{task}"
|
59
|
+
Rake::Task[task].invoke
|
60
|
+
puts "\n\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
if find_gem('activerecord')
|
64
|
+
run 'spec:active_record'
|
65
|
+
run 'spec:active_record_truncation'
|
66
|
+
elsif find_gem('mongoid')
|
67
|
+
run 'spec:mongoid'
|
68
|
+
else
|
69
|
+
run 'spec:rspec'
|
70
|
+
run 'spec:minitest'
|
71
|
+
run 'spec:unit'
|
72
|
+
run 'spec:cucumber'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
task :default => :spec
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "blueprints_boy/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "blueprints_boy"
|
7
|
+
s.version = BlueprintsBoy::VERSION
|
8
|
+
s.authors = ["Andrius Chamentauskas"]
|
9
|
+
s.email = ["andrius.chamentauskas@gmail.com"]
|
10
|
+
s.homepage = "http://andriusch.github.io/blueprints_boy/"
|
11
|
+
s.summary = %q{The ultimate solution to managing test data.}
|
12
|
+
s.description = %q{The ultimate DRY and fast solution to managing any kind of test data. Based on Blueprints.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "blueprints_boy"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "cucumber"
|
24
|
+
s.add_development_dependency "appraisal"
|
25
|
+
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
26
|
+
s.add_runtime_dependency "database_cleaner"
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
require 'rspec'
|
3
|
+
require 'blueprints_boy'
|
4
|
+
require_relative '../shared'
|
5
|
+
|
6
|
+
BlueprintsBoy.enable do |config|
|
7
|
+
config.root = File.dirname(__FILE__)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ActiveRecord::Base do
|
11
|
+
it "should create record in database" do
|
12
|
+
build :apple
|
13
|
+
apple.should be_a(ARFruit)
|
14
|
+
apple.should be_persisted
|
15
|
+
apple.species.should == 'apple'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should clean database before each test" do
|
19
|
+
ARFruit.all.should == []
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should use transactions for cleaning database" do
|
23
|
+
ActiveRecord::Base.connection.open_transactions.should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should allow building using :new strategy" do
|
27
|
+
build_with :new, :apple
|
28
|
+
apple.should be_a(ARFruit)
|
29
|
+
apple.should be_new_record
|
30
|
+
apple.species.should == 'apple'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should allow updating built blueprint" do
|
34
|
+
build :apple
|
35
|
+
build :apple => {species: 'orange'}
|
36
|
+
apple.reload.species.should == 'orange'
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
require 'rspec'
|
3
|
+
require 'blueprints_boy'
|
4
|
+
require_relative '../shared'
|
5
|
+
|
6
|
+
BlueprintsBoy.enable do |config|
|
7
|
+
config.root = File.dirname(__FILE__)
|
8
|
+
config.transactions = false
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ActiveRecord::Base do
|
12
|
+
it "should create record in database" do
|
13
|
+
build :apple
|
14
|
+
apple.should be_a(ARFruit)
|
15
|
+
apple.should be_persisted
|
16
|
+
apple.species.should == 'apple'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should clean database before each test" do
|
20
|
+
ARFruit.all.should == []
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should use transactions for cleaning database" do
|
24
|
+
ActiveRecord::Base.connection.open_transactions.should == 0
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
factory(ARFruit).blueprint :apple, species: 'apple'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'mysql2'
|
3
|
+
ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'blueprints_boy_test')
|
4
|
+
|
5
|
+
class ARFruit < ActiveRecord::Base
|
6
|
+
self.table_name = 'fruits'
|
7
|
+
attr_protected :species if ActiveRecord::VERSION::MAJOR < 4
|
8
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Feature: blueprints
|
2
|
+
In order to use blueprints with cucumber
|
3
|
+
As a developer
|
4
|
+
I should be able build blueprints with correct data
|
5
|
+
|
6
|
+
Scenario: build cherry
|
7
|
+
Given I have apple
|
8
|
+
Then apple should be available
|
9
|
+
And apple should equal "apple"
|
10
|
+
|
11
|
+
Scenario: no cherry
|
12
|
+
Then apple should NOT be available
|
13
|
+
|
14
|
+
Scenario: global cherry prebuild
|
15
|
+
When global_cherry should equal "cherry"
|
16
|
+
Then I change global_cherry
|
17
|
+
|
18
|
+
Scenario: global cherry another prebuild
|
19
|
+
When global_cherry should equal "cherry"
|
20
|
+
Then I change global_cherry
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Given /^I have (\w+)$/ do |name|
|
2
|
+
build name.to_sym
|
3
|
+
end
|
4
|
+
Then /^(\w+) should (NOT )?be available$/ do |name, negative|
|
5
|
+
data = blueprint_data(name.to_sym)
|
6
|
+
if negative
|
7
|
+
expect(data).to be_nil
|
8
|
+
else
|
9
|
+
expect(data).not_to be_nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
When /^(\w+) should equal "([^\"]*)"/ do |name, value|
|
13
|
+
expect(send(name)).to eq(value)
|
14
|
+
end
|
15
|
+
Then /^I change global_cherry$/ do
|
16
|
+
global_cherry << ' modified'
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'cucumber'
|
3
|
+
require 'blueprints_boy'
|
4
|
+
|
5
|
+
# Comment out the next two lines if you're not using RSpec's matchers (should / should_not) in your steps.
|
6
|
+
#require 'cucumber/rspec'
|
7
|
+
|
8
|
+
BlueprintsBoy.enable do |config|
|
9
|
+
config.root = File.expand_path("../../../rspec", __FILE__)
|
10
|
+
config.global = :global_cherry
|
11
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'blueprints_boy'
|
5
|
+
|
6
|
+
BlueprintsBoy.enable do |config|
|
7
|
+
config.root = File.dirname(__FILE__)
|
8
|
+
config.global = :global_cherry
|
9
|
+
end
|
10
|
+
|
11
|
+
describe BlueprintsBoy do
|
12
|
+
describe "build" do
|
13
|
+
it "allows building blueprint" do
|
14
|
+
build :apple
|
15
|
+
apple.must_equal 'apple'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not allow to reach blueprints from previous specs" do
|
19
|
+
blueprint_data(:apple).must_be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "allows building same blueprint in another spec" do
|
23
|
+
build :apple
|
24
|
+
apple.must_equal 'apple'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "class level set" do
|
29
|
+
build :apple
|
30
|
+
|
31
|
+
it "should build blueprints in before filter" do
|
32
|
+
apple.must_equal 'apple'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "global" do
|
37
|
+
it "should build global blueprints" do
|
38
|
+
global_cherry.must_equal 'cherry'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'blueprints_boy'
|
4
|
+
|
5
|
+
BlueprintsBoy.enable do |config|
|
6
|
+
config.root = File.dirname(__FILE__)
|
7
|
+
config.global = :global_cherry
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestMinitest < MiniTest::Test
|
11
|
+
def test_build
|
12
|
+
build :apple
|
13
|
+
assert_equal 'apple', apple
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_clearup
|
17
|
+
assert_nil blueprint_data(:apple)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_build_again
|
21
|
+
build :apple
|
22
|
+
assert_equal 'apple', apple
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_global
|
26
|
+
assert_equal 'cherry', global_cherry
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
factory(MongoidFruit).blueprint :apple, species: 'apple'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'mongoid'
|
3
|
+
require_relative '../shared'
|
4
|
+
|
5
|
+
class MongoidFruit
|
6
|
+
include Mongoid::Document
|
7
|
+
|
8
|
+
field :species
|
9
|
+
field :size, :type => Integer
|
10
|
+
|
11
|
+
attr_protected :species if Mongoid::VERSION.to_i < 4
|
12
|
+
end
|
13
|
+
|
14
|
+
Mongoid.configure.logger = Logger.new(File.expand_path('../debug.log', __FILE__))
|
15
|
+
if Mongoid.configure.respond_to?(:connect_to)
|
16
|
+
Mongoid.configure.connect_to 'blueprints_test'
|
17
|
+
else
|
18
|
+
Mongoid.configure.from_hash 'database' => 'blueprints_test'
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'blueprints_boy'
|
22
|
+
BlueprintsBoy.enable do |config|
|
23
|
+
config.root = File.dirname(__FILE__)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Mongoid do
|
27
|
+
it "should create record in database" do
|
28
|
+
build :apple
|
29
|
+
apple.should be_a(MongoidFruit)
|
30
|
+
apple.should be_persisted
|
31
|
+
apple.species.should == 'apple'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should clean database before each test" do
|
35
|
+
MongoidFruit.all.to_a.should == []
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should allow building using :new strategy" do
|
39
|
+
build_with :new, :apple
|
40
|
+
apple.should be_a(MongoidFruit)
|
41
|
+
apple.should be_new_record
|
42
|
+
apple.species.should == 'apple'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should allow updating built blueprint" do
|
46
|
+
build :apple
|
47
|
+
build :apple => {species: 'orange'}
|
48
|
+
apple.reload.species.should == 'orange'
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
blueprint :apple do
|
2
|
+
'apple'
|
3
|
+
end
|
4
|
+
|
5
|
+
attributes(name: 'orange').blueprint(:orange) do |data|
|
6
|
+
data.attributes[:name]
|
7
|
+
end.blueprint(:new) do |data|
|
8
|
+
"new #{data.attributes[:name]}"
|
9
|
+
end
|
10
|
+
|
11
|
+
blueprint :global_cherry, name: 'cherry' do |data|
|
12
|
+
data.attributes[:name]
|
13
|
+
end
|