blueprints 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), 'blueprints/plan')
3
3
  require File.join(File.dirname(__FILE__), 'blueprints/file_context')
4
4
  require File.join(File.dirname(__FILE__), 'blueprints/helper')
5
5
  require File.join(File.dirname(__FILE__), 'blueprints/errors')
6
- require File.join(File.dirname(__FILE__), 'blueprints/ar_extensions') if defined?(ActiveRecord)
7
6
  if defined? Spec or $0 =~ /script.spec$/
8
7
  require File.join(File.dirname(__FILE__), 'blueprints/rspec_extensions')
9
8
  else
@@ -17,6 +16,7 @@ module Blueprints
17
16
  ["#{path}.rb", File.join(path, "*.rb")]
18
17
  end
19
18
  end.flatten
19
+ SUPPORTED_ORMS = [:none, :active_record]
20
20
 
21
21
  DELETE_POLICIES = {:delete => "DELETE FROM %s", :truncate => "TRUNCATE %s"}
22
22
 
@@ -27,7 +27,7 @@ module Blueprints
27
27
  def self.setup(current_context)
28
28
  Plan.setup
29
29
  Plan.copy_ivars(current_context)
30
- if defined?(ActiveRecord)
30
+ unless @@orm == :none
31
31
  ActiveRecord::Base.connection.increment_open_transactions
32
32
  ActiveRecord::Base.connection.transaction_joinable = false
33
33
  ActiveRecord::Base.connection.begin_db_transaction
@@ -35,16 +35,22 @@ module Blueprints
35
35
  end
36
36
 
37
37
  def self.teardown
38
- if defined?(ActiveRecord)
38
+ unless @@orm == :none
39
39
  ActiveRecord::Base.connection.rollback_db_transaction
40
40
  ActiveRecord::Base.connection.decrement_open_transactions
41
41
  end
42
42
  end
43
43
 
44
44
  def self.load(options = {})
45
- options.assert_valid_keys(:delete_policy, :filename, :prebuild, :root)
45
+ options.assert_valid_keys(:delete_policy, :filename, :prebuild, :root, :orm)
46
+ options.symbolize_keys!
46
47
  return unless Plan.plans.empty?
47
48
 
49
+ @@orm = (options.delete(:orm) || :active_record).to_sym
50
+ raise ArgumentError, "Unsupported ORM #{@@orm}. Blueprints supports only #{SUPPORTED_ORMS.join(', ')}" unless SUPPORTED_ORMS.include?(@@orm)
51
+
52
+ require File.join(File.dirname(__FILE__), 'blueprints', 'ar_extensions') unless @@orm == :none
53
+
48
54
  @@delete_sql = DELETE_POLICIES[options[:delete_policy]] || DELETE_POLICIES[:delete]
49
55
  delete_tables
50
56
  @@framework_root = options[:root] if options[:root]
@@ -68,7 +74,7 @@ module Blueprints
68
74
  end
69
75
 
70
76
  def self.delete_tables(*args)
71
- if defined?(ActiveRecord)
77
+ unless @@orm == :none
72
78
  args = tables if args.blank?
73
79
  args.each { |t| ActiveRecord::Base.connection.delete(@@delete_sql % t) }
74
80
  end
@@ -1,9 +1,13 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe Blueprints do
4
- describe "scenario files" do
4
+ describe "constants" do
5
5
  it "should be loaded from specified dirs" do
6
- Blueprints::PLAN_FILES.should == ["blueprint.rb", "blueprint/*.rb", "blueprints.rb", "blueprints/*.rb", "spec/blueprint.rb", "spec/blueprint/*.rb", "spec/blueprints.rb", "spec/blueprints/*.rb", "test/blueprint.rb", "test/blueprint/*.rb", "test/blueprints.rb", "test/blueprints/*.rb"]
6
+ Blueprints::PLAN_FILES.should == ["blueprint.rb", "blueprint/*.rb", "blueprints.rb", "blueprints/*.rb", "spec/blueprint.rb", "spec/blueprint/*.rb", "spec/blueprints.rb", "spec/blueprints/*.rb", "test/blueprint.rb", "test/blueprint/*.rb", "test/blueprints.rb", "test/blueprints/*.rb"]
7
+ end
8
+
9
+ it "should support required ORMS" do
10
+ Blueprints::SUPPORTED_ORMS.should == [:none, :active_record]
7
11
  end
8
12
  end
9
13
 
@@ -189,7 +193,7 @@ describe Blueprints do
189
193
  build :not_existing
190
194
  }.should raise_error(Blueprints::PlanNotFoundError, "Plan(s) not found 'not_existing'")
191
195
  end
192
-
196
+
193
197
  it 'should raise ScenarioNotFoundError when scenario parent could not be found' do
194
198
  lambda {
195
199
  build :parent_not_existing
@@ -201,6 +205,13 @@ describe Blueprints do
201
205
  Blueprints::Plan.new(1)
202
206
  }.should raise_error(TypeError, "Pass plan names as strings or symbols only, cannot build plan 1")
