base_presenter 0.0.7 → 0.0.8

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.
@@ -6,7 +6,7 @@ require 'base_presenter/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "base_presenter"
8
8
  spec.version = BasePresenter::VERSION
9
- spec.date = '2013-10-11'
9
+ spec.date = '2013-10-15'
10
10
  spec.authors = ["Michał Szyma"]
11
11
  spec.email = ["raglub.ruby@gmail.com"]
12
12
  spec.description = %q{The gem adds "Presenter" functionality into Rails application}
@@ -5,7 +5,7 @@ module ApplicationHelper
5
5
  if object_or_class.methods.include?(:new)
6
6
  klass ||= "#{object_or_class}Presenter".constantize
7
7
  presenter = klass
8
- presenter.template = self
8
+ presenter.initialize(object_or_class, self)
9
9
  else
10
10
  klass ||= "#{object_or_class.class}Presenter".constantize
11
11
  presenter = klass.new(object_or_class, self)
@@ -21,19 +21,19 @@ class BasePresenter
21
21
  end
22
22
  end
23
23
 
24
- class << self
25
- attr_accessor :template
26
-
27
- def presents(name)
28
- define_method(name) do
29
- @object
30
- end
31
- end
24
+ def self.initialize(object, template)
25
+ @@object = object
26
+ @@template = template
27
+ end
32
28
 
33
- def method_missing(*args, &block)
34
- @@template.send(*args, &block)
29
+ def self.presents(name)
30
+ define_method(name) do
31
+ @object
35
32
  end
33
+ end
36
34
 
35
+ def self.method_missing(*args, &block)
36
+ @@template.send(*args, &block)
37
37
  end
38
38
 
39
39
  end
@@ -1,3 +1,3 @@
1
1
  class BasePresenter
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ class DummyModelPresenter < BasePresenter
3
+ presents :dummy
4
+
5
+ def get_object
6
+ dummy
7
+ end
8
+
9
+ def get_template
10
+ @template
11
+ end
12
+
13
+ def self.get_object
14
+ @@object
15
+ end
16
+
17
+ def self.get_template
18
+ @@template
19
+ end
20
+ end
21
+
22
+ describe ApplicationHelper do
23
+
24
+ let(:dummy_model) { DummyModel.new }
25
+
26
+ describe "for DummyModel object" do
27
+ it "should initialize presenter with properly template" do
28
+ helper.present(dummy_model).get_template.should be_an(ActionView::Base)
29
+ end
30
+
31
+ it "should initialize presenter with properly object model" do
32
+ helper.present(dummy_model).get_object.should eq dummy_model
33
+ end
34
+ end
35
+
36
+ describe "for DummyModel class" do
37
+ it "should initialize presenter with properly template" do
38
+ helper.present(DummyModel).get_template.should be_an(ActionView::Base)
39
+ end
40
+
41
+ it "should initialize presenter with properly object model" do
42
+ helper.present(DummyModel).get_object.should eq DummyModel
43
+ end
44
+ end
45
+ end
@@ -15,14 +15,11 @@ end
15
15
  describe ApplicationHelper do
16
16
  let(:dummy_model) { DummyModel.new }
17
17
 
18
- let(:dummy_presenter) do
19
- helper.present(dummy_model)
20
- end
18
+ let(:template) { ActionView::Base.new }
19
+
20
+ let(:dummy_presenter) { DummyModelPresenter.new(dummy_model, template) }
21
21
 
22
22
  describe "without block" do
23
- it "should initialize presenter" do
24
- dummy_presenter
25
- end
26
23
 
27
24
  it "#presents" do
28
25
  dummy_presenter.dummy.should eq dummy_model
@@ -45,13 +42,5 @@ describe ApplicationHelper do
45
42
  value = nil
46
43
  dummy_presenter.handle_none(value) {value}.should match('<span class')
47
44
  end
48
-
49
- it ".template" do
50
- helper.present(DummyModel).template.should_not be_nil
51
- end
52
-
53
- it "should show class name" do
54
- helper.present(DummyModel).name.should eq("Class name")
55
- end
56
45
  end
57
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: base_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-11 00:00:00.000000000 Z
12
+ date: 2013-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -113,7 +113,8 @@ files:
113
113
  - spec/dummy/config/routes.rb
114
114
  - spec/dummy/db/seeds.rb
115
115
  - spec/dummy/log/test.log
116
- - spec/helpers/base_presenter_spec.rb
116
+ - spec/helpers/application_helper_spec.rb
117
+ - spec/presenters/base_presenter_spec.rb
117
118
  - spec/spec_helper.rb
118
119
  homepage: https://github.com/raglub/base_presenter
119
120
  licenses:
@@ -163,5 +164,6 @@ test_files:
163
164
  - spec/dummy/config/routes.rb
164
165
  - spec/dummy/db/seeds.rb
165
166
  - spec/dummy/log/test.log
166
- - spec/helpers/base_presenter_spec.rb
167
+ - spec/helpers/application_helper_spec.rb
168
+ - spec/presenters/base_presenter_spec.rb
167
169
  - spec/spec_helper.rb