johnsbrn-classy-inheritance 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,17 @@
1
+ desc 'Generate website files'
2
+ task :website_generate => :ruby_env do
3
+ (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
+ sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
+ end
6
+ end
7
+
8
+ desc 'Upload website files to rubyforge'
9
+ task :website_upload do
10
+ host = "#{rubyforge_username}@rubyforge.org"
11
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
+ local_dir = 'website'
13
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
+ end
15
+
16
+ desc 'Generate and upload website files'
17
+ task :website => [:website_generate, :website_upload, :publish_docs]
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ User.depends_on :profile, :attrs => [:first_name, :last_name, :email]
4
+
5
+ class TestClassyInheritance < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @user = User.new
9
+ end
10
+
11
+ def test_active_record_should_have_classy_inheritance_included
12
+ assert ActiveRecord::Base.included_modules.include?(Stonean::ClassyInheritance)
13
+ end
14
+
15
+ def test_active_record_should_respond_to_depends_on
16
+ assert ActiveRecord::Base.respond_to?(:depends_on)
17
+ end
18
+
19
+ def test_user_should_respond_to_find_with_profile
20
+ assert User.respond_to?(:find_with_profile)
21
+ end
22
+
23
+ def test_user_should_respond_to_first_name
24
+ assert @user.respond_to?(:first_name)
25
+ end
26
+
27
+ def test_user_should_respond_to_first_name=
28
+ assert @user.respond_to?(:first_name=)
29
+ end
30
+
31
+ def test_user_should_respond_to_last_name
32
+ assert @user.respond_to?(:last_name)
33
+ end
34
+
35
+ def test_user_should_respond_to_last_name=
36
+ assert @user.respond_to?(:last_name=)
37
+ end
38
+
39
+ def test_user_should_respond_to_email
40
+ assert @user.respond_to?(:email)
41
+ end
42
+
43
+ def test_user_should_respond_to_email=
44
+ assert @user.respond_to?(:email=)
45
+ end
46
+
47
+ def test_user_should_be_invalid_without_profile_attributes
48
+ @user.login = 'joe'
49
+ assert !@user.valid?
50
+ end
51
+
52
+ def test_user_should_valid_with_profile_attributes
53
+ @user.login = 'joe'
54
+ @user.first_name = 'joe'
55
+ @user.last_name = 'bloggs'
56
+ @user.email = 'joe@bloggs.co.uk'
57
+
58
+ assert @user.valid?
59
+ end
60
+
61
+ def test_user_should_have_nice_error_message
62
+ @user = User.new(:first_name => "andy")
63
+ @user.valid?
64
+
65
+ assert @user.errors.full_messages.include?("Last name can't be blank")
66
+ assert @user.errors.full_messages.include?("Email can't be blank")
67
+ assert @user.errors.full_messages.include?("Login can't be blank")
68
+ end
69
+
70
+ end
@@ -0,0 +1,136 @@
1
+ require 'rubygems'
2
+ require 'activerecord'
3
+
4
+ require 'test/unit'
5
+ require File.dirname(__FILE__) + '/../lib/classy-inheritance'
6
+
7
+ ActiveRecord::Base.establish_connection({
8
+ :adapter => "sqlite3",
9
+ :dbfile => "test/database.sqlite3"
10
+ })
11
+
12
+ class SetupTestTables < ActiveRecord::Migration
13
+ def self.up
14
+ create_table :profiles, :force => true do |t|
15
+ t.string :first_name
16
+ t.string :last_name
17
+ t.string :email
18
+
19
+ t.timestamps
20
+ end
21
+
22
+ create_table :users, :force => true do |t|
23
+ t.string :login
24
+ t.integer :profile_id
25
+
26
+ t.timestamps
27
+ end
28
+
29
+ create_table :authors, :force => true do |t|
30
+ t.string :login
31
+ t.integer :profile_id
32
+
33
+ t.timestamps
34
+ end
35
+
36
+ create_table :artists, :force => true do |t|
37
+ t.string :login
38
+ t.integer :profile_id
39
+
40
+ t.timestamps
41
+ end
42
+
43
+ create_table :addresses, :force => true do |t|
44
+ t.string :line_one
45
+ t.string :line_two
46
+ t.string :city
47
+ t.string :state_code
48
+ t.string :postal_code
49
+
50
+ t.timestamps
51
+ end
52
+
53
+ create_table :offices, :force => true do |t|
54
+ t.string :name
55
+ t.integer :billing_address_id
56
+ t.integer :shipping_address_id
57
+
58
+ t.timestamps
59
+ end
60
+
61
+ create_table :contents, :force => true do |t|
62
+ t.string :name
63
+ t.string :presentable_type
64
+ t.integer :presentable_id
65
+
66
+ t.timestamps
67
+ end
68
+
69
+ create_table :pages, :force => true do |t|
70
+ t.text :body
71
+
72
+ t.timestamps
73
+ end
74
+
75
+ create_table :documents, :force => true do |t|
76
+ t.string :version_file_name
77
+ t.string :version_content_type
78
+ t.integer :version_file_size
79
+
80
+ t.timestamps
81
+ end
82
+ end
83
+
84
+ def self.down
85
+ drop_table :authors
86
+ drop_table :artists
87
+ drop_table :users
88
+ drop_table :profiles
89
+ drop_table :offices
90
+ drop_table :addresses
91
+ drop_table :pages
92
+ drop_table :documents
93
+ drop_table :contents
94
+ end
95
+ end
96
+
97
+ SetupTestTables.migrate(:up)
98
+
99
+ class Profile < ActiveRecord::Base
100
+ validates_presence_of :first_name, :last_name, :email
101
+ end
102
+
103
+ class User < ActiveRecord::Base
104
+ validates_presence_of :login
105
+ end
106
+
107
+ class Author < ActiveRecord::Base
108
+ validates_presence_of :login
109
+ end
110
+
111
+ # to test optional dependency
112
+ class Artist < ActiveRecord::Base
113
+ validates_presence_of :login
114
+ end
115
+
116
+ # to test using standard relationship options (class_name, etc..)
117
+ class Address < ActiveRecord::Base
118
+ validates_presence_of :line_one, :city, :postal_code
119
+ end
120
+
121
+ class Office < ActiveRecord::Base
122
+ validates_presence_of :name
123
+ end
124
+
125
+ # Polymorphic classes
126
+ class Content < ActiveRecord::Base
127
+ validates_presence_of :name
128
+ end
129
+
130
+ class Page < ActiveRecord::Base
131
+ validates_presence_of :body
132
+ end
133
+
134
+ # Would typically use PaperClip for this...
135
+ class Document < ActiveRecord::Base
136
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ Content.can_be :document, :as => :presentable
4
+
5
+ Page.depends_on :content, :attrs => [:name], :as => :presentable
6
+
7
+ class TestPolymorphicAssociations < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @page = Page.new
11
+
12
+ @test_page = Page.create(:name => 'My Page', :body => 'Something interesting')
13
+ @test_content = @test_page.content
14
+ end
15
+
16
+ # from Content.can_be declaration
17
+ def test_document_should_respond_to_find_with_content
18
+ assert Document.respond_to?(:find_with_content)
19
+ end
20
+
21
+ def test_page_should_respond_to_name
22
+ assert @page.respond_to?(:name)
23
+ end
24
+
25
+ def test_page_should_fail_validation_without_content_name
26
+ @page.body = 'Some really informative stuff that would be a lot longer'
27
+ assert !@page.valid?
28
+ end
29
+
30
+ def test_page_should_pass_validation_with_content_name
31
+ @page.name = 'First Page'
32
+ @page.body = 'Some really informative stuff that would be a lot longer'
33
+ assert @page.valid?
34
+ end
35
+
36
+ def test_page_should_create_content
37
+ @page.name = 'First Page'
38
+ @page.body = 'Some really informative stuff that would be a lot longer'
39
+ @page.save
40
+
41
+ assert @page.content.id != nil
42
+ end
43
+
44
+ def test_content_should_respond_to_is_a_document
45
+ assert @test_content.respond_to?(:is_a_document?)
46
+ end
47
+
48
+ def test_content_should_respond_to_as_a_document
49
+ assert @test_content.respond_to?(:as_a_document)
50
+ end
51
+
52
+ def test_content_should_respond_to_is_a_page
53
+ assert @test_content.respond_to?(:is_a_page?)
54
+ end
55
+
56
+ def test_content_should_respond_to_as_a_page
57
+ assert @test_content.respond_to?(:as_a_page)
58
+ end
59
+
60
+ def test_content_should_return_page_object
61
+ assert @test_content.as_a_page.is_a?(Page)
62
+ end
63
+
64
+ end
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestWithOptionalDependency < Test::Unit::TestCase
4
+ # Turn off the validates_presence_of call
5
+ Author.depends_on :profile, :validates_presence_if => false,
6
+ :attrs => [:first_name, :last_name, :email]
7
+
8
+ # Turn off the validates_presence_of and the validates_associated calls
9
+ Artist.depends_on :profile, :validates_presence_if => false,
10
+ :validates_associated_if => false,
11
+ :attrs => [:first_name, :last_name, :email]
12
+
13
+ def setup
14
+ @author = Author.new
15
+ @artist = Artist.new
16
+ end
17
+
18
+ def test_author_should_be_valid_without_profile
19
+ @author.login = 'joe'
20
+
21
+ @author.valid?
22
+ puts @author.errors.full_messages.to_sentence
23
+
24
+ assert @author.valid?
25
+ end
26
+
27
+ def test_author_should_be_invalid_with_invalid_profile
28
+ @author.login = 'joe'
29
+ @author.first_name = 'joe'
30
+
31
+ assert !@author.valid?
32
+ end
33
+
34
+ def test_author_should_be_valid_with_profile_attributes
35
+ @author.login = 'joe'
36
+ @author.first_name = 'joe'
37
+ @author.last_name = 'bloggs'
38
+ @author.email = 'joe@bloggs.co.uk'
39
+
40
+ assert @author.valid?
41
+ end
42
+
43
+ def test_artist_should_not_save_with_invalid_profile
44
+ @artist.login = 'joe'
45
+ @artist.first_name = 'joe'
46
+
47
+ assert !@artist.save
48
+ end
49
+
50
+ def test_artist_should_save_with_valid_profile
51
+ @artist.login = 'joe'
52
+ @artist.first_name = 'joe'
53
+ @artist.last_name = 'bloggs'
54
+ @artist.email = 'joe@bloggs.co.uk'
55
+
56
+ assert @artist.save
57
+ end
58
+
59
+ end
@@ -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