Permalink
Browse files

Add basic keymaker support

  • Loading branch information...
1 parent 3cff4ac commit b7a62f5102434692a2db5046ee93c57bfafa426e @paulelliott committed Oct 15, 2012
View
@@ -3,4 +3,6 @@ rvm:
- 1.9.3
- rbx-19mode
-services: mongodb
+services:
+ - mongodb
+ - neo4j
View
@@ -7,7 +7,7 @@ changes with rspec on a feature branch, and submit a pull request.
To run rake successfully:
1. Clone the project
-2. Install mongodb and sqlite3 (brew install ...)
+2. Install and run necessary databases (mongodb, neo4j, sqlite3)
3. Install bundler (gem install bundler)
4. Run `bundle` from the project root
5. Run `rake` and the test suite should be all green!
View
@@ -47,11 +47,23 @@ GEM
do_sqlite3 (~> 0.10.6)
do_sqlite3 (0.10.10)
data_objects (= 0.10.10)
+ faraday (0.8.4)
+ multipart-post (~> 1.1)
+ faraday_middleware (0.8.8)
+ faraday (>= 0.7.4, < 0.9)
ffaker (1.15.0)
gherkin (2.11.4)
json (>= 1.4.6)
+ hashie (1.2.0)
i18n (0.6.1)
json (1.7.5)
+ keymaker (0.1.0)
+ activemodel
+ activesupport
+ addressable
+ faraday
+ faraday_middleware
+ hashie
method_source (0.8)
mongoid (3.0.9)
activemodel (~> 3.1)
@@ -60,6 +72,7 @@ GEM
tzinfo (~> 0.3.22)
moped (1.2.7)
multi_json (1.3.6)
+ multipart-post (1.1.5)
origin (1.0.9)
pry (0.9.10)
coderay (~> 1.0.5)
@@ -95,6 +108,7 @@ DEPENDENCIES
dm-sqlite-adapter
fabrication!
ffaker
+ keymaker
mongoid
pry
rake
View
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
s.add_development_dependency("dm-sqlite-adapter")
s.add_development_dependency("turnip", [">= 0.3"])
s.add_development_dependency("ffaker")
+ s.add_development_dependency("keymaker")
s.add_development_dependency("mongoid")
s.add_development_dependency("pry")
s.add_development_dependency("rake")
View
@@ -23,6 +23,7 @@ module Generator
autoload :DataMapper, 'fabrication/generator/data_mapper'
autoload :Mongoid, 'fabrication/generator/mongoid'
autoload :Sequel, 'fabrication/generator/sequel'
+ autoload :Keymaker, 'fabrication/generator/keymaker'
autoload :Base, 'fabrication/generator/base'
end
@@ -0,0 +1,11 @@
+class Fabrication::Generator::Keymaker < Fabrication::Generator::Base
+
+ def self.supports?(klass)
+ defined?(Keymaker) && klass.ancestors.include?(Keymaker::Node)
+ end
+
+ def persist
+ __instance.save
+ end
+
+end
@@ -5,6 +5,7 @@ class Fabrication::Schematic::Definition
Fabrication::Generator::DataMapper,
Fabrication::Generator::Sequel,
Fabrication::Generator::Mongoid,
+ Fabrication::Generator::Keymaker,
Fabrication::Generator::Base
]
@@ -0,0 +1,8 @@
+Fabricator(:parent_keymaker_node) do
+ transient :placeholder
+ dynamic_field { |attrs| attrs[:placeholder] }
+ nil_field nil
+ number_field 5
+ string_field 'content'
+ false_field false
+end
View
@@ -155,6 +155,73 @@
it_should_behave_like 'something fabricatable'
end
+ context 'keymaker models' do
+ let(:fabricator_name) { :parent_keymaker_node }
+
+ subject { fabricated_object }
+ let(:fabricated_object) { Fabricate(fabricator_name, placeholder: 'dynamic content') }
+
+ context 'defaults from fabricator' do
+ its(:dynamic_field) { should == 'dynamic content' }
+ its(:nil_field) { should be_nil }
+ its(:number_field) { should == 5 }
+ its(:string_field) { should == 'content' }
+ its(:false_field) { should == false }
+ end
+
+ context 'model callbacks are fired' do
+ its(:before_save_value) { should == 11 }
+ end
+
+ context 'overriding at fabricate time' do
+ let(:fabricated_object) do
+ Fabricate(
+ fabricator_name,
+ string_field: 'new content',
+ number_field: 10,
+ nil_field: nil,
+ placeholder: 'is not invoked'
+ ) do
+ dynamic_field { 'new dynamic content' }
+ end
+ end
+
+ its(:dynamic_field) { should == 'new dynamic content' }
+ its(:nil_field) { should be_nil }
+ its(:number_field) { should == 10 }
+ its(:string_field) { should == 'new content' }
+ end
+
+ context 'state of the object' do
+ it 'generates a fresh object every time' do
+ Fabricate(fabricator_name).should_not == subject
+ end
+ it { should be_persisted }
+ end
+
+ context 'transient attributes' do
+ it { should_not respond_to(:placeholder) }
+ end
+
+ context 'build' do
+ subject { Fabricate.build(fabricator_name) }
+ it { should_not be_persisted }
+ end
+
+ context 'attributes for' do
+ subject { Fabricate.attributes_for(fabricator_name) }
+ it { should be_kind_of(HashWithIndifferentAccess) }
+ it 'serializes the attributes' do
+ should include({
+ :dynamic_field => nil,
+ :nil_field => nil,
+ :number_field => 5,
+ :string_field => 'content'
+ })
+ end
+ end
+ end
+
context 'when the class requires a constructor' do
subject do
Fabricate(:city) do
View
@@ -0,0 +1,19 @@
+Keymaker.configure do |c|
+ c.server = 'localhost'
+end
+
+class ParentKeymakerNode
+ include Keymaker::Node
+ property :before_save_value
+ property :dynamic_field
+ property :nil_field
+ property :number_field
+ property :string_field
+ property :false_field
+
+ attr_protected :number_field
+
+ before_save do
+ self.before_save_value = 11
+ end
+end

0 comments on commit b7a62f5

Please sign in to comment.