classy-inheritance 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.6.0 2008-07-18
2
+ * Add: new option: postfix
3
+ * Add: Expanded prefix,postfix functionality to either accept true or values to prefix/postix attribute with.
4
+ * Add: Tests to support new options
1
5
  == 0.5.0 2008-07-08
2
6
  * Add: new options: validates_presence_if, validates_associated_if to allow for greater control over validation use.
3
7
  * Add: Basic test cases of classy-inheritance depends_on functionality.
@@ -50,7 +50,7 @@ module Stonean
50
50
  define_find_with_method(model_sym)
51
51
 
52
52
  if options[:as]
53
- define_can_be_method_on_requisite_class(model_sym, options[:as])
53
+ define_can_be_method_on_requisite_class(options[:class_name] || model_sym, options[:as])
54
54
  end
55
55
 
56
56
  options[:attrs].each{|attr| define_accessors(model_sym, attr, options)}
@@ -78,7 +78,7 @@ module Stonean
78
78
  private
79
79
 
80
80
  def classy_options
81
- [:as, :attrs, :prefix, :validates_presence_if, :validates_associated_if]
81
+ [:as, :attrs, :prefix, :postfix, :validates_presence_if, :validates_associated_if]
82
82
  end
83
83
 
84
84
  def delete_classy_options(options, *keepers)
@@ -145,7 +145,15 @@ module Stonean
145
145
  end
146
146
 
147
147
  def define_accessors(model_sym, attr, options)
148
- accessor_method_name = ( options[:prefix] ? "#{model_sym}_#{attr}" : attr)
148
+ accessor_method_name = attr
149
+
150
+ if options[:prefix]
151
+ accessor_method_name = (options[:prefix] == true) ? "#{model_sym}_#{accessor_method_name}" : "#{options[:prefix]}_#{accessor_method_name}"
152
+ end
153
+
154
+ if options[:postfix]
155
+ accessor_method_name = (options[:postfix] == true) ? "#{accessor_method_name}_#{model_sym}" : "#{accessor_method_name}_#{options[:postfix]}"
156
+ end
149
157
 
150
158
  define_method accessor_method_name do
151
159
  eval("self.#{model_sym} ? self.#{model_sym}.#{attr} : nil")
@@ -1,7 +1,7 @@
1
1
  module ClassyInheritance #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 5
4
+ MINOR = 6
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -0,0 +1,96 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ Office.depends_on :billing_address,
4
+ :attrs => [:line_one, :line_two, :city, :state_code, :postal_code],
5
+ :class_name => "Address",
6
+ :foreign_key => "billing_address_id",
7
+ :postfix => true
8
+
9
+ Office.depends_on :shipping_address,
10
+ :attrs => [:line_one, :line_two, :city, :state_code, :postal_code],
11
+ :class_name => "Address",
12
+ :foreign_key => "shipping_address_id",
13
+ :prefix => "shipping"
14
+
15
+ User.depends_on :profile, :attrs => [:first_name, :last_name, :email], :prefix => "personal", :postfix => "information"
16
+
17
+ class TestWithPrefixPostfix < Test::Unit::TestCase
18
+ def setup
19
+ @office = Office.new
20
+ @user = User.new
21
+ end
22
+
23
+ def test_office_should_respond_to_line_one_billing_address
24
+ assert_respond_to(@office, :line_one_billing_address)
25
+ end
26
+
27
+ def test_office_should_respond_to_line_two_billing_address
28
+ assert_respond_to(@office, :line_two_billing_address)
29
+ end
30
+
31
+ def test_office_should_respond_to_city_billing_address
32
+ assert_respond_to(@office, :city_billing_address)
33
+ end
34
+
35
+ def test_office_should_respond_to_billing_address_state_code
36
+ assert_respond_to(@office, :billing_address_state_code)
37
+ end
38
+
39
+ def test_office_should_respond_to_postal_code_billing_address
40
+ assert_respond_to(@office, :postal_code_billing_address)
41
+ end
42
+
43
+ def test_office_should_respond_to_shipping_line_one
44
+ assert_respond_to(@office, :shipping_line_one)
45
+ end
46
+
47
+ def test_office_should_respond_to_shipping_line_two
48
+ assert_respond_to(@office, :shipping_line_two)
49
+ end
50
+
51
+ def test_office_should_respond_to_shipping_city
52
+ assert_respond_to(@office, :shipping_city)
53
+ end
54
+
55
+ def test_office_should_respond_to_shipping_state_code
56
+ assert_respond_to(@office, :shipping_state_code)
57
+ end
58
+
59
+ def test_office_should_respond_to_shipping_postal_code
60
+ assert_respond_to(@office, :shipping_postal_code)
61
+ end
62
+
63
+ def test_office_should_create_billing_and_shipping_address_records
64
+ @office.name = 'Initest'
65
+
66
+ @office.line_one_billing_address = '123 Somewhere'
67
+ @office.city_billing_address = 'Somecity'
68
+ @office.postal_code_billing_address = '12345'
69
+
70
+ @office.shipping_line_one = '999 MyHouse'
71
+ @office.shipping_city = 'Mycity'
72
+ @office.shipping_postal_code = '98765'
73
+
74
+ @office.save
75
+
76
+ @billing_address = Address.find(@office.billing_address_id)
77
+ @shipping_address = Address.find(@office.shipping_address_id)
78
+
79
+ assert_equal @billing_address, @office.billing_address
80
+
81
+ assert_equal @shipping_address, @office.shipping_address
82
+ end
83
+
84
+ def test_user_should_respond_to_personal_first_name_information
85
+ assert_respond_to(@user,:personal_first_name_information)
86
+ end
87
+
88
+ def test_user_should_respond_to_personal_last_name_information
89
+ assert_respond_to(@user,:personal_last_name_information)
90
+ end
91
+
92
+ def test_user_should_respond_to_personal_email_information
93
+ assert_respond_to(@user,:personal_email_information)
94
+ end
95
+
96
+ end
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>Classy Inheritance</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/classyinherit"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/classyinherit" class="numbers">0.5.0</a>
36
+ <a href="http://rubyforge.org/projects/classyinherit" class="numbers">0.6.0</a>
37
37
  </div>
38
38
  <p><i>&#8220;You stay classy, inheritance&#8221; &#8211; Gibson</i></p>
39
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classy-inheritance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Stone
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-08 00:00:00 -04:00
12
+ date: 2008-07-18 00:00:00 -04:00
13
13
  default_executable:
14
- dependencies: []
15
-
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: 1.7.0
24
+ version:
16
25
  description: Adds a depends_on class method to your ActiveRecord model so that you can define requisite objects.
17
26
  email:
18
27
  - andy@stonean.com
@@ -77,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
86
  requirements: []
78
87
 
79
88
  rubyforge_project: classyinherit
80
- rubygems_version: 1.1.1
89
+ rubygems_version: 1.2.0
81
90
  signing_key:
82
91
  specification_version: 2
83
92
  summary: Adds a depends_on class method to your ActiveRecord model so that you can define requisite objects.
@@ -86,4 +95,5 @@ test_files:
86
95
  - test/test_helper.rb
87
96
  - test/test_polymorphic_associations.rb
88
97
  - test/test_with_optional_dependency.rb
98
+ - test/test_with_prefix_postfix.rb
89
99
  - test/test_with_standard_attributes.rb