hickey 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
+
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
+
14
+ def test_should_auto_associate_models_even_they_are_not_related_directly
15
+ Hickey.dump :project => {
16
+ :identifier => 'hickey', :cards => [
17
+ {
18
+ :name => 'first card',
19
+ :taggings => [{:tag => {:name => 'first_tag'}}],
20
+ }
21
+ ]
22
+ }
23
+ assert_equal ['first_tag'], project.tags.collect(&:name)
24
+ assert_equal ['first card'], project.cards.collect(&:name)
25
+ end
26
+
27
+ def test_should_work_with_find_or_create_actions
28
+ Hickey.dump :project => {
29
+ :identifier => 'hickey', :cards => [
30
+ {
31
+ :name => 'first card',
32
+ :taggings => [{:tag => {:find_or_create => {:name => 'first_tag'}}}],
33
+ },
34
+ {
35
+ :name => 'dont make me think',
36
+ :taggings => [{:tag => {:find_or_create => {:name => 'first_tag'}}}],
37
+ }
38
+ ]
39
+ }
40
+ assert_equal ['first_tag'], project.tags.collect(&:name)
41
+ assert_equal ['first card', 'dont make me think'].sort, project.cards.collect(&:name).sort
42
+ end
43
+
44
+ def test_should_not_effect_object_out_of_model_scope
45
+ Hickey.dump :writer => {:login => 'writer', :disscutions => [{:speaker => {:login => 'xli'}}, {:speaker => {:login => 'oo'}}]}
46
+ assert_equal 2, writer.disscutions.collect(&:id).uniq.size
47
+ end
48
+
49
+ def test_should_ignore_keys_that_dont_belong_to_model_in_the_scopes
50
+ project = Hickey.dump :project => {
51
+ :identifier => 'hickey', :cards => [
52
+ {
53
+ :name => 'first card',
54
+ :taggings => [{:tag => {:find_or_create => {:name => 'first_tag'}}}],
55
+ },
56
+ {
57
+ :name => 'second card',
58
+ :taggings => [{:tag => {:find_or_create => {:name => 'first_tag'}}}],
59
+ }
60
+ ]
61
+ }
62
+ tag = project.cards.first.taggings.first.tag
63
+ assert_equal 'first_tag', tag.read_attribute('name')
64
+ assert_nil tag.read_attribute('card_id')
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hickey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Li Xiao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-17 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: iam@li-xiao.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE.txt
25
+ - TODO
26
+ - CHANGES
27
+ files:
28
+ - lib/hickey/acceptor.rb
29
+ - lib/hickey/domain_detector/actions.rb
30
+ - lib/hickey/domain_detector/associations.rb
31
+ - lib/hickey/domain_detector/base.rb
32
+ - lib/hickey/domain_detector/configurable.rb
33
+ - lib/hickey/domain_detector/scopes.rb
34
+ - lib/hickey/domain_detector.rb
35
+ - lib/hickey.rb
36
+ - CHANGES
37
+ - hickey.gemspec
38
+ - lib
39
+ - LICENSE.TXT
40
+ - Rakefile
41
+ - README.rdoc
42
+ - TODO
43
+ - LICENSE.txt
44
+ has_rdoc: true
45
+ homepage: http://github.com/xli/hickey/tree/master
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --line-numbers
49
+ - --inline-source
50
+ - --main
51
+ - README.rdoc
52
+ - --title
53
+ - Hickey
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: hickey
71
+ rubygems_version: 1.2.0
72
+ signing_key:
73
+ specification_version: 2
74
+ summary: Hickey provides a simple way of preparing test data inside test for Rails project.
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