acts_as_singleton 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ === 0.0.4 / 2010-01-21
2
+
3
+ * 1 bugfix
4
+
5
+ * Allow 'find' calls from ActiveRecord.
6
+
7
+
1
8
  === 0.0.3 / 2009-11-29
2
9
 
3
10
  * 1 bugfix
data/README.rdoc CHANGED
@@ -61,7 +61,7 @@ Configure:
61
61
 
62
62
  And install:
63
63
 
64
- % rake gems:install
64
+ % [sudo] rake gems:install
65
65
 
66
66
 
67
67
  === As a plugin
@@ -81,7 +81,7 @@ Or, as a submodule:
81
81
 
82
82
  (The MIT License)
83
83
 
84
- (c) 2009-* Stephen Celis, stephen@stephencelis.com.
84
+ (c) 2009-2010 Stephen Celis, stephen@stephencelis.com.
85
85
 
86
86
  Permission is hereby granted, free of charge, to any person obtaining a copy
87
87
  of this software and associated documentation files (the "Software"), to deal
@@ -46,6 +46,14 @@ module ActiveRecord
46
46
  def inspect
47
47
  super.sub(/id: .+?, /) {} # Irrelevant.
48
48
  end
49
+
50
+ def find(*args)
51
+ unless caller.first.include?("lib/active_record")
52
+ raise NoMethodError,
53
+ "private method `find' called for #{inspect}"
54
+ end
55
+ super # (:first) || create
56
+ end
49
57
  end
50
58
 
51
59
  def clone
@@ -1,5 +1,4 @@
1
1
  require 'test/unit'
2
- require 'rubygems'
3
2
  require 'active_record'
4
3
  require "#{File.dirname(__FILE__)}/../init"
5
4
  require 'active_support'
@@ -14,6 +13,10 @@ def setup_db
14
13
  t.text :welcome_message
15
14
  t.timestamp :published_at, :expired_at
16
15
  end
16
+
17
+ create_table :cottages do |t|
18
+ t.belongs_to :home_away_from_home, :polymorphic => true
19
+ end
17
20
  end
18
21
  end
19
22
 
@@ -26,11 +29,17 @@ end
26
29
  setup_db
27
30
  class HomepageSettings < ActiveRecord::Base
28
31
  acts_as_singleton
32
+ has_many :cottages, :as => :home_away_from_home
29
33
  end
30
34
 
31
35
  class LoggedInSettings < HomepageSettings
32
36
  end
33
37
 
38
+ class Cottage < ActiveRecord::Base
39
+ belongs_to :home_away_from_home, :polymorphic => true
40
+ validates_associated :home_away_from_home
41
+ end
42
+
34
43
  class ActsAsSingletonTest < ActiveSupport::TestCase
35
44
  setup do
36
45
  setup_db
@@ -38,6 +47,10 @@ class ActsAsSingletonTest < ActiveSupport::TestCase
38
47
 
39
48
  teardown do
40
49
  teardown_db
50
+
51
+ HomepageSettings.instance_eval do
52
+ remove_instance_variable :@instance if defined? @instance
53
+ end
41
54
  end
42
55
 
43
56
  test "should be provocative" do
@@ -78,7 +91,6 @@ class ActsAsSingletonTest < ActiveSupport::TestCase
78
91
  end
79
92
 
80
93
  test "should honor STI" do
81
- ActiveRecord::Base.logger = STDOUT
82
94
  ActiveRecord::Base.clear_active_connections!
83
95
  HomepageSettings.instance # Fetch parent.
84
96
  LoggedInSettings.instance # Fetch child.
@@ -86,4 +98,8 @@ class ActsAsSingletonTest < ActiveSupport::TestCase
86
98
  LoggedInSettings.instance # Fetch again.
87
99
  end
88
100
  end
101
+
102
+ test "should honor polymorphism" do
103
+ HomepageSettings.instance.cottages.create
104
+ end
89
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_singleton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Celis
@@ -9,13 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-29 00:00:00 -05:00
12
+ date: 2010-01-21 00:00:00 -06:00
13
13
  default_executable:
14
- dependencies: []
15
-
16
- description: "A lightweight singleton library for your Active Record models. It just makes sense to store mutable, site-wide, admin-level settings in the database. Right? A key-value table may be more flexible, but maybe we don't want to be flexible! If you truly want that flexibility: http://github.com/stephencelis/kvc"
17
- email:
18
- - stephen@stephencelis.com
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: "It just makes sense to store mutable, site-wide, admin-level settings in the database. Right? A key-value table may be more flexible, but maybe we don't want to be flexible! If you truly want that flexibility: http://github.com/stephencelis/kvc"
26
+ email: stephen@stephencelis.com
19
27
  executables: []
20
28
 
21
29
  extensions: []
@@ -56,10 +64,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
64
  version:
57
65
  requirements: []
58
66
 
59
- rubyforge_project: actsassingleton
67
+ rubyforge_project:
60
68
  rubygems_version: 1.3.5
61
69
  signing_key:
62
70
  specification_version: 3
63
- summary: A lightweight singleton library for your Active Record models
71
+ summary: A lightweight singleton library for your Active Record models.
64
72
  test_files: []
65
73