xli-hickey 0.0.1 → 0.0.2

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.
@@ -31,7 +31,7 @@ Suppose we have a User model that has attributes login and admin
31
31
  % end
32
32
 
33
33
  We can create a user model by the following code:
34
- % Hickey.kiss(:user => {:login => 'xli', :admin => true})
34
+ % Hickey.dump(:user => {:login => 'xli', :admin => true})
35
35
 
36
36
  It's not the simplest way to create user model, but just let you know how it works.
37
37
 
@@ -59,7 +59,7 @@ Suppose we have the following models:
59
59
  % end
60
60
 
61
61
  We can create a domain in the test by the following code:
62
- % Hickey.kiss :project => {
62
+ % Hickey.dump :project => {
63
63
  % :identifier => 'hickey', :cards => [
64
64
  % {
65
65
  % :name => 'first card',
@@ -73,7 +73,7 @@ We can create a domain in the test by the following code:
73
73
  % }
74
74
 
75
75
  Another example for we want to create tag cards with one same tag named 'first_tag':
76
- % Hickey.kiss :project => {
76
+ % Hickey.dump :project => {
77
77
  % :identifier => 'hickey', :cards => [
78
78
  % {
79
79
  % :name => 'first card',
@@ -90,15 +90,6 @@ Another example for we want to create tag cards with one same tag named 'first_t
90
90
 
91
91
  Hickey is available under an Apache License Version 2.0.
92
92
 
93
- == Support
94
-
95
- Feel free to submit commits or feature requests. If you send a patch,
96
- remember to update the corresponding unit tests. If fact, I prefer
97
- new feature to be submitted in the form of new unit tests.
98
-
99
- For other information, feel free to ask on the ruby-talk mailing list or contact
100
- mailto:iam@li-xiao.com.
101
-
102
93
  = Other stuff
103
94
 
104
95
  Author:: Li Xiao <iam@li-xiao.com>
data/Rakefile CHANGED
@@ -37,20 +37,52 @@ end
37
37
 
38
38
  rd = Rake::RDocTask.new("rdoc") { |rdoc|
39
39
  rdoc.rdoc_dir = 'html'
40
- # rdoc.template = 'kilmer'
41
- # rdoc.template = 'css2'
42
- rdoc.template = 'doc/jamis.rb'
40
+ rdoc.template = 'html'
43
41
  rdoc.title = "Hickey"
44
42
  rdoc.options << '--line-numbers' << '--inline-source' <<
45
- '--main' << 'README' <<
43
+ '--main' << 'README.rdoc' <<
46
44
  '--title' << 'Hickey'
47
- rdoc.rdoc_files.include('README', 'LICENSE.txt', 'TODO', 'CHANGES')
45
+ rdoc.rdoc_files.include('README.rdoc', 'LICENSE.txt', 'TODO', 'CHANGES')
48
46
  rdoc.rdoc_files.include('lib/**/*.rb', 'doc/**/*.rdoc')
49
47
  }
50
48
 
51
49
  if ! defined?(Gem)
52
50
  puts "Package Target requires RubyGEMs"
53
51
  else
52
+ gem_content = <<-GEM
53
+ Gem::Specification.new do |spec|
54
+ spec.name = 'hickey'
55
+ spec.version = "0.0.2"
56
+ spec.summary = "Hickey provides a simple way of preparing test data inside test for Rails project."
57
+
58
+ #### Dependencies and requirements.
59
+ spec.files = #{(Dir.glob("lib/**/*.rb") + ["CHANGES", "hickey.gemspec", "lib", "LICENSE.TXT", "Rakefile", "README.rdoc", "TODO"]).inspect}
60
+
61
+ spec.test_files = #{Dir.glob("test/**/*.rb").inspect}
62
+
63
+ #### Load-time details: library and application (you will need one or both).
64
+
65
+ spec.require_path = 'lib' # Use these for libraries.
66
+
67
+ #### Documentation and testing.
68
+
69
+ spec.has_rdoc = true
70
+ spec.extra_rdoc_files = #{rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a.inspect}
71
+ spec.rdoc_options = #{rd.options.inspect}
72
+
73
+ #### Author and project details.
74
+
75
+ spec.author = "Li Xiao"
76
+ spec.email = "iam@li-xiao.com"
77
+ spec.homepage = "http://github.com/xli/hickey/tree/master"
78
+ spec.rubyforge_project = "hickey"
79
+ end
80
+ GEM
81
+ File.open(File.dirname(__FILE__) + '/hickey.gemspec', 'w') do |f|
82
+ f.write(gem_content)
83
+ end
84
+
85
+ #build gem package same steps with github
54
86
  File.open(File.dirname(__FILE__) + '/hickey.gemspec') do |f|
55
87
  data = f.read
56
88
  spec = nil
data/hickey.gemspec CHANGED
@@ -1,26 +1,27 @@
1
- Gem::Specification.new do |s|
2
-
3
- #### Basic information.
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'hickey'
3
+ spec.version = "0.0.2"
4
+ spec.summary = "Hickey provides a simple way of preparing test data inside test for Rails project."
4
5
 
5
- s.name = 'hickey'
6
- s.version = '0.0.1'
7
- s.summary = "Hickey provides a simple way of preparing test data inside test for Rails project."
6
+ #### Dependencies and requirements.
7
+ spec.files = ["lib/hickey/acceptor.rb", "lib/hickey/domain_detector/actions.rb", "lib/hickey/domain_detector/associations.rb", "lib/hickey/domain_detector/base.rb", "lib/hickey/domain_detector/configurable.rb", "lib/hickey/domain_detector/scopes.rb", "lib/hickey/domain_detector.rb", "lib/hickey.rb", "CHANGES", "hickey.gemspec", "lib", "LICENSE.TXT", "Rakefile", "README.rdoc", "TODO"]
8
8
 
9
- s.add_dependency('activerecord', '>= 2.1.0')
10
- #### Which files are to be included in this gem? Everything! (Except SVN directories.)
11
- # p Dir.glob("lib/**/*.rb") + Dir.glob("test/**/*.rb")
12
- s.files = ["lib/hickey/acceptor.rb", "lib/hickey/domain_detector/actions.rb", "lib/hickey/domain_detector/associations.rb", "lib/hickey/domain_detector/base.rb", "lib/hickey/domain_detector/configurable.rb", "lib/hickey/domain_detector/scopes.rb", "lib/hickey/domain_detector.rb", "lib/hickey.rb", "test/belongs_to_association_test.rb", "test/database_config.rb", "test/enable_callbacks_test.rb", "test/find_or_create_actions_test.rb", "test/has_and_belongs_to_many_association_test.rb", "test/has_many_association_test.rb", "test/has_one_association_test.rb", "test/model_association_test.rb", "test/models/address.rb", "test/models/author.rb", "test/models/country.rb", "test/models/project.rb", "test/models/projects_member.rb", "test/models/property_definition.rb", "test/models/simple.rb", "test/models/tag.rb", "test/models/topic.rb", "test/models/user.rb", "test/models/writer.rb", "test/schema.rb", "test/single_model_test.rb", "test/test_helper.rb", "test/with_scope_test.rb"] + ["CHANGES", "hickey.gemspec", "LICENSE.TXT", "Rakefile", "README", "TODO"]
9
+ spec.test_files = ["test/belongs_to_association_test.rb", "test/database_config.rb", "test/enable_callbacks_test.rb", "test/find_or_create_actions_test.rb", "test/has_and_belongs_to_many_association_test.rb", "test/has_many_association_test.rb", "test/has_one_association_test.rb", "test/model_association_test.rb", "test/models/address.rb", "test/models/author.rb", "test/models/country.rb", "test/models/project.rb", "test/models/projects_member.rb", "test/models/property_definition.rb", "test/models/simple.rb", "test/models/tag.rb", "test/models/topic.rb", "test/models/user.rb", "test/models/writer.rb", "test/schema.rb", "test/single_model_test.rb", "test/test_helper.rb", "test/with_scope_test.rb"]
13
10
 
14
11
  #### Load-time details: library and application (you will need one or both).
15
12
 
16
- s.require_path = 'lib' # Use these for libraries.
13
+ spec.require_path = 'lib' # Use these for libraries.
17
14
 
18
15
  #### Documentation and testing.
19
16
 
20
- s.has_rdoc = false
17
+ spec.has_rdoc = true
18
+ spec.extra_rdoc_files = ["README.rdoc", "LICENSE.txt", "TODO", "CHANGES"]
19
+ spec.rdoc_options = ["--line-numbers", "--inline-source", "--main", "README.rdoc", "--title", "Hickey"]
21
20
 
22
21
  #### Author and project details.
23
- s.author = "Li Xiao"
24
- s.email = "iam@li-xiao.com"
25
- s.homepage = "https://github.com/xli/hickey/tree"
22
+
23
+ spec.author = "Li Xiao"
24
+ spec.email = "iam@li-xiao.com"
25
+ spec.homepage = "http://github.com/xli/hickey/tree/master"
26
+ spec.rubyforge_project = "hickey"
26
27
  end
data/lib/hickey.rb CHANGED
@@ -10,13 +10,13 @@ require 'hickey/acceptor'
10
10
  require 'hickey/domain_detector'
11
11
 
12
12
  module Hickey
13
- def kiss(domain)
13
+ def dump(domain)
14
14
  DomainDetector::Base.new.visit(domain)
15
15
  end
16
16
 
17
- def lipstick(domain={})
17
+ def setup(domain={})
18
18
  DomainDetector::Base.configurations.merge! domain
19
19
  end
20
20
 
21
- module_function :kiss, :lipstick
21
+ module_function :dump, :setup
22
22
  end
@@ -2,13 +2,13 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
2
 
3
3
  class BelongsToAssociationTest < Test::Unit::TestCase
4
4
  def test_create_associated_belongs_to_model
5
- Hickey.kiss :projects_member => {:user => {:login => 'xli'}}
5
+ Hickey.dump :projects_member => {:user => {:login => 'xli'}}
6
6
  assert_not_nil projects_member.user
7
7
  assert_equal 'xli', projects_member.user.login
8
8
  end
9
9
 
10
10
  def test_create_associated_belongs_to_model_with_class_name
11
- Hickey.kiss :topic => {:title => 'Bla bla...', :owner => {:login => 'xli'}}
11
+ Hickey.dump :topic => {:title => 'Bla bla...', :owner => {:login => 'xli'}}
12
12
 
13
13
  topic = Topic.find(:first)
14
14
  assert_not_nil topic.owner
@@ -3,133 +3,142 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
3
3
  class EnableCallbacksTest < Test::Unit::TestCase
4
4
 
5
5
  def teardown
6
- Hickey.lipstick.clear
6
+ Hickey.setup.clear
7
7
  Simple.public_instance_methods(false).each do |method|
8
8
  next if method == 'id'
9
9
  Simple.class_eval "def #{method};end"
10
10
  end
11
11
  end
12
-
12
+
13
+ def test_configuration_setup_should_not_effect_other_instances
14
+ Hickey.setup(:simple => {:callbacks => [:after_save]})
15
+ simple = Hickey.dump(:simple => {})
16
+ assert simple.respond_to?(:original_callback, true)
17
+
18
+ simple = Simple.find(:all).first
19
+ assert !simple.respond_to?(:original_callback, true)
20
+ end
21
+
13
22
  def test_invoke_before_save_and_after_save_after_configured_all_callbacks
14
- Hickey.lipstick(:simple => {:callbacks => :all})
23
+ Hickey.setup(:simple => {:callbacks => :all})
15
24
  Simple.class_eval do
16
25
  before_save :create_user_before_save
17
26
  after_save :create_user_after_save
18
27
  def create_user_after_save
19
- Hickey.kiss(:user => {:login => 'create_user_after_save'})
28
+ Hickey.dump(:user => {:login => 'create_user_after_save'})
20
29
  end
21
30
  def create_user_before_save
22
- Hickey.kiss(:user => {:login => 'create_user_before_save'})
31
+ Hickey.dump(:user => {:login => 'create_user_before_save'})
23
32
  end
24
33
  def validate
25
34
  raise 'should bypass'
26
35
  end
27
36
  end
28
37
 
29
- Hickey.kiss(:simple => {})
38
+ Hickey.dump(:simple => {})
30
39
 
31
40
  assert_equal ['create_user_before_save', 'create_user_after_save'].sort, User.find(:all).collect(&:login).sort
32
41
  end
33
42
 
34
43
  def test_invoke_before_validation_on_create_after_configured_all_callbacks
35
- Hickey.lipstick(:simple => {:callbacks => :all})
44
+ Hickey.setup(:simple => {:callbacks => :all})
36
45
  Simple.class_eval do
37
46
  before_validation_on_create :create_user_before_validation_on_create
38
47
  def create_user_before_validation_on_create
39
- Hickey.kiss(:user => {:login => 'create_user_before_validation_on_create'})
48
+ Hickey.dump(:user => {:login => 'create_user_before_validation_on_create'})
40
49
  end
41
50
  def validate
42
51
  raise 'should bypass'
43
52
  end
44
53
  end
45
54
 
46
- Hickey.kiss(:simple => {})
55
+ Hickey.dump(:simple => {})
47
56
  assert_equal ['create_user_before_validation_on_create'], User.find(:all).collect(&:login)
48
57
  end
49
58
 
50
59
  def test_invoke_before_validation_after_configured_all_callbacks
51
- Hickey.lipstick(:simple => {:callbacks => :all})
60
+ Hickey.setup(:simple => {:callbacks => :all})
52
61
  Simple.class_eval do
53
62
  before_validation :create_user_before_validation
54
63
  def create_user_before_validation
55
- Hickey.kiss(:user => {:login => 'create_user_before_validation'})
64
+ Hickey.dump(:user => {:login => 'create_user_before_validation'})
56
65
  end
57
66
  def validate
58
67
  raise 'should bypass'
59
68
  end
60
69
  end
61
70
 
62
- Hickey.kiss(:simple => {})
71
+ Hickey.dump(:simple => {})
63
72
  assert_equal ['create_user_before_validation'], User.find(:all).collect(&:login)
64
73
  end
65
74
 
66
75
  def test_invoke_before_validation_after_configured_all_callbacks
67
- Hickey.lipstick(:simple => {:callbacks => :all})
76
+ Hickey.setup(:simple => {:callbacks => :all})
68
77
  Simple.class_eval do
69
78
  after_validation :create_user_after_validation
70
79
  def create_user_after_validation
71
- Hickey.kiss(:user => {:login => 'create_user_after_validation'})
80
+ Hickey.dump(:user => {:login => 'create_user_after_validation'})
72
81
  end
73
82
  def validate
74
83
  raise 'should bypass'
75
84
  end
76
85
  end
77
86
 
78
- Hickey.kiss(:simple => {})
87
+ Hickey.dump(:simple => {})
79
88
  assert_equal ['create_user_after_validation'], User.find(:all).collect(&:login)
80
89
  end
81
90
 
82
91
  def test_should_not_callback_before_validation_on_create_if_pass_in_existed_model
83
- simple = Hickey.kiss(:simple => {})
84
- Hickey.lipstick(:simple => {:callbacks => :all})
92
+ simple = Hickey.dump(:simple => {})
93
+ Hickey.setup(:simple => {:callbacks => :all})
85
94
  Simple.class_eval do
86
95
  before_validation_on_create :create_user_before_validation_on_create
87
96
  def create_user_before_validation_on_create
88
- Hickey.kiss(:user => {:login => 'create_user_before_validation_on_create'})
97
+ Hickey.dump(:user => {:login => 'create_user_before_validation_on_create'})
89
98
  end
90
99
  def validate
91
100
  raise 'should bypass'
92
101
  end
93
102
  end
94
103
 
95
- Hickey.kiss(simple => {})
104
+ Hickey.dump(simple => {})
96
105
  assert_equal [], User.find(:all).collect(&:login)
97
106
  end
98
107
 
99
108
  def test_should_enable_configuration_of_invoking_all_callbacks_for_all_subclasses
100
- Hickey.lipstick(:property_definition => {:callbacks => :all})
109
+ Hickey.setup(:property_definition => {:callbacks => :all})
101
110
  DatePropertyDefinition.class_eval do
102
111
  after_validation :create_user_after_validation
103
112
  def create_user_after_validation
104
- Hickey.kiss(:user => {:login => 'create_user_after_validation'})
113
+ Hickey.dump(:user => {:login => 'create_user_after_validation'})
105
114
  end
106
115
  def validate
107
116
  raise 'should bypass'
108
117
  end
109
118
  end
110
119
 
111
- Hickey.kiss(:property_definition => {:type => 'DatePropertyDefinition'})
120
+ Hickey.dump(:property_definition => {:type => 'DatePropertyDefinition'})
112
121
 
113
122
  assert_equal ['create_user_after_validation'], User.find(:all).collect(&:login)
114
123
  end
115
124
 
116
125
  def test_invoke_callback_specified_after_configured
117
- Hickey.lipstick(:simple => {:callbacks => [:after_create, :before_create]})
126
+ Hickey.setup(:simple => {:callbacks => [:after_create, :before_create]})
118
127
  Simple.class_eval do
119
128
  before_create :create_user_before_create
120
129
  after_create :create_user_after_create
121
130
  def create_user_before_create
122
- Hickey.kiss(:user => {:login => 'create_user_before_create'})
131
+ Hickey.dump(:user => {:login => 'create_user_before_create'})
123
132
  end
124
133
  def create_user_after_create
125
- Hickey.kiss(:user => {:login => 'create_user_after_create'})
134
+ Hickey.dump(:user => {:login => 'create_user_after_create'})
126
135
  end
127
136
  def validate
128
137
  raise 'should bypass'
129
138
  end
130
139
  end
131
140
 
132
- Hickey.kiss(:simple => {})
141
+ Hickey.dump(:simple => {})
133
142
  assert_equal ['create_user_after_create', 'create_user_before_create'].sort, User.find(:all).collect(&:login).sort
134
143
  end
135
144
  end
@@ -2,39 +2,39 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
2
 
3
3
  class FindOrCreateActionsTest < Test::Unit::TestCase
4
4
  def test_create_action
5
- assert Hickey.kiss(:simple => {:create => {}})
5
+ assert Hickey.dump(:simple => {:create => {}})
6
6
  end
7
7
 
8
8
  def test_create_multi_models
9
- result = Hickey.kiss(:simple => {:create => {}}, :user => {:create => {:login => 'xli'}})
9
+ result = Hickey.dump(:simple => {:create => {}}, :user => {:create => {:login => 'xli'}})
10
10
  assert_equal({:simple => Simple.find(:first), :user => User.find(:first)}, result)
11
11
  end
12
12
 
13
13
  def test_create_association_model
14
- Hickey.kiss(:project => {:identifier => 'hickey', :users => [{:create => {:login => 'xli', :admin => true}}]})
14
+ Hickey.dump(:project => {:identifier => 'hickey', :users => [{:create => {:login => 'xli', :admin => true}}]})
15
15
 
16
16
  assert_equal 'xli', project.users.first.login
17
17
  end
18
18
 
19
19
  def test_find_action
20
- simple1 = Hickey.kiss(:simple => {})
21
- simple2 = Hickey.kiss(:simple => {:find => {}})
20
+ simple1 = Hickey.dump(:simple => {})
21
+ simple2 = Hickey.dump(:simple => {:find => {}})
22
22
  assert_equal simple1, simple2
23
23
  assert_equal 1, Simple.count(:all)
24
24
  end
25
25
 
26
26
  def test_find_by_attributes
27
- Hickey.kiss(:user => {:login => 'mm'})
28
- user1 = Hickey.kiss(:user => {:login => 'xli'})
29
- user2 = Hickey.kiss(:user => {:find => {:login => 'xli'}})
27
+ Hickey.dump(:user => {:login => 'mm'})
28
+ user1 = Hickey.dump(:user => {:login => 'xli'})
29
+ user2 = Hickey.dump(:user => {:find => {:login => 'xli'}})
30
30
  assert_equal user1, user2
31
31
  assert_equal 2, User.count(:all)
32
32
  end
33
33
 
34
34
  def test_should_find_model_without_association
35
- Hickey.kiss(:project => {:identifier => 'hickey', :users => [{:login => 'xli', :admin => true}]})
35
+ Hickey.dump(:project => {:identifier => 'hickey', :users => [{:login => 'xli', :admin => true}]})
36
36
 
37
- project = Hickey.kiss(:project => {:find => {:identifier => 'hickey', :users => [{:login => 'xli', :admin => true}]}})
37
+ project = Hickey.dump(:project => {:find => {:identifier => 'hickey', :users => [{:login => 'xli', :admin => true}]}})
38
38
  assert_equal 'hickey', project.identifier
39
39
  assert_equal 'xli', project.users.first.login
40
40
  assert_equal 1, Project.count(:all)
@@ -43,9 +43,9 @@ class FindOrCreateActionsTest < Test::Unit::TestCase
43
43
  end
44
44
 
45
45
  def test_find_model_with_finding_association
46
- Hickey.kiss(:project => {:identifier => 'hickey', :users => [{:login => 'xli', :admin => true}]})
46
+ Hickey.dump(:project => {:identifier => 'hickey', :users => [{:login => 'xli', :admin => true}]})
47
47
 
48
- project = Hickey.kiss(:project => {:find => {:identifier => 'hickey', :users => [{:find => {:login => 'xli', :admin => true}}]}})
48
+ project = Hickey.dump(:project => {:find => {:identifier => 'hickey', :users => [{:find => {:login => 'xli', :admin => true}}]}})
49
49
  assert_equal 'hickey', project.identifier
50
50
  assert_equal 'xli', project.users.first.login
51
51
  assert_equal 1, Project.count(:all)
@@ -54,9 +54,9 @@ class FindOrCreateActionsTest < Test::Unit::TestCase
54
54
  end
55
55
 
56
56
  def test_find_or_create
57
- Hickey.kiss(:simple => {:find_or_create => {}})
57
+ Hickey.dump(:simple => {:find_or_create => {}})
58
58
  assert_equal 1, Simple.count(:all)
59
- Hickey.kiss(:simple => {:find_or_create => {}})
59
+ Hickey.dump(:simple => {:find_or_create => {}})
60
60
  assert_equal 1, Simple.count(:all)
61
61
  end
62
62
  end
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
2
 
3
3
  class HasAndBelongsToManyAssociationTest < Test::Unit::TestCase
4
4
  def test_create_associated_has_and_belongs_to_many_models
5
- Hickey.kiss :user => {:login => 'xli', :countries => [{:name => 'China'}]}
5
+ Hickey.dump :user => {:login => 'xli', :countries => [{:name => 'China'}]}
6
6
 
7
7
  assert_equal 1, user.countries.size
8
8
  assert_equal 'China', user.countries.first.name
@@ -3,12 +3,12 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
3
3
  class HasManyAssociationTest < Test::Unit::TestCase
4
4
 
5
5
  def test_create_associated_empty_models
6
- Hickey.kiss(:project => {:identifier => 'hickey', :projects_members => []})
6
+ Hickey.dump(:project => {:identifier => 'hickey', :projects_members => []})
7
7
  assert_equal [], project.projects_members
8
8
  end
9
9
 
10
10
  def test_create_associated_many_existed_models
11
- Hickey.kiss :project => {:identifier => 'hickey', :projects_members => [{}, {}]}
11
+ Hickey.dump :project => {:identifier => 'hickey', :projects_members => [{}, {}]}
12
12
 
13
13
  assert_equal 2, project.projects_members.size
14
14
  assert_not_nil project.projects_members.first
@@ -16,13 +16,13 @@ class HasManyAssociationTest < Test::Unit::TestCase
16
16
  end
17
17
 
18
18
  def test_option_class_name
19
- Hickey.kiss :user => {:login => 'xli', :my_topics => [{:title => 'Bla bla...'}]}
19
+ Hickey.dump :user => {:login => 'xli', :my_topics => [{:title => 'Bla bla...'}]}
20
20
  assert_equal 1, user.my_topics.size
21
21
  assert_equal 'Bla bla...', user.my_topics.first.title
22
22
  end
23
23
 
24
24
  def test_option_through_models
25
- Hickey.kiss :project => {:identifier => 'hickey', :users => [{:login => 'xli'}]}
25
+ Hickey.dump :project => {:identifier => 'hickey', :users => [{:login => 'xli'}]}
26
26
  assert_equal 1, project.projects_members.size
27
27
  assert_not_nil project.projects_members.first.user
28
28
  assert_equal 'xli', project.projects_members.first.user.login
@@ -31,18 +31,18 @@ class HasManyAssociationTest < Test::Unit::TestCase
31
31
  end
32
32
 
33
33
  def test_option_foreign_key
34
- Hickey.kiss :writer => {:login => 'xli', :addresses => [{:location => 'BeiJing'}, {:location => 'ShangHai'}]}
34
+ Hickey.dump :writer => {:login => 'xli', :addresses => [{:location => 'BeiJing'}, {:location => 'ShangHai'}]}
35
35
  assert_equal 2, writer.addresses.size
36
36
  assert_equal ['BeiJing', 'ShangHai'].sort, writer.addresses.collect(&:location).sort
37
37
  end
38
38
 
39
39
  def test_option_as
40
- Hickey.kiss :writer => {:topics => [{:title => 'Hello world'}, {:title => 'Hello world again'}]}
40
+ Hickey.dump :writer => {:topics => [{:title => 'Hello world'}, {:title => 'Hello world again'}]}
41
41
  assert_equal ['Hello world', 'Hello world again'].sort, writer.topics.collect(&:title).sort
42
42
  end
43
43
 
44
44
  def test_option_through_and_as
45
- Hickey.kiss :writer => {:login => 'writer', :disscutions => [{:speaker => {:login => 'xli'}}, {:speaker => {:login => 'oo'}}]}
45
+ Hickey.dump :writer => {:login => 'writer', :disscutions => [{:speaker => {:login => 'xli'}}, {:speaker => {:login => 'oo'}}]}
46
46
  speakers = writer.disscutions.collect(&:speaker)
47
47
  assert_equal ['writer', 'xli', 'oo'].sort, User.find(:all).collect(&:login).sort
48
48
  assert_equal 2, speakers.size
@@ -51,20 +51,20 @@ class HasManyAssociationTest < Test::Unit::TestCase
51
51
  end
52
52
 
53
53
  def test_specifying_type_attribute_for_single_table_inheritance
54
- Hickey.kiss :project => {:all_property_definitions => [{:name => 'status', :type => 'EnumPropertyDefinition'}, {:name => 'owner', :type => 'UserPropertyDefinition'}]}
54
+ Hickey.dump :project => {:all_property_definitions => [{:name => 'status', :type => 'EnumPropertyDefinition'}, {:name => 'owner', :type => 'UserPropertyDefinition'}]}
55
55
 
56
56
  assert_equal ['status', 'owner'].sort, project.all_property_definitions.collect(&:name).sort
57
57
  end
58
58
 
59
59
  def test_subclass_relationship_of_single_table_inheritance
60
- Hickey.kiss :property_definition => {:type => 'EnumPropertyDefinition', :enum_values => [{:value => 'new'}, {:value => 'open'}]}
60
+ Hickey.dump :property_definition => {:type => 'EnumPropertyDefinition', :enum_values => [{:value => 'new'}, {:value => 'open'}]}
61
61
 
62
62
  assert_equal ['new', 'open'].sort, property_definition.enum_values.collect(&:value).sort
63
63
  end
64
64
 
65
65
  def test_should_raise_active_record_subclass_not_found_error_when_cant_find_subclass
66
66
  assert_raise ActiveRecord::SubclassNotFound do
67
- Hickey.kiss :property_definition => {:type => 'NotPropertyDefinition'}
67
+ Hickey.dump :property_definition => {:type => 'NotPropertyDefinition'}
68
68
  end
69
69
  end
70
70
 
@@ -2,32 +2,32 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
2
 
3
3
  class HasOneAssociationTest < Test::Unit::TestCase
4
4
  def test_user_has_one_address
5
- Hickey.kiss :user => {:address => {:location => 'BeiJing'}}
5
+ Hickey.dump :user => {:address => {:location => 'BeiJing'}}
6
6
  assert_equal 'BeiJing', user.address.location
7
7
  end
8
8
 
9
9
  def test_with_option_foreign_key
10
- Hickey.kiss :author => {:address => {:location => 'BeiJing'}}
10
+ Hickey.dump :author => {:address => {:location => 'BeiJing'}}
11
11
  assert_equal 'BeiJing', author.address.location
12
12
  end
13
13
 
14
14
  def test_with_option_as_and_class_name
15
- Hickey.kiss :author => {:working_topic => {:title => 'Hello world'}}
15
+ Hickey.dump :author => {:working_topic => {:title => 'Hello world'}}
16
16
  assert_equal 'Hello world', author.working_topic.title
17
17
  end
18
18
 
19
19
  def test_with_option_through_has_one
20
- Hickey.kiss :author => {:country => {:name => 'China'}}
20
+ Hickey.dump :author => {:country => {:name => 'China'}}
21
21
  assert_equal 'China', author.country.name
22
22
  end
23
23
 
24
24
  def test_with_option_through_source
25
- Hickey.kiss :author => {:living_country => {:name => 'China'}}
25
+ Hickey.dump :author => {:living_country => {:name => 'China'}}
26
26
  assert_equal 'China', author.living_country.name
27
27
  end
28
28
 
29
29
  def test_with_option_through_source_type
30
- Hickey.kiss :disscution => {:speaker => {:login => 'xli'}}
30
+ Hickey.dump :disscution => {:speaker => {:login => 'xli'}}
31
31
  assert_equal 'xli', disscution.speaker.login
32
32
  end
33
33
 
@@ -41,13 +41,13 @@ class HasOneAssociationTest < Test::Unit::TestCase
41
41
  DisscutionBelongsToTopic.create!(:owner => user)
42
42
  assert_equal 'xli', d.owner.login
43
43
 
44
- Hickey.kiss :disscution_belongs_to_topic => {:owner => {:login => 'xli'}}
44
+ Hickey.dump :disscution_belongs_to_topic => {:owner => {:login => 'xli'}}
45
45
  assert_equal 'xli', disscution_belongs_to_topic.owner.login
46
46
  end
47
47
 
48
48
  #active_record couldn't work on has_one :through belongs to
49
49
  def xtest_with_option_through_source_type
50
- Hickey.kiss :disscution_belongs_to_topic => {:speaker => {:login => 'xli'}}
50
+ Hickey.dump :disscution_belongs_to_topic => {:speaker => {:login => 'xli'}}
51
51
  assert_equal 'xli', disscution_belongs_to_topic.speaker.login
52
52
  end
53
53
  end
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
3
3
  class ModelAssociationTest < Test::Unit::TestCase
4
4
 
5
5
  def test_should_return_same_with_models_loaded_from_db_after_created_models
6
- project = Hickey.kiss :project => {:identifier => 'hickey', :projects_members => [:user => {:login => 'xli'}]}
6
+ project = Hickey.dump :project => {:identifier => 'hickey', :projects_members => [:user => {:login => 'xli'}]}
7
7
 
8
8
  db_project = Project.find(:first)
9
9
  assert_equal project, db_project
@@ -12,7 +12,7 @@ class ModelAssociationTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_create_associated_both_has_many_association_and_belongs_to_association_models
15
- Hickey.kiss :project => {:identifier => 'hickey', :projects_members => [:user => {:login => 'xli'}]}
15
+ Hickey.dump :project => {:identifier => 'hickey', :projects_members => [:user => {:login => 'xli'}]}
16
16
  assert_equal 1, project.projects_members.size
17
17
  assert_not_nil project.projects_members.first.user
18
18
  assert_equal 'xli', project.projects_members.first.user.login
data/test/models/tag.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  class Tag < ActiveRecord::Base
2
2
  has_many :taggings, :class_name => '::Tagging'
3
3
  belongs_to :project
4
-
5
- should_bypass_all_callbacks_and_validations
4
+ before_save :validate_scopt_object
5
+ def validate_scopt_object
6
+ raise 'Project is nil' if project.nil?
7
+ end
6
8
  end
7
9
 
8
10
  class Tagging < ActiveRecord::Base
@@ -14,4 +16,9 @@ end
14
16
  class Card < ActiveRecord::Base
15
17
  has_many :taggings, :as => :taggable
16
18
  belongs_to :project
19
+
20
+ before_save :validate_scopt_object
21
+ def validate_scopt_object
22
+ raise 'Project is nil' if project.nil?
23
+ end
17
24
  end
@@ -2,22 +2,22 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
2
 
3
3
  class SingleModelTest < Test::Unit::TestCase
4
4
  def test_create_simple_model
5
- Hickey.kiss(:simple => {})
5
+ Hickey.dump(:simple => {})
6
6
  assert_equal 1, Simple.find(:all).size
7
7
  end
8
8
 
9
9
  def test_should_return_created_domain
10
- result = Hickey.kiss(:simple => {})
10
+ result = Hickey.dump(:simple => {})
11
11
  assert_equal Simple.find(:first), result
12
12
  end
13
13
 
14
14
  def test_should_return_created_domain
15
- result = Hickey.kiss(:simple => [{}])
15
+ result = Hickey.dump(:simple => [{}])
16
16
  assert_equal Simple.find(:all), result
17
17
  end
18
18
 
19
- def test_should_return_created_domain_as_hash_when_kiss_multi_models
20
- result = Hickey.kiss(:simple => {}, :user => {:login => 'xli'})
19
+ def test_should_return_created_domain_as_hash_when_dump_multi_models
20
+ result = Hickey.dump(:simple => {}, :user => {:login => 'xli'})
21
21
  assert_equal({:simple => Simple.find(:first), :user => User.find(:first)}, result)
22
22
  end
23
23
 
@@ -28,7 +28,7 @@ class SingleModelTest < Test::Unit::TestCase
28
28
  end
29
29
  end
30
30
 
31
- Hickey.kiss(:simple => {})
31
+ Hickey.dump(:simple => {})
32
32
  ensure
33
33
  Simple.class_eval do
34
34
  def validate
@@ -37,7 +37,7 @@ class SingleModelTest < Test::Unit::TestCase
37
37
  end
38
38
 
39
39
  def test_create_simple_model_list
40
- Hickey.kiss(:simple => [{}, {}])
40
+ Hickey.dump(:simple => [{}, {}])
41
41
  assert_equal 2, Simple.find(:all).size
42
42
  end
43
43
 
@@ -49,7 +49,7 @@ class SingleModelTest < Test::Unit::TestCase
49
49
  end
50
50
  end
51
51
 
52
- Hickey.kiss(:simple => {})
52
+ Hickey.dump(:simple => {})
53
53
  ensure
54
54
  Simple.class_eval do
55
55
  def should_be_bypass
@@ -59,59 +59,72 @@ class SingleModelTest < Test::Unit::TestCase
59
59
 
60
60
  def test_should_bypass_notifications
61
61
  SimpleObserver.instance
62
- Hickey.kiss(:simple => {})
62
+ Hickey.dump(:simple => {})
63
63
  assert_equal 1, Simple.count(:all)
64
64
  end
65
65
 
66
66
  def test_create_model_with_attributes
67
- Hickey.kiss(:user => {:login => 'xli', :admin => true})
67
+ Hickey.dump(:user => {:login => 'xli', :admin => true})
68
68
  user = User.find_by_login_and_admin('xli', true)
69
69
  assert_not_nil user
70
70
  end
71
71
 
72
+ def test_create_model_with_nil_attribute
73
+ Hickey.dump(:user => {:login => 'xli', :admin => nil})
74
+ user = User.find_by_login_and_admin('xli')
75
+ assert_not_nil user
76
+ assert_nil user.admin
77
+ end
78
+
79
+ def test_create_model_with_string_keys
80
+ Hickey.dump('user' => {'login' => 'xli'})
81
+ user = User.find_by_login_and_admin('xli')
82
+ assert_not_nil user
83
+ end
84
+
72
85
  def test_should_auto_set_created_at_and_updated_at_attributes
73
- Hickey.kiss(:project => {:identifier => 'hickey'})
86
+ Hickey.dump(:project => {:identifier => 'hickey'})
74
87
  assert_not_nil Project.find(:first).created_at
75
88
  assert_not_nil Project.find(:first).updated_at
76
89
  end
77
90
 
78
91
  def test_should_auto_set_created_on_and_updated_on_attributes
79
- Hickey.kiss(:project => {:identifier => 'hickey'})
92
+ Hickey.dump(:project => {:identifier => 'hickey'})
80
93
  assert_not_nil Project.find(:first).created_on
81
94
  assert_not_nil Project.find(:first).updated_on
82
95
  end
83
96
 
84
97
  def test_should_ignore_created_timestamp_attributes_when_they_have_value
85
98
  t = Time.parse("1/1/2000")
86
- Hickey.kiss(:project => {:identifier => 'hickey', :created_on => t, :created_at => t})
99
+ Hickey.dump(:project => {:identifier => 'hickey', :created_on => t, :created_at => t})
87
100
 
88
101
  assert_equal t, project.created_on
89
102
  assert_equal t, project.created_at
90
103
  end
91
104
 
92
105
  def test_should_update_object_specified
93
- project = Hickey.kiss(:project => {:identifier => 'hickey'})
94
- Hickey.kiss project => {:identifier => 'new project identifier'}
106
+ project = Hickey.dump(:project => {:identifier => 'hickey'})
107
+ Hickey.dump project => {:identifier => 'new project identifier'}
95
108
  project.reload
96
109
 
97
110
  assert_equal 'new project identifier', project.identifier
98
111
  end
99
112
 
100
113
  def test_create_object_associating_with_exist_object
101
- user = Hickey.kiss(:user => {:login => 'xli', :admin => true})
102
- Hickey.kiss(:project => {:identifier => 'hickey', :users => [user]})
114
+ user = Hickey.dump(:user => {:login => 'xli', :admin => true})
115
+ Hickey.dump(:project => {:identifier => 'hickey', :users => [user]})
103
116
 
104
117
  assert_equal 'xli', project.users.first.login
105
118
  end
106
119
 
107
120
  def test_should_raise_error_when_create_model_failed_by_sql_error
108
121
  assert_raise ActiveRecord::StatementInvalid do
109
- Hickey.kiss(:property_definition => {}) #type should not be nil
122
+ Hickey.dump(:property_definition => {}) #type should not be nil
110
123
  end
111
124
  end
112
125
 
113
126
  def test_should_work_after_redefined_accessor_method_for_column
114
- Hickey.kiss(:prisoner => {:login => 'xli'})
127
+ Hickey.dump(:prisoner => {:login => 'xli'})
115
128
  assert_equal 'xli', prisoner.login
116
129
  end
117
130
  end
data/test/test_helper.rb CHANGED
@@ -32,7 +32,6 @@ module Hickey
32
32
  end
33
33
 
34
34
  def should_be_bypass
35
- return if $testing_active_record
36
35
  raise 'should be bypass'
37
36
  end
38
37
  end
@@ -63,13 +62,6 @@ class Test::Unit::TestCase
63
62
  end
64
63
  end
65
64
 
66
- def with_testing_active_record
67
- $testing_active_record = true
68
- yield
69
- ensure
70
- $testing_active_record = false
71
- end
72
-
73
65
  def models
74
66
  return @models if defined?(@models)
75
67
  @models = []
@@ -1,8 +1,18 @@
1
1
  require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
2
 
3
3
  class WithScopeTest < Test::Unit::TestCase
4
+ def test_should_be_able_get_associated_scope_object_in_before_save
5
+ Hickey.setup(:card => {:callbacks => :all})
6
+ Hickey.setup(:tag => {:callbacks => :all})
7
+ Hickey.dump :project => {
8
+ :identifier => 'hickey', :cards => [{:name => 'first card', :taggings => [{:tag => {:name => 'first_tag'}}]}]
9
+ }
10
+ ensure
11
+ Hickey.setup.clear
12
+ end
13
+
4
14
  def test_should_auto_associate_models_even_they_are_not_related_directly
5
- Hickey.kiss :project => {
15
+ Hickey.dump :project => {
6
16
  :identifier => 'hickey', :cards => [
7
17
  {
8
18
  :name => 'first card',
@@ -15,7 +25,7 @@ class WithScopeTest < Test::Unit::TestCase
15
25
  end
16
26
 
17
27
  def test_should_work_with_find_or_create_actions
18
- Hickey.kiss :project => {
28
+ Hickey.dump :project => {
19
29
  :identifier => 'hickey', :cards => [
20
30
  {
21
31
  :name => 'first card',
@@ -32,12 +42,12 @@ class WithScopeTest < Test::Unit::TestCase
32
42
  end
33
43
 
34
44
  def test_should_not_effect_object_out_of_model_scope
35
- Hickey.kiss :writer => {:login => 'writer', :disscutions => [{:speaker => {:login => 'xli'}}, {:speaker => {:login => 'oo'}}]}
45
+ Hickey.dump :writer => {:login => 'writer', :disscutions => [{:speaker => {:login => 'xli'}}, {:speaker => {:login => 'oo'}}]}
36
46
  assert_equal 2, writer.disscutions.collect(&:id).uniq.size
37
47
  end
38
48
 
39
49
  def test_should_ignore_keys_that_dont_belong_to_model_in_the_scopes
40
- project = Hickey.kiss :project => {
50
+ project = Hickey.dump :project => {
41
51
  :identifier => 'hickey', :cards => [
42
52
  {
43
53
  :name => 'first card',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xli-hickey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Li Xiao
@@ -9,26 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-13 00:00:00 -07:00
12
+ date: 2008-10-27 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: activerecord
17
- version_requirement:
18
- version_requirements: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.1.0
23
- version:
14
+ dependencies: []
15
+
24
16
  description:
25
17
  email: iam@li-xiao.com
26
18
  executables: []
27
19
 
28
20
  extensions: []
29
21
 
30
- extra_rdoc_files: []
31
-
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE.txt
25
+ - TODO
26
+ - CHANGES
32
27
  files:
33
28
  - lib/hickey/acceptor.rb
34
29
  - lib/hickey/domain_detector/actions.rb
@@ -38,40 +33,24 @@ files:
38
33
  - lib/hickey/domain_detector/scopes.rb
39
34
  - lib/hickey/domain_detector.rb
40
35
  - lib/hickey.rb
41
- - test/belongs_to_association_test.rb
42
- - test/database_config.rb
43
- - test/enable_callbacks_test.rb
44
- - test/find_or_create_actions_test.rb
45
- - test/has_and_belongs_to_many_association_test.rb
46
- - test/has_many_association_test.rb
47
- - test/has_one_association_test.rb
48
- - test/model_association_test.rb
49
- - test/models/address.rb
50
- - test/models/author.rb
51
- - test/models/country.rb
52
- - test/models/project.rb
53
- - test/models/projects_member.rb
54
- - test/models/property_definition.rb
55
- - test/models/simple.rb
56
- - test/models/tag.rb
57
- - test/models/topic.rb
58
- - test/models/user.rb
59
- - test/models/writer.rb
60
- - test/schema.rb
61
- - test/single_model_test.rb
62
- - test/test_helper.rb
63
- - test/with_scope_test.rb
64
36
  - CHANGES
65
37
  - hickey.gemspec
38
+ - lib
66
39
  - LICENSE.TXT
67
40
  - Rakefile
68
- - README
41
+ - README.rdoc
69
42
  - TODO
70
- has_rdoc: false
71
- homepage: https://github.com/xli/hickey/tree
43
+ - LICENSE.txt
44
+ has_rdoc: true
45
+ homepage: http://github.com/xli/hickey/tree/master
72
46
  post_install_message:
73
- rdoc_options: []
74
-
47
+ rdoc_options:
48
+ - --line-numbers
49
+ - --inline-source
50
+ - --main
51
+ - README.rdoc
52
+ - --title
53
+ - Hickey
75
54
  require_paths:
76
55
  - lib
77
56
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -88,10 +67,32 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
67
  version:
89
68
  requirements: []
90
69
 
91
- rubyforge_project:
70
+ rubyforge_project: hickey
92
71
  rubygems_version: 1.2.0
93
72
  signing_key:
94
73
  specification_version: 2
95
74
  summary: Hickey provides a simple way of preparing test data inside test for Rails project.
96
- test_files: []
97
-
75
+ test_files:
76
+ - test/belongs_to_association_test.rb
77
+ - test/database_config.rb
78
+ - test/enable_callbacks_test.rb
79
+ - test/find_or_create_actions_test.rb
80
+ - test/has_and_belongs_to_many_association_test.rb
81
+ - test/has_many_association_test.rb
82
+ - test/has_one_association_test.rb
83
+ - test/model_association_test.rb
84
+ - test/models/address.rb
85
+ - test/models/author.rb
86
+ - test/models/country.rb
87
+ - test/models/project.rb
88
+ - test/models/projects_member.rb
89
+ - test/models/property_definition.rb
90
+ - test/models/simple.rb
91
+ - test/models/tag.rb
92
+ - test/models/topic.rb
93
+ - test/models/user.rb
94
+ - test/models/writer.rb
95
+ - test/schema.rb
96
+ - test/single_model_test.rb
97
+ - test/test_helper.rb
98
+ - test/with_scope_test.rb