code_spike 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,12 +6,12 @@
6
6
  gem install code_spike
7
7
  ```
8
8
 
9
- CodeSpike is a simple Gem for spiking ActiveRecord models. It uses an in memory sqlite3 database and requires all the necessary libs
10
- for unit testing. In addition it provides a DSL for creating the database schema as well calling test methods.
9
+ CodeSpike is a simple Gem for spiking ActiveRecord models. It uses an in memory sqlite3 database and requires all the necessary libs
10
+ for unit testing. In addition it provides a DSL for creating the database schema as well calling test methods.
11
11
 
12
12
  I created this Gem because when working on complex ActiveRecord associations, I like to hop outside of Rails to isolate the problem. Setting up
13
- ActiveRecord outside of Rails is easy enough, but the setup is a little verbose and I can never quite remember all the libraries
14
- or the exact syntax. So I spend time googling or looking back through old code, which I don't like doing if I've already solved the problem.
13
+ ActiveRecord outside of Rails is easy enough, but the setup is a little verbose and I can never quite remember all the libraries
14
+ or the exact syntax. So I spend time googling or looking back through old code, which I don't like doing if I've already solved the problem.
15
15
 
16
16
  This Gem just wraps the setup and adds a simple DSL that I can remember, so I can move right into the problem I'm working on!
17
17
 
@@ -51,10 +51,37 @@ end
51
51
  class Person < ActiveRecord::Base; end
52
52
 
53
53
  class CodeSpikeTest < ActiveSupport::TestCase
54
- teardown { ActiveRecord::Base.subclasses.each { |klass| klass.destroy_all} }
55
-
54
+ teardown { ActiveRecord::Base.subclasses.each { |klass| klass.destroy_all} }
55
+
56
56
  test "person create" do
57
57
  assert Person.create!
58
58
  end
59
59
  end
60
60
  ```
61
+
62
+ ## Using Fixtures
63
+
64
+ You can also use fixtures to load up seed data for your tests. You have to provide the directory to the YAML files. Here is an example using fixtures.
65
+
66
+ ```ruby
67
+ require 'code_spike'
68
+
69
+ # In ./companies.yml
70
+ #
71
+ # one:
72
+ # name: Gristmill
73
+ fixtures_directory '.'
74
+
75
+ schema do
76
+ create_table :companies { |t| t.string :name }
77
+ end
78
+
79
+ class Company < ActiveRecord::Base; end
80
+
81
+ units do
82
+ test "company" do
83
+ assert_equal "Gristmill", Company.first.name
84
+ end
85
+ end
86
+
87
+ ```
data/lib/code_spike.rb CHANGED
@@ -25,6 +25,15 @@ def schema(&block)
25
25
  ActiveRecord::Schema.define do
26
26
  instance_eval(&block)
27
27
  end
28
+
29
+ end
30
+
31
+ def fixtures_directory(fixtures_directory='.')
32
+ require 'active_record/fixtures'
33
+ require 'yaml'
34
+ require 'erb'
35
+
36
+ @fixtures_directory = fixtures_directory
28
37
  end
29
38
 
30
39
  class CodeSpike < ActiveSupport::TestCase
@@ -32,5 +41,9 @@ class CodeSpike < ActiveSupport::TestCase
32
41
  end
33
42
 
34
43
  def units(&block)
44
+ if defined?(@fixtures_directory)
45
+ ActiveRecord::Fixtures.create_fixtures(@fixtures_directory, Dir["*.yml"].map { |f| File.basename(f, '.*') })
46
+ end
47
+
35
48
  CodeSpike.instance_eval(&block)
36
49
  end
@@ -1,3 +1,3 @@
1
1
  module CodeSpike
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_spike
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70367016368160 !ruby/object:Gem::Requirement
16
+ requirement: &70230055741000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70367016368160
24
+ version_requirements: *70230055741000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activerecord
27
- requirement: &70367016380160 !ruby/object:Gem::Requirement
27
+ requirement: &70230055736160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.2'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70367016380160
35
+ version_requirements: *70230055736160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70367016376940 !ruby/object:Gem::Requirement
38
+ requirement: &70230055758920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '1.3'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70367016376940
46
+ version_requirements: *70230055758920
47
47
  description: Down and dirty ActiveRecord code spiking outside of Rails
48
48
  email:
49
49
  - inbox@seanbehan.com