fixturease 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'rake/gempackagetask'
2
2
  require 'rubygems'
3
3
 
4
- PKG_VERSION="0.2.2"
5
- PKG_FILES=["bin/fixturease.rb","Rakefile"]
4
+ PKG_VERSION="0.2.3"
5
+ PKG_FILES=["bin/fixturease.rb","Rakefile","spec/database.yml","spec/fixturease_spec.rb"]
6
6
 
7
7
  spec = Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
data/bin/fixturease.rb CHANGED
@@ -35,7 +35,7 @@ else
35
35
  print "#{k} [#{filename}]: "
36
36
  v = {}
37
37
  val.each_pair {|rec_id,obj| v[rec_id] = obj if k.exists?(rec_id) }
38
- puts v.keys.collect{|rec_id| o = k.find(rec_id) ; vars[o] ? vars[o] : rec_id}.to_sentence
38
+ puts v.keys.collect{|rec_id| vars[k.find(rec_id)] || rec_id}.to_sentence
39
39
  f = File.new("#{filename}","a")
40
40
  f.write "\n\n# Fixturease (#{Time.now}):\n\n"
41
41
  f.write v.values.inject({}) { |hsh, record| hsh.merge(vars[record] || "#{k.table_name}_#{record.id}" => record.attributes) }.to_yaml(:SortKeys => true).gsub(/^---.*\n/,"")
data/spec/database.yml ADDED
@@ -0,0 +1,20 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: testfixtureaseproject_development
4
+ username: root
5
+ password:
6
+ host: localhost
7
+
8
+ test:
9
+ adapter: sqlite3
10
+ database: testfixtureaseproject_test
11
+ username: root
12
+ password:
13
+ host: localhost
14
+
15
+ production:
16
+ adapter: sqlite3
17
+ database: testfixtureaseproject_production
18
+ username: root
19
+ password:
20
+ host: localhost
@@ -0,0 +1,113 @@
1
+ require 'yaml'
2
+ require 'fileutils'
3
+
4
+ context "Fixturease" do
5
+
6
+
7
+ setup do
8
+ FileUtils.rm_rf 'testfixtureaseproject'
9
+ `rails testfixtureaseproject`
10
+ FileUtils.cp File.dirname(__FILE__)+'/database.yml','testfixtureaseproject/config/database.yml'
11
+ `cd testfixtureaseproject && ./script/generate model TestModel title:string`
12
+ `cd testfixtureaseproject && rake db:migrate RAILS_ENV=test`
13
+ end
14
+
15
+ teardown do
16
+ FileUtils.rm_rf 'testfixtureaseproject'
17
+ end
18
+
19
+ specify "should say greeting on the start" do
20
+ run_fixturease do |f|
21
+ f.readline.should == "Loading Fixturease console for test mode.\n"
22
+ f.puts "exit"
23
+ f.readline until f.eof?
24
+ end
25
+ end
26
+
27
+
28
+ specify "should create simple model (without columns)" do
29
+ `echo -n > testfixtureaseproject/test/fixtures/test_models.yml`
30
+ run_fixturease do |f|
31
+ f.puts "TestModel.create"
32
+ f.puts "exit"
33
+ f.readline until f.eof?
34
+ end
35
+ yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
36
+ yaml.keys.should_have(1).grep(/test_models_(\d)+/)
37
+ key = yaml.keys.grep(/test_models_(\d)+/).first
38
+ yaml[key]["id"].should_not_be_nil
39
+ end
40
+
41
+ specify "should create model (with title)" do
42
+ `echo -n > testfixtureaseproject/test/fixtures/test_models.yml`
43
+ run_fixturease do |f|
44
+ f.puts "TestModel.create :title => 'test title'"
45
+ f.puts "exit"
46
+ f.readline until f.eof?
47
+ end
48
+ yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
49
+ yaml.keys.should_have(1).grep(/test_models_(\d)+/)
50
+ key = yaml.keys.grep(/test_models_(\d)+/).first
51
+ yaml[key]["title"].should == 'test title'
52
+ end
53
+
54
+ specify "should not create destroyed model" do
55
+ `echo -n > testfixtureaseproject/test/fixtures/test_models.yml`
56
+ run_fixturease do |f|
57
+ f.puts "@test1 = TestModel.create :title => 'test title'"
58
+ f.puts "@test2 = TestModel.create :title => 'test title'"
59
+ f.puts "@test2.destroy"
60
+ f.puts "exit"
61
+ f.readline until f.eof?
62
+ end
63
+ yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
64
+ yaml.keys.should_have(1).grep(/test1/)
65
+ yaml.keys.should_have(0).grep(/test2/)
66
+ end
67
+
68
+ specify "should ignore non-ActiveRecord instance variables" do
69
+ `echo -n > testfixtureaseproject/test/fixtures/test_models.yml`
70
+ run_fixturease do |f|
71
+ f.puts "@test1 = 1"
72
+ f.puts "exit"
73
+ f.readline until f.eof?
74
+ end
75
+ yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
76
+ yaml.should == false
77
+ end
78
+
79
+ specify "should not create unsaved model" do
80
+ `echo -n > testfixtureaseproject/test/fixtures/test_models.yml`
81
+ run_fixturease do |f|
82
+ f.puts "@test1 = TestModel.new :title => 'test title'"
83
+ f.puts "exit"
84
+ f.readline until f.eof?
85
+ end
86
+ yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
87
+ yaml.should == false
88
+ end
89
+
90
+ specify "should create named model" do
91
+ `echo -n > testfixtureaseproject/test/fixtures/test_models.yml`
92
+ run_fixturease do |f|
93
+ f.puts "@test = TestModel.create :title => 'test title'"
94
+ f.puts "exit"
95
+ f.readline until f.eof?
96
+ end
97
+ yaml = YAML::load_file("testfixtureaseproject/test/fixtures/test_models.yml")
98
+ yaml.keys.should_have(1).grep(/^test$/)
99
+ key = yaml.keys.grep(/^test$/).first
100
+ yaml[key]["title"].should == 'test title'
101
+ end
102
+
103
+
104
+ private
105
+
106
+ def run_fixturease(&block)
107
+ ENV['RAILS_ROOT']='testfixtureaseproject'
108
+ ENV['FIXTURES_ROOT']='test/fixtures'
109
+ ENV['RAILS_ENV']='test'
110
+ @io = IO.popen "#{File.dirname(__FILE__)}/../bin/fixturease.rb", "r+", &block
111
+ end
112
+
113
+ end
metadata CHANGED
@@ -3,7 +3,7 @@ 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.2
6
+ version: 0.2.3
7
7
  date: 2007-01-19 00:00:00 +02:00
8
8
  summary: Easy fixture creation tool
9
9
  require_paths:
@@ -31,6 +31,8 @@ authors:
31
31
  files:
32
32
  - bin/fixturease.rb
33
33
  - Rakefile
34
+ - spec/database.yml
35
+ - spec/fixturease_spec.rb
34
36
  test_files: []
35
37
 
36
38
  rdoc_options: []