rails3_plugin_toolbox 0.3.0 → 0.3.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -4,7 +4,7 @@ module Rails3
4
4
  class BeExtendedWith
5
5
  include Rails3::PluginExtender::Util
6
6
 
7
- attr_reader :methods, :module_const, :rails_const, :submodules
7
+ attr_reader :methods, :module_const, :rails_const, :submodules, :bad_const, :cause
8
8
 
9
9
  def initialize(module_const, submodules=nil)
10
10
  @module_const = module_const
@@ -14,10 +14,12 @@ module Rails3
14
14
 
15
15
  def matches? type
16
16
  begin
17
- @rails_const = get_base_class(type)
17
+ @rails_const = get_base_class(type)
18
18
  return match_submodules? if submodules
19
+ @bad_const = module_const
19
20
  methods_included? module_const.instance_methods
20
21
  rescue
22
+ @cause = ", but the extension module wasn't found"
21
23
  false
22
24
  end
23
25
  end
@@ -28,7 +30,10 @@ module Rails3
28
30
 
29
31
  def match_submodules?
30
32
  submodules.each do |name|
31
- return false if !methods_included? get_methods(name)
33
+ @bad_const = make_constant(module_const, name)
34
+ if !methods_included? get_methods(name)
35
+ return false
36
+ end
32
37
  end
33
38
  true
34
39
  end
@@ -42,11 +47,11 @@ module Rails3
42
47
  end
43
48
 
44
49
  def failure_message
45
- "Expected the rails class #{rails_const} to be extended with all the methods in #{module_const}"
50
+ "Expected the rails class #{rails_const} to be extended with the methods in #{bad_const}#{cause}"
46
51
  end
47
52
 
48
53
  def negative_failure_message
49
- "Din not expect the rails class #{rails_const} to be extended with all the methods in #{module_const}"
54
+ "Did not expect the rails class #{rails_const} to be extended with the methods in #{module_const}"
50
55
  end
51
56
  end
52
57
 
@@ -5,13 +5,29 @@ module Rails3
5
5
  ACTIVE_MODULES = {:AR => :active_record, :view => :action_view, :controller => :action_controller, :mailer => :action_mailer}
6
6
 
7
7
  def get_base_class type
8
- type = get_load_type(type).to_s
9
- return "#{type.to_s.camelize}::Base".constantize if type =~/action/ || type =~/active/
10
- "#{type.to_s.camelize}".constantize
8
+ begin
9
+ type = get_load_type(type).to_s
10
+ const = act_type?(type) ? rails_const_base(type) : "#{type.to_s.camelize}"
11
+ const.constantize
12
+ rescue
13
+ raise ArgumentError, "Can't find rails constant: #{const}"
14
+ end
15
+ end
16
+
17
+ def act_type? type
18
+ type =~/action/ || type =~/active/
11
19
  end
12
20
 
13
21
  def get_constant base_name, name
14
- "#{base_name.to_s.camelize}::#{name.to_s.camelize}".constantize
22
+ make_constant(base_name, name).constantize
23
+ end
24
+
25
+ def rails_const_base type
26
+ "#{type.to_s.camelize}::Base"
27
+ end
28
+
29
+ def make_constant base_name, name
30
+ "#{base_name.to_s.camelize}::#{name.to_s.camelize}"
15
31
  end
16
32
 
17
33
  def get_load_type type
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails3_plugin_toolbox}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
@@ -43,6 +43,9 @@ describe Rails3::PluginExtender do
43
43
 
44
44
  :view.should be_extended_with Helper::View, :panel, :window, :button, :form
45
45
  :view.should_not be_extended_with Helper::View, :unknown
46
+
47
+ lambda {:view.should be_extended_with Helper::View, :unknown}.should raise_error
48
+ # :view.should be_extended_with Helper::View, :unknown
46
49
  end
47
50
  end
48
51
  end
@@ -4,6 +4,7 @@ describe Rails3::PluginExtender do
4
4
  describe '#extend_rails' do
5
5
  it "should extend Action View" do
6
6
  extender = Rails3::PluginExtender.new
7
+
7
8
  extender.extend_rails :view do
8
9
  with MyAddition
9
10
 
@@ -1,20 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
+ def extend_unknown
4
+ Rails3::PluginExtender.new do
5
+ extend_rails :unknown do
6
+ with MyAddition
7
+ end
8
+ end
9
+ end
10
+
3
11
  describe Rails3::PluginExtender do
4
12
  describe '#extend_rails' do
5
13
  it "should NOT extend Unknown" do
6
- lambda do
7
- Rails3::PluginExtender.new
8
- extend_rails :unknown do
9
- with MyAddition
10
- end
11
- end
12
- end.should raise_error
13
-
14
- # Initialize the rails application
15
- Minimal::Application.initialize!
16
-
17
- MyAddition.heard.should == null
14
+ lambda { extend_unknown }.should raise_error
18
15
  end
19
16
 
20
17
  it "should extend Active Record" do
data/spec/spec_helper.rb CHANGED
@@ -4,13 +4,14 @@ require 'rails3_plugin_toolbox'
4
4
 
5
5
  # See http://www.igvita.com/2010/08/04/rails-3-internals-railtie-creating-plugins/
6
6
 
7
- # require 'active_support'
8
- # require 'active_record'
9
- # require 'action_controller'
10
- # require 'action_view'
11
- # require 'action_mailer'
12
- # require 'active_support/railtie'
13
- require 'rails/all'
7
+
8
+ require 'active_record'
9
+ require 'action_mailer'
10
+ require 'active_support'
11
+ require 'action_controller'
12
+ require 'action_view'
13
+ require 'active_support/railtie'
14
+ # require 'rails/all'
14
15
 
15
16
  module Minimal
16
17
  class Application < Rails::Application
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup