rails3_plugin_toolbox 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/plugin_toolbox/rspec/matchers/be_extended_with.rb +10 -5
- data/lib/plugin_toolbox/util.rb +20 -4
- data/rails3_plugin_toolbox.gemspec +1 -1
- data/spec/plugin_toolbox/extend_view_content_spec.rb +3 -0
- data/spec/plugin_toolbox/extender_action_spec.rb +1 -0
- data/spec/plugin_toolbox/extender_spec.rb +9 -12
- data/spec/spec_helper.rb +8 -7
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
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
|
-
|
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
|
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
|
-
"
|
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
|
|
data/lib/plugin_toolbox/util.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
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
|
@@ -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
|
@@ -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
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
require '
|
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
|