fixturease 0.2.9 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ desc 'Default: run unit tests.'
7
7
  task :default => :spec
8
8
 
9
9
 
10
- PKG_VERSION="0.2.9"
10
+ PKG_VERSION="0.3"
11
11
  PKG_FILES=["bin/fixturease.rb","Rakefile","spec/database.yml","spec/fixturease_spec.rb"]
12
12
 
13
13
  spec = Gem::Specification.new do |s|
data/bin/fixturease.rb CHANGED
@@ -75,6 +75,11 @@ else
75
75
  @@fixtures[self.class] ||= {}
76
76
  @@fixtures[self.class][self.id] = self unless self.new_record?
77
77
  end
78
+
79
+ alias_method :to_yaml_orig, :to_yaml
80
+ def to_yaml
81
+ id || to_yaml_orig
82
+ end
78
83
 
79
84
  def self.fixturease_fixtures
80
85
  @@fixtures
@@ -8,11 +8,19 @@ context "Fixturease" do
8
8
  FileUtils.rm_rf 'testfixtureaseproject'
9
9
  `rails testfixtureaseproject`
10
10
  FileUtils.cp File.dirname(__FILE__)+'/database.yml','testfixtureaseproject/config/database.yml'
11
- `cd testfixtureaseproject && ./script/generate model TestModel title:string`
11
+ `cd testfixtureaseproject && ./script/generate model TestModel title:string another_model_id:integer`
12
+ `cd testfixtureaseproject && ./script/generate model AnotherModel title:string`
13
+ File.open('testfixtureaseproject/app/models/test_model.rb','w') do |f|
14
+ f.write "
15
+ class TestModel < ActiveRecord::Base
16
+ belongs_to :another_model
17
+ end
18
+ "
19
+ end
12
20
  `cd testfixtureaseproject && rake db:migrate RAILS_ENV=test`
13
21
  cleanup_fixtures
14
22
  end
15
-
23
+
16
24
  teardown do
17
25
  FileUtils.rm_rf 'testfixtureaseproject'
18
26
  end
@@ -24,7 +32,7 @@ context "Fixturease" do
24
32
  f.readline until f.eof?
25
33
  end
26
34
  end
27
-
35
+
28
36
 
29
37
  specify "should create empty TestModel" do
30
38
  run_fixturease do |f|
@@ -50,6 +58,21 @@ context "Fixturease" do
50
58
  yaml[key]["title"].should == 'test title'
51
59
  end
52
60
 
61
+ specify "should create TestModel with title and another_model" do
62
+ run_fixturease do |f|
63
+ f.puts "TestModel.create :title => 'test title', :another_model => AnotherModel.create(:title=>'hello')"
64
+ f.puts "exit"
65
+ f.readline until f.eof?
66
+ end
67
+ ayaml = YAML::load_file("testfixtureaseproject/test/fixtures/another_models.yml")
68
+ yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
69
+ yaml.keys.should_have(1).grep(/test_models_(\d)+/)
70
+ key = yaml.keys.grep(/test_models_(\d)+/).first
71
+ akey = ayaml.keys.grep(/another_models_(\d)+/).first
72
+ yaml[key]["title"].should == 'test title'
73
+ yaml[key]["another_model_id"].should == ayaml[akey]["id"]
74
+ end
75
+
53
76
  specify "should not create destroyed model" do
54
77
  run_fixturease do |f|
55
78
  f.puts "@test1 = TestModel.create :title => 'test title'"
@@ -64,24 +87,24 @@ context "Fixturease" do
64
87
  end
65
88
 
66
89
  specify "should not create unsaved model" do
67
- run_fixturease do |f|
68
- f.puts "@test1 = TestModel.new :title => 'test title'"
69
- f.puts "exit"
70
- f.readline until f.eof?
71
- end
72
- yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
73
- yaml.should == false
74
- end
75
-
76
- specify "should ignore non-ActiveRecord instance variables" do
77
- run_fixturease do |f|
78
- f.puts "@test1 = 1"
79
- f.puts "exit"
80
- f.readline until f.eof?
81
- end
82
- yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
83
- yaml.should == false
84
- end
90
+ run_fixturease do |f|
91
+ f.puts "@test1 = TestModel.new :title => 'test title'"
92
+ f.puts "exit"
93
+ f.readline until f.eof?
94
+ end
95
+ yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
96
+ yaml.should == false
97
+ end
98
+
99
+ specify "should ignore non-ActiveRecord instance variables" do
100
+ run_fixturease do |f|
101
+ f.puts "@test1 = 1"
102
+ f.puts "exit"
103
+ f.readline until f.eof?
104
+ end
105
+ yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
106
+ yaml.should == false
107
+ end
85
108
 
86
109
  specify "should create named model according to instance variable name" do
87
110
  run_fixturease do |f|
@@ -129,7 +152,7 @@ context "Fixturease" do
129
152
  new_yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
130
153
  new_yaml.should == original_yaml
131
154
  end
132
-
155
+
133
156
  specify "should rewrite fixtures from scratch with altered models if load_fixtures!" do
134
157
  run_fixturease do |f|
135
158
  f.puts "@test = TestModel.create :title => 'test title'"
@@ -184,7 +207,7 @@ context "Fixturease" do
184
207
  def cleanup_fixtures()
185
208
  `echo -n > testfixtureaseproject/test/fixtures/test_models.yml`
186
209
  end
187
-
210
+
188
211
  def run_fixturease(stropt=nil,&block)
189
212
  ENV['RAILS_ROOT']='testfixtureaseproject'
190
213
  ENV['FIXTURES_ROOT']='test/fixtures'
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: fixturease
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.9
7
- date: 2007-02-04 00:00:00 +02:00
6
+ version: "0.3"
7
+ date: 2007-02-05 00:00:00 +02:00
8
8
  summary: Easy fixture creation tool
9
9
  require_paths:
10
10
  - lib