polymorphic_identity 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.
- data/MIT-LICENSE +1 -1
- data/README +4 -0
- data/Rakefile +4 -4
- data/test/test_helper.rb +5 -30
- data/test/unit/polymorphic_identity_test.rb +14 -4
- metadata +11 -15
- data/test/app_root/config/boot.rb +0 -13
- data/test/app_root/config/database.yml +0 -22
- data/test/app_root/config/environment.rb +0 -45
data/MIT-LICENSE
CHANGED
data/README
CHANGED
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rake/gempackagetask'
|
|
4
4
|
require 'rake/contrib/sshpublisher'
|
5
5
|
|
6
6
|
PKG_NAME = 'polymorphic_identity'
|
7
|
-
PKG_VERSION = '0.0.
|
7
|
+
PKG_VERSION = '0.0.2'
|
8
8
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
9
9
|
RUBY_FORGE_PROJECT = 'pluginaweek'
|
10
10
|
|
@@ -14,7 +14,7 @@ task :default => :test
|
|
14
14
|
desc 'Test the polymorphic_identity plugin.'
|
15
15
|
Rake::TestTask.new(:test) do |t|
|
16
16
|
t.libs << 'lib'
|
17
|
-
t.pattern = 'test
|
17
|
+
t.pattern = 'test/**/*_test.rb'
|
18
18
|
t.verbose = true
|
19
19
|
end
|
20
20
|
|
@@ -37,10 +37,10 @@ spec = Gem::Specification.new do |s|
|
|
37
37
|
s.require_path = 'lib'
|
38
38
|
s.autorequire = 'polymorphic_identity'
|
39
39
|
s.has_rdoc = true
|
40
|
-
s.test_files = Dir['test
|
40
|
+
s.test_files = Dir['test/**/*_test.rb']
|
41
41
|
s.add_dependency 'activerecord', '>= 1.15.0'
|
42
42
|
|
43
|
-
s.author = 'Aaron Pfeifer
|
43
|
+
s.author = 'Aaron Pfeifer, Neil Abraham'
|
44
44
|
s.email = 'info@pluginaweek.org'
|
45
45
|
s.homepage = 'http://www.pluginaweek.org'
|
46
46
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,31 +1,6 @@
|
|
1
|
-
# Load the
|
2
|
-
|
3
|
-
require
|
1
|
+
# Load the plugin testing framework
|
2
|
+
$:.unshift("#{File.dirname(__FILE__)}/../../../../test/plugin_test_helper/lib")
|
3
|
+
require 'rubygems'
|
4
|
+
require 'plugin_test_helper'
|
4
5
|
|
5
|
-
#
|
6
|
-
require 'test/unit'
|
7
|
-
require 'active_record/fixtures'
|
8
|
-
|
9
|
-
# Load the plugin
|
10
|
-
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
11
|
-
require File.dirname(__FILE__) + '/../init'
|
12
|
-
|
13
|
-
# Run the migrations
|
14
|
-
ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate")
|
15
|
-
|
16
|
-
# Load fixtures
|
17
|
-
Test::Unit::TestCase.fixture_path = "#{APP_ROOT}/test/fixtures/"
|
18
|
-
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
19
|
-
|
20
|
-
class Test::Unit::TestCase #:nodoc:
|
21
|
-
def create_fixtures(*table_names)
|
22
|
-
if block_given?
|
23
|
-
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
|
24
|
-
else
|
25
|
-
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
self.use_transactional_fixtures = true
|
30
|
-
self.use_instantiated_fixtures = false
|
31
|
-
end
|
6
|
+
ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
|
@@ -7,15 +7,25 @@ end
|
|
7
7
|
class PolymorphicIdentityTest < Test::Unit::TestCase
|
8
8
|
fixtures :authors, :articles, :pages, :users, :comments
|
9
9
|
|
10
|
-
def
|
10
|
+
def test_should_find_polymorphic_association_name_for_valid_symbolized_association
|
11
11
|
c = Comment.new
|
12
12
|
c.commenter_type = 'Article'
|
13
13
|
assert_equal :commenter, c.find_polymorphic_association_name(:article)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_find_polymorphic_association_name_for_valid_stringified_association
|
17
|
+
c = Comment.new
|
18
|
+
c.commenter_type = 'Article'
|
14
19
|
assert_equal :commenter, c.find_polymorphic_association_name('article')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_not_find_polymorphic_association_name_for_invalid_association
|
23
|
+
c = Comment.new
|
24
|
+
c.commenter_type = 'Article'
|
15
25
|
assert_equal nil, c.find_polymorphic_association_name('page')
|
16
26
|
end
|
17
27
|
|
18
|
-
def
|
28
|
+
def test_should_not_respond_to_polymorhic_association_name_if_association_is_nil
|
19
29
|
([Comment.new] + Comment.find(:all)).each do |c|
|
20
30
|
c.commentable = nil if c.commentable
|
21
31
|
c.commenter = nil if c.commenter
|
@@ -27,7 +37,7 @@ class PolymorphicIdentityTest < Test::Unit::TestCase
|
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
30
|
-
def
|
40
|
+
def test_should_respond_to_polymorphic_association_name_if_association_exists
|
31
41
|
c = comments(:article_test_author_john_doe)
|
32
42
|
assert c.respond_to?(:article)
|
33
43
|
assert c.respond_to?(:author)
|
@@ -41,7 +51,7 @@ class PolymorphicIdentityTest < Test::Unit::TestCase
|
|
41
51
|
assert_equal users(:anonymous), c.user
|
42
52
|
end
|
43
53
|
|
44
|
-
def
|
54
|
+
def test_should_update_response_when_changing_polymorphic_association
|
45
55
|
c = comments(:article_test_author_john_doe)
|
46
56
|
c.commentable = pages(:about)
|
47
57
|
c.commenter = users(:anonymous)
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.2
|
3
3
|
specification_version: 1
|
4
4
|
name: polymorphic_identity
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2007-08-05 00:00:00 -04:00
|
8
8
|
summary: Dynamically generates aliases for polymorphic associations based on their class names
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -27,38 +27,34 @@ signing_key:
|
|
27
27
|
cert_chain:
|
28
28
|
post_install_message:
|
29
29
|
authors:
|
30
|
-
- Aaron Pfeifer
|
30
|
+
- Aaron Pfeifer, Neil Abraham
|
31
31
|
files:
|
32
32
|
- lib/polymorphic_identity.rb
|
33
|
-
- test/unit
|
34
|
-
- test/test_helper.rb
|
35
33
|
- test/app_root
|
36
|
-
- test/unit/polymorphic_identity_test.rb
|
37
34
|
- test/app_root/app
|
38
|
-
- test/app_root/config
|
39
|
-
- test/app_root/db
|
40
|
-
- test/app_root/test
|
41
35
|
- test/app_root/app/models
|
42
|
-
- test/app_root/app/models/user.rb
|
43
36
|
- test/app_root/app/models/article.rb
|
44
|
-
- test/app_root/app/models/comment.rb
|
45
37
|
- test/app_root/app/models/author.rb
|
38
|
+
- test/app_root/app/models/comment.rb
|
46
39
|
- test/app_root/app/models/page.rb
|
47
|
-
- test/app_root/
|
48
|
-
- test/app_root/
|
49
|
-
- test/app_root/config/environment.rb
|
40
|
+
- test/app_root/app/models/user.rb
|
41
|
+
- test/app_root/db
|
50
42
|
- test/app_root/db/migrate
|
51
43
|
- test/app_root/db/migrate/001_create_authors.rb
|
52
44
|
- test/app_root/db/migrate/002_create_articles.rb
|
53
45
|
- test/app_root/db/migrate/003_create_pages.rb
|
54
46
|
- test/app_root/db/migrate/004_create_users.rb
|
55
47
|
- test/app_root/db/migrate/005_create_comments.rb
|
48
|
+
- test/app_root/test
|
56
49
|
- test/app_root/test/fixtures
|
57
50
|
- test/app_root/test/fixtures/articles.yml
|
58
51
|
- test/app_root/test/fixtures/authors.yml
|
59
52
|
- test/app_root/test/fixtures/comments.yml
|
60
53
|
- test/app_root/test/fixtures/pages.yml
|
61
54
|
- test/app_root/test/fixtures/users.yml
|
55
|
+
- test/test_helper.rb
|
56
|
+
- test/unit
|
57
|
+
- test/unit/polymorphic_identity_test.rb
|
62
58
|
- init.rb
|
63
59
|
- MIT-LICENSE
|
64
60
|
- Rakefile
|
@@ -1,13 +0,0 @@
|
|
1
|
-
unless defined?(APP_ROOT)
|
2
|
-
root_path = File.join(File.dirname(__FILE__), '..')
|
3
|
-
|
4
|
-
unless RUBY_PLATFORM =~ /mswin32/
|
5
|
-
require 'pathname'
|
6
|
-
root_path = Pathname.new(root_path).cleanpath(true).to_s
|
7
|
-
end
|
8
|
-
|
9
|
-
APP_ROOT = root_path
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'rubygems'
|
13
|
-
require 'active_record'
|
@@ -1,22 +0,0 @@
|
|
1
|
-
in_memory:
|
2
|
-
adapter: sqlite3
|
3
|
-
database: ":memory:"
|
4
|
-
verbosity: quiet
|
5
|
-
sqlite:
|
6
|
-
adapter: sqlite
|
7
|
-
dbfile: polymorphic_identity_test.sqlite.db
|
8
|
-
sqlite3:
|
9
|
-
adapter: sqlite3
|
10
|
-
dbfile: polymorphic_identity_test.sqlite3.db
|
11
|
-
postgresql:
|
12
|
-
adapter: postgresql
|
13
|
-
username: postgres
|
14
|
-
password: postgres
|
15
|
-
database: polymorphic_identity_test
|
16
|
-
min_messages: ERROR
|
17
|
-
mysql:
|
18
|
-
adapter: mysql
|
19
|
-
host: localhost
|
20
|
-
username: root
|
21
|
-
password:
|
22
|
-
database: polymorphic_identity_test
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'boot')
|
2
|
-
|
3
|
-
# set_load_path
|
4
|
-
load_paths = %w(app app/models config vendor).collect {|dir| "#{APP_ROOT}/#{dir}"}
|
5
|
-
load_paths.reverse_each {|dir| $LOAD_PATH.unshift("#{APP_ROOT}/#{dir}") if File.directory?(dir)}
|
6
|
-
$LOAD_PATH.uniq!
|
7
|
-
|
8
|
-
# set_autoload_paths
|
9
|
-
Dependencies.load_paths = load_paths
|
10
|
-
|
11
|
-
# load_environment
|
12
|
-
APP_ENV = ENV['DB']
|
13
|
-
|
14
|
-
# initialize_database
|
15
|
-
ActiveRecord::Base.configurations = YAML::load(IO.read("#{APP_ROOT}/config/database.yml"))
|
16
|
-
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[APP_ENV])
|
17
|
-
|
18
|
-
# initializer_logger
|
19
|
-
log_path = "#{APP_ROOT}/log/#{APP_ENV}.log"
|
20
|
-
begin
|
21
|
-
logger = Logger.new(log_path)
|
22
|
-
logger.level = Logger::DEBUG
|
23
|
-
rescue StandardError
|
24
|
-
logger = Logger.new(STDERR)
|
25
|
-
logger.level = Logger::WARN
|
26
|
-
logger.warn(
|
27
|
-
"Logger Error: Unable to access log file. Please ensure that #{log_path} exists and is chmod 0666. " +
|
28
|
-
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
# initialize_framework_logging
|
33
|
-
ActiveRecord::Base.logger = logger
|
34
|
-
|
35
|
-
# initialize_dependency_mechanism
|
36
|
-
Dependencies.mechanism = :require
|
37
|
-
|
38
|
-
# initialize_breakpoints
|
39
|
-
require 'active_support/breakpoint'
|
40
|
-
|
41
|
-
# initialize_whiny_nils
|
42
|
-
# require('active_support/whiny_nil')
|
43
|
-
|
44
|
-
# load_observers
|
45
|
-
ActiveRecord::Base.instantiate_observers
|