bourgeois 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 1.9.3
6
+
7
+ script: "echo 'DO IT' && bundle exec rake spec"
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in bourgeois.gemspec
4
2
  gemspec
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Bourgeois
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/bourgeois.png)](https://rubygems.org/gems/bourgeois)
4
+ [![Build Status](https://travis-ci.org/mirego/bourgeois.png?branch=master)](https://travis-ci.org/mirego/bourgeois)
5
+
3
6
  Bourgeois is a Ruby library that makes using presenters a very simple thing.
4
7
 
5
8
  ## Installation
@@ -50,5 +53,6 @@ Bourgeois was inspired by some code [@rafBM](https://twitter.com/rafBM) wrote fo
50
53
 
51
54
  ## About Mirego
52
55
 
53
- Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun.
54
- We proudly built mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development").
56
+ Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We proudly build mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development") in beautiful Quebec City.
57
+
58
+ We also love [open-source software](http://open.mirego.com/) and we try to extract as much code as possible from our projects to give back to the community.
data/Rakefile CHANGED
@@ -1,3 +1,11 @@
1
1
  require 'bundler'
2
2
  require 'rake'
3
3
  require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ task default: :spec
7
+
8
+ desc 'Run all specs'
9
+ RSpec::Core::RakeTask.new(:spec) do |task|
10
+ task.pattern = 'spec/**/*_spec.rb'
11
+ end
data/bourgeois.gemspec CHANGED
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.3'
22
- spec.add_development_dependency 'rake'
23
-
24
21
  spec.add_dependency 'activemodel', '>= 3.0.0'
25
22
  spec.add_dependency 'actionpack', '>= 3.0.0'
23
+
24
+ spec.add_development_dependency 'rspec', '~> 2.13'
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake'
26
27
  end
@@ -1,32 +1,40 @@
1
1
  module Bourgeois
2
2
  class Presenter < ::SimpleDelegator
3
- def initialize(object, view)
3
+ def initialize(object, view = nil)
4
4
  @view = view
5
5
  super(@object = object)
6
6
  end
7
7
 
8
+ # Return a String representation of the presenter + the original object
8
9
  def inspect
9
10
  "#<#{self.class} object=#{@object.inspect}>"
10
11
  end
11
12
 
13
+ # We need to explicitely define this method because it's not
14
+ # catched by the delegator
12
15
  def kind_of?(mod)
13
16
  @object.kind_of?(mod)
14
17
  end
15
18
 
19
+ # ActionView::Helpers::FormBuilder needs this
16
20
  def self.model_name
17
21
  klass.model_name
18
22
  end
19
23
 
24
+ # ActionView::Helpers::FormBuilder needs this too
20
25
  def self.human_attribute_name(*args)
21
26
  klass.human_attribute_name(*args)
22
27
  end
23
28
 
24
29
  private
25
30
 
31
+ # Return the view from where the presenter was created
26
32
  def view
27
33
  @view
28
34
  end
29
35
 
36
+ # Return the original object class based on the presenter class name
37
+ # We would be able to use `@object.class` but we need this in class methods
30
38
  def self.klass
31
39
  @klass ||= self.name.split(/Presenter$/).first.constantize
32
40
  end
@@ -1,3 +1,3 @@
1
1
  module Bourgeois
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/bourgeois.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'bourgeois/version'
2
2
 
3
3
  require 'delegate'
4
+ require 'active_model'
5
+ require 'action_view'
6
+
4
7
  require 'bourgeois/presenter'
5
8
  require 'bourgeois/view_helper'
6
9
 
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bourgeois::Presenter do
4
+ let(:user) { User.new first_name: 'Patrick', last_name: 'Bourgeois' }
5
+ let(:view) { ActionView::Base.new }
6
+ let(:presenter) { UserPresenter.new(user, view) }
7
+
8
+ describe :DelegatedMethods do
9
+ before do
10
+ class UserPresenter < Bourgeois::Presenter
11
+ def formatted_name
12
+ "#{first_name} #{last_name}".strip
13
+ end
14
+ end
15
+
16
+ class User < OpenStruct
17
+ end
18
+ end
19
+
20
+ it { expect(presenter.formatted_name).to eql 'Patrick Bourgeois' }
21
+ it { expect(presenter.first_name).to eql 'Patrick' }
22
+ it { expect(presenter.last_name).to eql 'Bourgeois' }
23
+ end
24
+
25
+ describe :InstanceMethods do
26
+ describe :initialize do
27
+ before do
28
+ class UserPresenter < Bourgeois::Presenter; end
29
+ class User < OpenStruct; end
30
+ end
31
+
32
+ it { expect{ UserPresenter.new(user) }.to_not raise_error }
33
+ end
34
+
35
+ describe :view do
36
+ context 'with present view' do
37
+ before do
38
+ class UserPresenter < Bourgeois::Presenter
39
+ def local_name
40
+ view.t('users.attributes.local_name')
41
+ end
42
+ end
43
+
44
+ class ActionView::Base
45
+ def t(*args)
46
+ "Fancy translated string from #{args.join(', ')}"
47
+ end
48
+ end
49
+
50
+ class User < OpenStruct; end
51
+ end
52
+
53
+ it { expect(presenter.local_name).to eql 'Fancy translated string from users.attributes.local_name' }
54
+ end
55
+
56
+ context 'with blank view' do
57
+ before do
58
+ class UserPresenter < Bourgeois::Presenter; end
59
+ class User < OpenStruct; end
60
+ end
61
+
62
+ let(:presenter) { UserPresenter.new(user) }
63
+
64
+ it { expect(presenter.instance_variable_get(:@view)).to be_nil }
65
+ end
66
+ end
67
+
68
+ describe :inspect do
69
+ before do
70
+ class UserPresenter < Bourgeois::Presenter; end
71
+ class User < OpenStruct; end
72
+ end
73
+ let(:user) { User.new foo: 'bar' }
74
+
75
+ it { expect(presenter.inspect).to eql '#<UserPresenter object=#<User foo="bar">>' }
76
+ end
77
+ end
78
+
79
+ describe :ClassMethods do
80
+ describe :kind_of? do
81
+ before do
82
+ class UserPresenter < Bourgeois::Presenter; end
83
+ class User < OpenStruct; end
84
+ end
85
+
86
+ it { expect(presenter).to be_kind_of(User) }
87
+ end
88
+
89
+ describe :model_name do
90
+ before do
91
+ class UserPresenter < Bourgeois::Presenter; end
92
+ class User < OpenStruct; end
93
+
94
+ User.should_receive(:model_name).and_return(:foo)
95
+ end
96
+
97
+ it { expect(UserPresenter.model_name).to eql :foo }
98
+ end
99
+
100
+ describe :human_attribute_name do
101
+ before do
102
+ class UserPresenter < Bourgeois::Presenter; end
103
+ class User < OpenStruct; end
104
+
105
+ User.should_receive(:human_attribute_name).and_return(:foo)
106
+ end
107
+
108
+ it { expect(UserPresenter.human_attribute_name).to eql :foo }
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'ostruct'
4
+ require 'rspec'
5
+ require 'bourgeois'
6
+
7
+ RSpec.configure do |config|
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bourgeois
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,72 +9,88 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-27 00:00:00.000000000 Z
12
+ date: 2013-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: bundler
15
+ name: activemodel
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '1.3'
22
- type: :development
21
+ version: 3.0.0
22
+ type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '1.3'
29
+ version: 3.0.0
30
30
  - !ruby/object:Gem::Dependency
31
- name: rake
31
+ name: actionpack
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
37
+ version: 3.0.0
38
+ type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: 3.0.0
46
46
  - !ruby/object:Gem::Dependency
47
- name: activemodel
47
+ name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 3.0.0
54
- type: :runtime
53
+ version: '2.13'
54
+ type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 3.0.0
61
+ version: '2.13'
62
62
  - !ruby/object:Gem::Dependency
63
- name: actionpack
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
64
80
  requirement: !ruby/object:Gem::Requirement
65
81
  none: false
66
82
  requirements:
67
83
  - - ! '>='
68
84
  - !ruby/object:Gem::Version
69
- version: 3.0.0
70
- type: :runtime
85
+ version: '0'
86
+ type: :development
71
87
  prerelease: false
72
88
  version_requirements: !ruby/object:Gem::Requirement
73
89
  none: false
74
90
  requirements:
75
91
  - - ! '>='
76
92
  - !ruby/object:Gem::Version
77
- version: 3.0.0
93
+ version: '0'
78
94
  description: Bourgeois is a Ruby library that makes using presenters a very simple
79
95
  thing.
80
96
  email:
@@ -84,6 +100,8 @@ extensions: []
84
100
  extra_rdoc_files: []
85
101
  files:
86
102
  - .gitignore
103
+ - .rspec
104
+ - .travis.yml
87
105
  - Gemfile
88
106
  - LICENSE.md
89
107
  - README.md
@@ -94,6 +112,8 @@ files:
94
112
  - lib/bourgeois/railtie.rb
95
113
  - lib/bourgeois/version.rb
96
114
  - lib/bourgeois/view_helper.rb
115
+ - spec/bourgeois/presenter_spec.rb
116
+ - spec/spec_helper.rb
97
117
  homepage: https://github.com/mirego/bourgeois
98
118
  licenses:
99
119
  - BSD 3-Clause
@@ -109,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
129
  version: '0'
110
130
  segments:
111
131
  - 0
112
- hash: -1720415151698695919
132
+ hash: -4422150060977082943
113
133
  required_rubygems_version: !ruby/object:Gem::Requirement
114
134
  none: false
115
135
  requirements:
@@ -118,11 +138,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
138
  version: '0'
119
139
  segments:
120
140
  - 0
121
- hash: -1720415151698695919
141
+ hash: -4422150060977082943
122
142
  requirements: []
123
143
  rubyforge_project:
124
144
  rubygems_version: 1.8.23
125
145
  signing_key:
126
146
  specification_version: 3
127
147
  summary: Bourgeois is a Ruby library that makes using presenters a very simple thing.
128
- test_files: []
148
+ test_files:
149
+ - spec/bourgeois/presenter_spec.rb
150
+ - spec/spec_helper.rb