koujou 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestCustomValidation < Test::Unit::TestCase
4
+
5
+ context 'CustomValidation' do
6
+
7
+ should 'override any custom validations' do
8
+ instance = User.new
9
+ Koujou::CustomValidation.stub_custom_validations!(instance)
10
+ assert instance.custom_validation_method
11
+ end
12
+
13
+ should 'override any before_validate methods' do
14
+
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,120 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestDataGenerator < Test::Unit::TestCase
4
+
5
+ context 'on generate' do
6
+
7
+ setup do
8
+ @validation = mock("ActiveRecord::Reflection::MacroReflection")
9
+ @validation.expects(:active_record).twice.returns(User)
10
+ end
11
+
12
+ should 'generate a valid int' do
13
+ @validation.expects(:name).twice.returns('age')
14
+ int = Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
15
+ assert_kind_of Fixnum, int
16
+ assert int > 0
17
+ end
18
+
19
+ should 'generate a valid float' do
20
+ @validation.expects(:name).twice.returns('salary')
21
+ float = Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
22
+ assert_kind_of Float, float
23
+ end
24
+
25
+ should 'generate a valid string' do
26
+ @validation.expects(:name).at_least_once.returns('name')
27
+ string = Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
28
+ assert_kind_of String, string
29
+ assert string.size > 0
30
+ end
31
+
32
+ should 'generate a valid email' do
33
+ @validation.expects(:name).times(1..10).returns('email')
34
+ email = Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
35
+ assert_match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, email)
36
+ end
37
+
38
+ should 'genreate valid text field values' do
39
+ @validation.expects(:name).twice.returns('about')
40
+ body = Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
41
+ assert_not_nil body
42
+ end
43
+
44
+ should 'generate a valid datetime' do
45
+ @validation.expects(:name).twice.returns('hired_on')
46
+ dt = Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
47
+ assert_kind_of DateTime, dt
48
+ end
49
+
50
+ should 'always generate true for booleans' do
51
+ @validation.expects(:name).twice.returns('terms_of_service')
52
+ assert Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
53
+ end
54
+ end
55
+
56
+ context 'on generate for attributes that are not columns' do
57
+ setup do
58
+ @validation = mock("ActiveRecord::Reflection::MacroReflection")
59
+ @validation.expects(:active_record).once.returns(User)
60
+ end
61
+
62
+ should 'always generate "koujourama" for passwords' do
63
+ @validation.expects(:name).at_least_once.returns('password')
64
+ assert_equal "koujourama", Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
65
+ end
66
+
67
+ should 'always generate "koujourama" for password confirmations' do
68
+ @validation.expects(:name).at_least_once.returns('password_confirmation')
69
+ assert_equal "koujourama", Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
70
+ end
71
+
72
+ should 'always generate the same for password and password confirmations' do
73
+ @validation.expects(:name).at_least_once.returns('password')
74
+ password = Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
75
+ @validation.expects(:active_record).once.returns(User)
76
+ @validation.expects(:name).at_least_once.returns('password_confirmation')
77
+ password_confirmation = Koujou::DataGenerator.new(false, @validation).generate_data_for_column_type
78
+ assert_equal password, password_confirmation
79
+ end
80
+ end
81
+
82
+ context 'on generate with a required length' do
83
+ setup do
84
+ @validation = mock("ActiveRecord::Reflection::MacroReflection")
85
+ @validation.expects(:active_record).twice.returns(Post)
86
+ end
87
+
88
+ should 'generate the correct size string with a length passed in' do
89
+ @validation.expects(:name).twice.returns('body')
90
+ data_generator = Koujou::DataGenerator.new(false, @validation)
91
+ data_generator.required_length = 20
92
+ body = data_generator.generate_data_for_column_type
93
+ assert_equal 20, body.size
94
+ end
95
+
96
+ end
97
+
98
+ context 'on generate with an inclusion' do
99
+
100
+ setup do
101
+ @validation = mock("ActiveRecord::Reflection::MacroReflection")
102
+ end
103
+
104
+ should 'generate the correct string with an inclusion_value passed in' do
105
+ data_generator = Koujou::DataGenerator.new(false, @validation)
106
+ data_generator.inclusion_values = %w(Nissan Subaru)
107
+ make = data_generator.generate_data_for_column_type
108
+ assert_equal 'Nissan', make
109
+ end
110
+
111
+ should 'generate the correct int with an inclusion_value passed in' do
112
+ data_generator = Koujou::DataGenerator.new(false, @validation)
113
+ data_generator.inclusion_values = (1..3)
114
+ num = data_generator.generate_data_for_column_type
115
+ assert_equal 1, num
116
+ end
117
+
118
+ end
119
+
120
+ end
@@ -0,0 +1,12 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require 'stringio'
4
+ require 'test/unit'
5
+ require 'rubygems'
6
+ gem 'thoughtbot-shoulda'
7
+ require 'shoulda'
8
+ gem 'mocha'
9
+ require 'mocha'
10
+ require File.dirname(__FILE__) + '/../lib/koujou'
11
+ require File.join(File.dirname(__FILE__), 'lib', 'active_record_test_connector')
12
+
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestKoujou < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestSequence < Test::Unit::TestCase
4
+
5
+ context "sequence" do
6
+
7
+ should "implement the singleton pattern" do
8
+ assert !Koujou::Sequence.respond_to?(:new)
9
+ assert Koujou::Sequence.include?(Singleton)
10
+ end
11
+
12
+ should "generate successive numbers when calling next" do
13
+ first = Koujou::Sequence.instance.next
14
+ second = Koujou::Sequence.instance.next
15
+ assert_not_equal first, second
16
+ end
17
+
18
+ end
19
+
20
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: koujou
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Leung
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-12 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.2
24
+ version:
25
+ description: |-
26
+ Koujou is a fixture replacement that requires no effort to use. You don't have to define a single thing
27
+ in your test_helper or whatever. Just call the koujou method on your active record model, and you're
28
+ off.
29
+
30
+ Check out: http://www.michaelleung.us/koujou for all the juicy details.
31
+
32
+ Please note this is a very early release of koujou, so if you find any issues, just post
33
+ them here: http://github.com/mleung/koujou/issues
34
+ email:
35
+ - me@michaelleung.us
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - History.txt
42
+ - Manifest.txt
43
+ - PostInstall.txt
44
+ files:
45
+ - History.txt
46
+ - Manifest.txt
47
+ - PostInstall.txt
48
+ - README.rdoc
49
+ - Rakefile
50
+ - koujou.gemspec
51
+ - lib/koujou.rb
52
+ - lib/koujou/builder.rb
53
+ - lib/koujou/custom_validation.rb
54
+ - lib/koujou/data_generator.rb
55
+ - lib/koujou/sequence.rb
56
+ - lib/koujou/validation_reflection.rb
57
+ - script/console
58
+ - script/destroy
59
+ - script/generate
60
+ - test/lib/active_record_test_connector.rb
61
+ - test/lib/models/car.rb
62
+ - test/lib/models/comment.rb
63
+ - test/lib/models/message.rb
64
+ - test/lib/models/photo.rb
65
+ - test/lib/models/post.rb
66
+ - test/lib/models/profile.rb
67
+ - test/lib/models/user.rb
68
+ - test/test_builder.rb
69
+ - test/test_custom_validation.rb
70
+ - test/test_data_generator.rb
71
+ - test/test_helper.rb
72
+ - test/test_kojo.rb
73
+ - test/test_sequence.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/mleung/koujou
76
+ licenses: []
77
+
78
+ post_install_message: PostInstall.txt
79
+ rdoc_options:
80
+ - --main
81
+ - README.rdoc
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project: koujou
99
+ rubygems_version: 1.3.5
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Koujou is a fixture replacement that requires no effort to use
103
+ test_files:
104
+ - test/test_builder.rb
105
+ - test/test_custom_validation.rb
106
+ - test/test_data_generator.rb
107
+ - test/test_helper.rb
108
+ - test/test_kojo.rb
109
+ - test/test_sequence.rb