autolink 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,10 +14,10 @@ Then add this to your 'spec/spec_helper.rb', under the line that requires 'spec/
14
14
 
15
15
  Now add this to any models that you want to autolink:
16
16
 
17
- def self.default_lineage(object)
18
- [:path, :to, :model, object.parent, object]
17
+ def default_lineage
18
+ [:path, :to, :model, parent, self]
19
19
  end
20
20
 
21
- This default lineage works exactly like ActionController's PolymorphicRouting lineage (since that's what it is...). The reason it's a class method rather than an instance method is to deal with some sticky mock-related issues.
21
+ This default lineage works exactly like ActionController's PolymorphicRouting lineage (since that's what it is...).
22
22
 
23
23
  I make no guarantees that this will work for you.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'autolink'
3
- gem.version = "0.0.2"
3
+ gem.version = "1.0.0"
4
4
 
5
5
  gem.author, gem.email = 'Burke Libbey', "burke@burkelibbey.org"
6
6
  gem.homepage = "http://github.com/burke/autolink"
@@ -1,3 +1,2 @@
1
1
  require 'autolink/action_controller_extensions'
2
2
  require 'autolink/action_view_extensions'
3
- require 'autolink/active_record_extensions'
@@ -2,7 +2,7 @@ module ActionController #:nodoc:
2
2
  class Base
3
3
 
4
4
  def autolink(obj)
5
- polymorphic_url(obj.class.default_lineage(obj))
5
+ polymorphic_url(obj.default_lineage)
6
6
  end
7
7
 
8
8
  def url_for(options = {})
@@ -4,8 +4,8 @@ module ActionView
4
4
  def url_for(options = {})
5
5
  options ||= {}
6
6
  url = case options
7
- when ActiveRecord::Base # This method is the same as 2.3.8,
8
- polymorphic_path(options.class.default_lineage(options)) # Except for the addition of these two lines.
7
+ when ActiveRecord::Base # This method is the same as 2.3.8,
8
+ polymorphic_path(options.default_lineage) # Except for the addition of these two lines.
9
9
  when String
10
10
  escape = true
11
11
  options
@@ -21,5 +21,36 @@ module Spec
21
21
 
22
22
  end
23
23
  end
24
+
25
+ module Mocks
26
+
27
+ def __post_mock_model(model_class, mock)
28
+
29
+ mock.__send__(:__mock_proxy).instance_eval <<-CODE
30
+ def @target.default_lineage
31
+ # self == @target
32
+ syms = __mock_proxy.instance_variable_get("@stubs").map(&:sym)
33
+ @__sub = #{model_class}.new
34
+ syms.each do |sym|
35
+ # Define this method to call the same method on @target.
36
+ that = self
37
+ (class << @__sub; self; end).send(:define_method, sym) do
38
+ that.send(sym)
39
+ end
40
+ end
41
+ @__sub.default_lineage
42
+ end
43
+ CODE
44
+
45
+ mock
46
+ end
47
+
48
+ alias __mock_model mock_model
49
+ def mock_model(model_class, options_and_stubs = {})
50
+ mock = __mock_model(model_class, options_and_stubs)
51
+ __post_mock_model(model_class, mock)
52
+ end
53
+ end
54
+
24
55
  end
25
56
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autolink
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Burke Libbey
@@ -30,7 +30,6 @@ extra_rdoc_files: []
30
30
  files:
31
31
  - lib/autolink/action_controller_extensions.rb
32
32
  - lib/autolink/action_view_extensions.rb
33
- - lib/autolink/active_record_extensions.rb
34
33
  - lib/autolink/rspec.rb
35
34
  - lib/autolink.rb
36
35
  - spec/spec_helper.rb
@@ -1,9 +0,0 @@
1
- class ActiveRecord::Base
2
- def default_lineage
3
- if self.class.respond_to?(:default_lineage)
4
- self.class.default_lineage(self)
5
- else
6
- raise "default_lineage() has not been implemented for this class"
7
- end
8
- end
9
- end