temping 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/README.md CHANGED
@@ -17,6 +17,7 @@ Temping is used to create temporary table-backed ActiveRecord models for use in
17
17
  def popular?
18
18
  view_count > 100
19
19
  end
20
+ end
20
21
  end
21
22
 
22
23
  describe "#popular" do
@@ -33,7 +34,7 @@ Temping is used to create temporary table-backed ActiveRecord models for use in
33
34
 
34
35
  end
35
36
 
36
- This is especially useful if testing an ActiveRecord plugin or a Module used in a Rails application:
37
+ This is especially useful if testing an ActiveRecord plugin or a module used in a Rails application to decouple your module's tests from a concrete implementation.
37
38
 
38
39
  include Temping
39
40
 
@@ -43,4 +44,6 @@ This is especially useful if testing an ActiveRecord plugin or a Module used in
43
44
  end
44
45
  end
45
46
 
46
- describe "HasArticles tests"...
47
+ describe "HasArticles tests"...
48
+
49
+ By default, temping will use whichever connection ActiveRecord::Base has defined. If none exists, it'll use an in-memory SQLite3 instance.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/lib/temping.rb CHANGED
@@ -1,11 +1,20 @@
1
1
  require 'active_record'
2
- require 'active_support'
3
2
 
4
3
  module Temping
5
- def create_model(model_name, &block)
6
- unless eval("defined?(#{model_name.to_s.classify})")
7
- ModelFactory.new(model_name, &block).klass
4
+ ModelAlreadyDefined = Class.new(StandardError)
5
+
6
+ def self.included(base)
7
+ ActiveRecord::Base.configurations['temping'] = { :adapter => 'sqlite3', :database => ':memory:' }
8
+ ActiveRecord::Base.establish_connection 'temping' unless ActiveRecord::Base.connected?
9
+ end
10
+
11
+ def create_model(model_name, &block)
12
+ if eval("defined?(#{model_name.to_s.classify})")
13
+ raise ModelAlreadyDefined, "Constant #{model_name.to_s.classify} is already defined"
8
14
  end
15
+
16
+ factory = ModelFactory.new(model_name, &block)
17
+ factory.klass
9
18
  end
10
19
 
11
20
  class ModelFactory
data/spec/spec_helper.rb CHANGED
@@ -11,10 +11,5 @@ ActiveRecord::Base.configurations = {
11
11
 
12
12
  'postgres' => { :adapter => 'postgresql',
13
13
  :database => 'activerecord_unittest',
14
- :min_messages => 'warning' },
15
-
16
- 'sqlite3' => { :adapter => 'sqlite3',
17
- :database => ':memory:' }
18
- }
19
-
20
- ActiveRecord::Base.establish_connection 'mysql'
14
+ :min_messages => 'warning' }
15
+ }
data/spec/temping_spec.rb CHANGED
@@ -25,6 +25,10 @@ describe Temping do
25
25
  vote.should be_valid
26
26
  end
27
27
 
28
+ it "raises ModelAlreadyDefined if a const is already defined" do
29
+ lambda { 2.times { create_model :dogs }}.should raise_error(Temping::ModelAlreadyDefined)
30
+ end
31
+
28
32
  describe ".with_columns" do
29
33
  it "creates columns passed in through a block" do
30
34
  create_model :comments do
@@ -41,6 +45,11 @@ describe Temping do
41
45
  end
42
46
 
43
47
  describe "database agnostism" do
48
+ it "supports Sqlite3" do
49
+ ActiveRecord::Base.establish_connection 'temping'
50
+ create_model(:oranges).should == Orange
51
+ end
52
+
44
53
  it "supports MySQL" do
45
54
  ActiveRecord::Base.establish_connection 'mysql'
46
55
  create_model(:apples).should == Apple
@@ -50,10 +59,5 @@ describe Temping do
50
59
  ActiveRecord::Base.establish_connection 'postgres'
51
60
  create_model(:cherries).should == Cherry
52
61
  end
53
-
54
- it "supports Sqlite3" do
55
- ActiveRecord::Base.establish_connection 'sqlite3'
56
- create_model(:oranges).should == Orange
57
- end
58
62
  end
59
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temping
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Pignata
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-15 00:00:00 -05:00
12
+ date: 2009-12-17 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,6 +41,7 @@ extensions: []
41
41
  extra_rdoc_files:
42
42
  - README.md
43
43
  files:
44
+ - .gitignore
44
45
  - README.md
45
46
  - Rakefile
46
47
  - VERSION