active-component 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_component/base.rb +4 -0
- data/lib/active_component/context.rb +10 -0
- data/lib/active_component/railtie.rb +0 -1
- data/lib/active_component/renderable.rb +17 -9
- data/lib/active_component/version.rb +1 -1
- data/test/active_component/base_test.rb +3 -3
- data/test/active_component/context_test.rb +16 -1
- data/test/active_component/railtie_test.rb +8 -2
- data/test/active_component/renderable_test.rb +9 -1
- data/test/dummy/log/test.log +65 -0
- data/test/support/foo_component.mustache +1 -0
- data/test/support/foo_component.rb +3 -0
- data/test/test_helper.rb +1 -0
- metadata +19 -3
- data/test/support/foo.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7de4ea36b77ba8216a9ac0c9788cf5fdc15a64f
|
4
|
+
data.tar.gz: 5eba3cd8f644f1fdd92d2875c6176b895b162a8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4619068c02a72ad5aeee95e4a6c9495fa551b41b5cd19515b798f104f34d64f6c96bbd1926e2fc0683048fde8c4910e29df26557ff4606096f4e01a4fe0b9cab
|
7
|
+
data.tar.gz: 24f96ae408f07f70d7464dd26105a90c300c1852914e47da7226930694f2ae96db0fb005b5c78f0093fb5cd41453dc528b7bb70f629286fc01026700ab3ab71e
|
@@ -1,4 +1,5 @@
|
|
1
1
|
#
|
2
|
+
#
|
2
3
|
# This is an autoincluded module for ActionController::Base
|
3
4
|
#
|
4
5
|
# It will store the controller context for the given request in a
|
@@ -15,6 +16,15 @@ module ActiveComponent
|
|
15
16
|
@@controllers = {}
|
16
17
|
|
17
18
|
class << self
|
19
|
+
|
20
|
+
def controllers
|
21
|
+
if Rails.env.test?
|
22
|
+
@@controllers
|
23
|
+
else
|
24
|
+
puts "WARNING: ActiveComponent#controllers cannot be accessible from outside of the class"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
18
28
|
def get_controller
|
19
29
|
@@controllers[Thread.current.object_id]
|
20
30
|
end
|
@@ -6,7 +6,6 @@ module ActiveComponent
|
|
6
6
|
initializer "Appends a method to the action controller class" do
|
7
7
|
ActiveSupport.on_load(:action_controller) do
|
8
8
|
ActionController::Base.send(:include, ActiveComponent::Context)
|
9
|
-
ActionController::Base.send(:include, ActiveComponent::Renderable)
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
@@ -1,20 +1,28 @@
|
|
1
1
|
require 'active_support/concern'
|
2
2
|
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# This provides a clean implementation for rendering your template
|
5
|
+
# inside your view.
|
5
6
|
#
|
6
|
-
#
|
7
|
-
# render view components nicely from the view or even respond
|
8
|
-
# with them from a controller instance
|
9
|
-
#
|
10
|
-
# render_component(:view_component, var: var)
|
7
|
+
# <%= render_component(:view, var: var) %>
|
11
8
|
#
|
12
9
|
module ActiveComponent
|
13
10
|
module Renderable
|
14
|
-
extend ActiveSupport::Concern
|
15
11
|
|
16
|
-
def render_component
|
17
|
-
""
|
12
|
+
def render_component(type, args={})
|
13
|
+
resource = constantize("#{type.to_s}_component").new(args)
|
14
|
+
resource.render
|
15
|
+
end
|
16
|
+
|
17
|
+
def constantize(type)
|
18
|
+
type = type.camelize.constantize
|
19
|
+
unless type.superclass == ActiveComponent::Base
|
20
|
+
raise TypeError, ":type must be compliant to any existing component class"
|
21
|
+
end
|
22
|
+
type
|
18
23
|
end
|
24
|
+
|
19
25
|
end
|
20
26
|
end
|
27
|
+
|
28
|
+
ActionView::Base.send(:include, ActiveComponent::Renderable)
|
@@ -4,7 +4,7 @@ class ActiveComponent::BaseTest < ActiveSupport::TestCase
|
|
4
4
|
|
5
5
|
setup do
|
6
6
|
FooController.new.get_context
|
7
|
-
@foo =
|
7
|
+
@foo = FooComponent.new(bar: "bar")
|
8
8
|
end
|
9
9
|
|
10
10
|
test "has included date helper from action view" do
|
@@ -12,11 +12,11 @@ class ActiveComponent::BaseTest < ActiveSupport::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
test "a new instance of active_component/base accepts only a hash of arguments" do
|
15
|
-
assert_nothing_raised(ArgumentError, nil) {
|
15
|
+
assert_nothing_raised(ArgumentError, nil) { FooComponent.new(bar: Faker::Name.name) }
|
16
16
|
end
|
17
17
|
|
18
18
|
test "a new instance of active component should raise an error if the given value is not a hash" do
|
19
|
-
assert_raise(ArgumentError, nil) {
|
19
|
+
assert_raise(ArgumentError, nil) { FooComponent.new(Faker::Lorem.sentence) }
|
20
20
|
end
|
21
21
|
|
22
22
|
test "assigns the values to instance variables" do
|
@@ -2,9 +2,24 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ActiveComponent::ContextTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
|
5
|
+
def setup
|
6
6
|
FooController.new.get_context
|
7
|
+
end
|
8
|
+
|
9
|
+
test "returns a cotroller instance" do
|
7
10
|
assert_kind_of FooController, ActiveComponent.get_controller
|
8
11
|
end
|
9
12
|
|
13
|
+
test "saves the controller in a @@controllers hash" do
|
14
|
+
assert_nothing_raised Exception do
|
15
|
+
ActiveComponent.set_controller(FooController.new)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
test "it returns exactly the same controller sent" do
|
20
|
+
controller = FooController.new
|
21
|
+
controller.get_context
|
22
|
+
assert_equal controller, ActiveComponent.controllers[Thread.current.object_id]
|
23
|
+
end
|
24
|
+
|
10
25
|
end
|
@@ -2,8 +2,14 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ActiveComponent::RailtieTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
test "
|
6
|
-
|
5
|
+
test "has before filter" do
|
6
|
+
assert_equal :get_context, ActionController::Base.new._process_action_callbacks.first.filter
|
7
|
+
end
|
8
|
+
|
9
|
+
test "has the context method" do
|
10
|
+
assert_nothing_raised Exception do
|
11
|
+
ActionController::Base.new.get_context
|
12
|
+
end
|
7
13
|
end
|
8
14
|
|
9
15
|
end
|
@@ -3,7 +3,15 @@ require 'test_helper'
|
|
3
3
|
class ActiveComponent::RenderableTest < ActiveSupport::TestCase
|
4
4
|
|
5
5
|
test "renders a component" do
|
6
|
-
|
6
|
+
FooComponent.any_instance.stubs(:render).returns("")
|
7
|
+
assert_nothing_raised TypeError do
|
8
|
+
ActionView::Base.new.render_component(:foo)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
test "gets a component instance from symbol" do
|
13
|
+
FooComponent.any_instance.stubs(:render).returns("")
|
14
|
+
assert_kind_of String, ActionView::Base.new.render_component(:foo)
|
7
15
|
end
|
8
16
|
|
9
17
|
end
|
data/test/dummy/log/test.log
CHANGED
@@ -2777,3 +2777,68 @@ ActiveComponent::RenderableTest: test_renders_a_component
|
|
2777
2777
|
ActiveComponentTest: test_has_a_get_controller_method
|
2778
2778
|
-----------------------------------------------------
|
2779
2779
|
[1m[35m (0.1ms)[0m rollback transaction
|
2780
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
2781
|
+
--------------------------------------------------------------------------------------------------------
|
2782
|
+
ActiveComponent::BaseTest: test_a_new_instance_of_active_component/base_accepts_only_a_hash_of_arguments
|
2783
|
+
--------------------------------------------------------------------------------------------------------
|
2784
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2785
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2786
|
+
-------------------------------------------------------------------------------------------------------------------------
|
2787
|
+
ActiveComponent::BaseTest: test_a_new_instance_of_active_component_should_raise_an_error_if_the_given_value_is_not_a_hash
|
2788
|
+
-------------------------------------------------------------------------------------------------------------------------
|
2789
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
2790
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2791
|
+
------------------------------------------------------------------------
|
2792
|
+
ActiveComponent::BaseTest: test_assigns_the_values_to_instance_variables
|
2793
|
+
------------------------------------------------------------------------
|
2794
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
2795
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2796
|
+
-------------------------------------------------------------------------
|
2797
|
+
ActiveComponent::BaseTest: test_has_included_date_helper_from_action_view
|
2798
|
+
-------------------------------------------------------------------------
|
2799
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2800
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2801
|
+
-------------------------------------------------------------------------
|
2802
|
+
ActiveComponent::BaseTest: test_sets_controller_for_the_component_context
|
2803
|
+
-------------------------------------------------------------------------
|
2804
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2805
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2806
|
+
------------------------------------------------------------------------------
|
2807
|
+
ActiveComponent::ContextTest: test_it_returns_exactly_the_same_controller_sent
|
2808
|
+
------------------------------------------------------------------------------
|
2809
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2810
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2811
|
+
---------------------------------------------------------------
|
2812
|
+
ActiveComponent::ContextTest: test_returns_a_cotroller_instance
|
2813
|
+
---------------------------------------------------------------
|
2814
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2815
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2816
|
+
-------------------------------------------------------------------------------
|
2817
|
+
ActiveComponent::ContextTest: test_saves_the_controller_in_a_@@controllers_hash
|
2818
|
+
-------------------------------------------------------------------------------
|
2819
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
2820
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2821
|
+
----------------------------------------------------
|
2822
|
+
ActiveComponent::RailtieTest: test_has_before_filter
|
2823
|
+
----------------------------------------------------
|
2824
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2825
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2826
|
+
---------------------------------------------------------
|
2827
|
+
ActiveComponent::RailtieTest: test_has_the_context_method
|
2828
|
+
---------------------------------------------------------
|
2829
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
2830
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2831
|
+
---------------------------------------------------------------------------
|
2832
|
+
ActiveComponent::RenderableTest: test_gets_a_component_instance_from_symbol
|
2833
|
+
---------------------------------------------------------------------------
|
2834
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2835
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2836
|
+
---------------------------------------------------------
|
2837
|
+
ActiveComponent::RenderableTest: test_renders_a_component
|
2838
|
+
---------------------------------------------------------
|
2839
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2840
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2841
|
+
-----------------------------------------------------
|
2842
|
+
ActiveComponentTest: test_has_a_get_controller_method
|
2843
|
+
-----------------------------------------------------
|
2844
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antonio Chavez
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - '>='
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: mocha
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
description: A View-Component framework for Rails applications.
|
85
99
|
email:
|
86
100
|
- cavjzz@gmail.com
|
@@ -159,7 +173,8 @@ files:
|
|
159
173
|
- test/dummy/tmp/cache/assets/development/sprockets/edbef6e0d0a4742346cf479f2c522eb0
|
160
174
|
- test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655
|
161
175
|
- test/generators/component_generator_test.rb
|
162
|
-
- test/support/
|
176
|
+
- test/support/foo_component.mustache
|
177
|
+
- test/support/foo_component.rb
|
163
178
|
- test/support/foo_controller.rb
|
164
179
|
- test/test_helper.rb
|
165
180
|
homepage: https://github.com/TheNaoX/active_component
|
@@ -245,7 +260,8 @@ test_files:
|
|
245
260
|
- test/dummy/tmp/cache/assets/development/sprockets/edbef6e0d0a4742346cf479f2c522eb0
|
246
261
|
- test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655
|
247
262
|
- test/generators/component_generator_test.rb
|
248
|
-
- test/support/
|
263
|
+
- test/support/foo_component.mustache
|
264
|
+
- test/support/foo_component.rb
|
249
265
|
- test/support/foo_controller.rb
|
250
266
|
- test/test_helper.rb
|
251
267
|
has_rdoc:
|
data/test/support/foo.rb
DELETED