base_presenter 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,4 +1,12 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
4
  - 1.9.3
4
5
  - 2.0.0
6
+
7
+ env:
8
+ - "RAILS_VERSION=4.1"
9
+ - "RAILS_VERSION=4.0"
10
+ - "RAILS_VERSION=3.2"
11
+ - "RAILS_VERSION=3.1"
12
+ - "RAILS_VERSION=3.0"
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # BasePresenter
2
- [![Gem Version](https://badge.fury.io/rb/base_presenter.png)](http://badge.fury.io/rb/base_presenter)
2
+ [![Gem Version](https://badge.fury.io/rb/base_presenter.png)](http://badge.fury.io/rb/base_presenter)
3
3
  [![Build Status](https://travis-ci.org/raglub/base_presenter.png?branch=master)](https://travis-ci.org/raglub/base_presenter)
4
+ [![Code Climate](https://codeclimate.com/github/raglub/base_presenter.png)](https://codeclimate.com/github/raglub/base_presenter)
4
5
 
5
6
  The gem adds "Presenter" functionality into Rails application.
6
7
 
@@ -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-26'
9
+ spec.date = '2013-10-28'
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.}
@@ -19,8 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake"
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
24
  spec.add_development_dependency 'rspec-rails'
25
- spec.add_development_dependency 'rails', ">= 3.0.0"
25
+ spec.add_development_dependency 'rails', '>= 3.0.0'
26
+ spec.add_development_dependency 'simplecov'
27
+
26
28
  end
@@ -1,5 +1,5 @@
1
1
  module ApplicationHelper
2
- def present(object_or_class, klass = nil)
2
+ def present(object_or_class, klass = nil, &block)
3
3
  presenter = nil
4
4
 
5
5
  if object_or_class.methods.include?(:new)
@@ -8,22 +8,19 @@ class BasePresenter
8
8
  @template = template
9
9
  end
10
10
 
11
- def method_missing(*args, &block)
12
- @template.send(*args, &block)
11
+ def self.initialize(object, template)
12
+ @@object = object
13
+ @@template = template
13
14
  end
14
15
 
15
- # Return span with 'None given' when value is blank
16
- def handle_none(value)
17
- if value.present?
18
- yield
19
- else
20
- content_tag :span, "None given", class: "none"
21
- end
16
+ private
17
+
18
+ def method_missing(*args, &block)
19
+ @template.send(*args, &block)
22
20
  end
23
21
 
24
- def self.initialize(object, template)
25
- @@object = object
26
- @@template = template
22
+ def self.method_missing(*args, &block)
23
+ @@template.send(*args, &block)
27
24
  end
28
25
 
29
26
  def self.presents(name)
@@ -32,8 +29,13 @@ class BasePresenter
32
29
  end
33
30
  end
34
31
 
35
- def self.method_missing(*args, &block)
36
- @@template.send(*args, &block)
32
+ # Return span with 'None given' when value is blank
33
+ def handle_none(value)
34
+ if value.present?
35
+ yield
36
+ else
37
+ content_tag :span, "None given", class: "none"
38
+ end
37
39
  end
38
40
 
39
41
  end
@@ -1,3 +1,3 @@
1
1
  class BasePresenter
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -1,23 +1,4 @@
1
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
2
 
22
3
  describe ApplicationHelper do
23
4
 
@@ -29,7 +10,23 @@ describe ApplicationHelper do
29
10
  end
30
11
 
31
12
  it "should initialize presenter with properly object model" do
32
- helper.present(dummy_model).get_object.should eq dummy_model
13
+ present(dummy_model).get_object.should eq dummy_model
14
+ end
15
+
16
+ it "should valid presenter method using block without variable" do
17
+ result = ""
18
+ present(dummy_model) do
19
+ result += dummy_name
20
+ end
21
+ result.should eq "DUMMY"
22
+ end
23
+
24
+ it "should valid presenter method using block with variable" do
25
+ result = ""
26
+ present(dummy_model) do |dummy_presenter|
27
+ result += dummy_presenter.dummy_name
28
+ end
29
+ result.should eq "DUMMY"
33
30
  end
34
31
  end
35
32
 
@@ -39,7 +36,16 @@ describe ApplicationHelper do
39
36
  end
40
37
 
41
38
  it "should initialize presenter with properly object model" do
42
- helper.present(DummyModel).get_object.should eq DummyModel
39
+ present(DummyModel).get_object.should eq DummyModel
43
40
  end
41
+
42
+ it "should valid presenter method using block" do
43
+ expect do
44
+ helper.present(DummyModel) do |dummy_presenter|
45
+
46
+ end
47
+ end.to_not raise_error
48
+ end
49
+
44
50
  end
45
51
  end
@@ -1,16 +1,4 @@
1
1
  require 'spec_helper'
2
- class DummyModelPresenter < BasePresenter
3
- presents :dummy
4
- delegate :id, to: :dummy
5
-
6
- def name
7
- dummy.name.upcase
8
- end
9
-
10
- def self.name
11
- "Class name"
12
- end
13
- end
14
2
 
15
3
  describe ApplicationHelper do
16
4
  let(:dummy_model) { DummyModel.new }
@@ -35,12 +23,12 @@ describe ApplicationHelper do
35
23
 
36
24
  it "#handle_none with not blank of value" do
37
25
  value = "no empty"
38
- dummy_presenter.handle_none(value) {value}.should eq(value)
26
+ dummy_presenter.show_value(value).should eq(value)
39
27
  end
40
28
 
41
29
  it "#handle_none with not blank of value" do
42
30
  value = nil
43
- dummy_presenter.handle_none(value) {value}.should match('<span class')
31
+ dummy_presenter.show_value(value).should match('<span class')
44
32
  end
45
33
  end
46
34
  end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,10 @@ ENV["RAILS_ENV"] ||= 'test'
3
3
  require ::File.expand_path('../dummy/config/environment', __FILE__)
4
4
  require 'rspec/rails'
5
5
  require 'base_presenter'
6
+ require_relative 'support/dummy_model_presenter'
7
+
8
+ require 'simplecov'
9
+ SimpleCov.start
6
10
 
7
11
  RSpec.configure do |config|
8
12
  config.color_enabled = true
@@ -0,0 +1,40 @@
1
+ class DummyModelPresenter < BasePresenter
2
+ presents :dummy
3
+
4
+ delegate :id, to: :dummy
5
+
6
+ def show_value(value)
7
+ handle_none(value) do
8
+ value
9
+ end
10
+ end
11
+
12
+ def name
13
+ dummy.name.upcase
14
+ end
15
+
16
+ def self.name
17
+ "Class name"
18
+ end
19
+
20
+ def dummy_name
21
+ "DUMMY"
22
+ end
23
+
24
+ def get_object
25
+ dummy
26
+ end
27
+
28
+ def get_template
29
+ @template
30
+ end
31
+
32
+ def self.get_object
33
+ @@object
34
+ end
35
+
36
+ def self.get_template
37
+ @@template
38
+ end
39
+
40
+ 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.9
4
+ version: 0.0.10
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-26 00:00:00.000000000 Z
12
+ date: 2013-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: 3.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
78
94
  description: The gem adds "Presenter" functionality into Rails application.
79
95
  email:
80
96
  - raglub.ruby@gmail.com
@@ -120,6 +136,7 @@ files:
120
136
  - spec/helpers/application_helper_spec.rb
121
137
  - spec/presenters/base_presenter_spec.rb
122
138
  - spec/spec_helper.rb
139
+ - spec/support/dummy_model_presenter.rb
123
140
  homepage: https://github.com/raglub/base_presenter
124
141
  licenses:
125
142
  - MIT
@@ -171,3 +188,4 @@ test_files:
171
188
  - spec/helpers/application_helper_spec.rb
172
189
  - spec/presenters/base_presenter_spec.rb
173
190
  - spec/spec_helper.rb
191
+ - spec/support/dummy_model_presenter.rb