203
207
  end
208
+
209
+ it "should raise ArgumentError when unknown ORM specified" do
210
+ Blueprints::Plan.plans.expects(:empty?).returns(true)
211
+ lambda {
212
+ Blueprints.load(:orm => :unknown)
213
+ }.should raise_error(ArgumentError, "Unsupported ORM unknown. Blueprints supports only none, active_record")
214
+ end
204
215
  end
205
216
 
206
217
  describe 'with active record blueprints extensions' do
@@ -0,0 +1,4 @@
1
+ class Tree < ActiveRecord::Base
2
+ attr_protected :size
3
+ has_many :fruits
4
+ end
@@ -5,20 +5,20 @@ begin
5
5
  rescue LoadError
6
6
  end
7
7
 
8
- Dir.chdir File.join(File.dirname(__FILE__), '..')
8
+ Dir.chdir File.join(File.dirname(__FILE__), '..', '..')
9
9
 
10
10
  ActiveRecord::Base.logger = Logger.new("debug.log")
11
11
 
12
- databases = YAML::load(IO.read("spec/db/database.yml"))
12
+ databases = YAML::load(IO.read("spec/active_record/fixtures/database.yml"))
13
13
  db_info = databases[ENV["DB"] || "test"]
14
14
  ActiveRecord::Base.establish_connection(db_info)
15
15
 
16
16
  require 'spec/autorun'
17
17
  require 'lib/blueprints'
18
- require 'spec/db/fruit'
19
- require 'spec/db/tree'
18
+ require 'spec/active_record/fixtures/fruit'
19
+ require 'spec/active_record/fixtures/tree'
20
20
 
21
21
  Spec::Runner.configure do |config|
22
22
  config.mock_with :mocha
23
- config.enable_blueprints :root => File.expand_path(File.join(File.dirname(__FILE__), '..')), :prebuild => :big_cherry
23
+ config.enable_blueprints :root => File.expand_path(File.join(File.dirname(__FILE__))), :prebuild => :big_cherry
24
24
  end
@@ -0,0 +1,7 @@
1
+ blueprint :cherry do
2
+ Fruit.new('cherry')
3
+ end
4
+
5
+ blueprint :big_cherry do
6
+ Fruit.new('cherry', 10)
7
+ end
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Blueprints do
4
+ it "should build cherry blueprint" do
5
+ build :cherry
6
+ @cherry.should_not be_nil
7
+ @cherry.should be_instance_of(Fruit)
8
+ @cherry.species.should == 'cherry'
9
+ end
10
+
11
+ it "should not build cherry if not asked" do
12
+ @cherry.should == nil
13
+ end
14
+
15
+ describe "prebuilt blueprints" do
16
+ it "big cherry should have size of 10 even if it was changed in test below" do
17
+ @big_cherry.size.should == 10
18
+ @big_cherry.size = 15
19
+ end
20
+
21
+ it "big cherry should have size of 10 even if it was changed in test above" do
22
+ @big_cherry.size.should == 10
23
+ @big_cherry.size = 13
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ class Fruit
2
+ attr_accessor :species, :size
3
+
4
+ def initialize(species, size = 5)
5
+ @species = species
6
+ @size = size
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ Dir.chdir File.join(File.dirname(__FILE__), '..', '..')
2
+
3
+ require 'spec/autorun'
4
+ require 'lib/blueprints'
5
+ require 'spec/no_db/fixtures/fruit'
6
+
7
+ Spec::Runner.configure do |config|
8
+ config.mock_with :mocha
9
+ config.enable_blueprints :root => File.expand_path(File.join(File.dirname(__FILE__))), :prebuild => :big_cherry, :orm => :none
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blueprints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrius Chamentauskas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-10 00:00:00 +03:00
12
+ date: 2009-10-11 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -70,11 +70,16 @@ signing_key:
70
70
  specification_version: 3
71
71
  summary: Another replacement for factories and fixtures
72
72
  test_files:
73
- - spec/spec_helper.rb
74
- - spec/blueprints_spec.rb
75
- - spec/blueprints.rb
76
- - spec/db/fruit.rb
77
- - spec/db/database.yml.example
78
- - spec/db/schema.rb
73
+ - spec/no_db/spec_helper.rb
74
+ - spec/no_db/blueprints_spec.rb
75
+ - spec/no_db/blueprints.rb
76
+ - spec/no_db/fixtures/fruit.rb
77
+ - spec/active_record/spec_helper.rb
78
+ - spec/active_record/blueprints_spec.rb
79
+ - spec/active_record/blueprints.rb
80
+ - spec/active_record/fixtures/fruit.rb
81
+ - spec/active_record/fixtures/tree.rb
82
+ - spec/active_record/fixtures/database.yml.example
83
+ - spec/active_record/fixtures/schema.rb
79
84
  - test/test_helper.rb
80
85
  - test/blueprints_test.rb