active_decorator 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b4ff2ae758a8f2c1a18ff85c02a06cfe4227815d
4
+ data.tar.gz: 5e8fe96b2279ba2ef44a62d342056e4b6aa6b9fd
5
+ SHA512:
6
+ metadata.gz: b1d64f92890474e35d2e3efcc231f1dd1299c5fd1cee9c6f4e526d8cc1d8c1900d1ce35715f8061129248e8baace4d6034bd50b805ca25b2cd6019117b0acdf1
7
+ data.tar.gz: 7f885ea5e6e225b08edef2c2962affac26d450d0ea7e41af18150f1affdd624f8dabc4018504dfd4c66ad141751421f40cd7d0b828ba561da4f7e93e9e787eda
data/.gitignore CHANGED
@@ -1,7 +1,6 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
- gemfiles/Gemfile-rails.3.0.x.lock
5
- gemfiles/Gemfile-rails.3.1.x.lock
4
+ gemfiles/*.lock
6
5
  pkg/*
7
6
  log
data/.travis.yml CHANGED
@@ -1,21 +1,35 @@
1
1
  language: ruby
2
+
2
3
  script: bundle exec rake spec
4
+
3
5
  rvm:
4
- - 1.8.7
5
6
  - 1.9.3
6
7
  - 2.0.0
8
+ - 2.1
9
+ - 2.2
7
10
  - ruby-head
8
11
  gemfile:
9
- - gemfiles/Gemfile-rails.3.0.x
10
- - gemfiles/Gemfile-rails.3.1.x
11
- - Gemfile
12
+ - gemfiles/Gemfile-rails.3.2.x
13
+ - gemfiles/Gemfile-rails.4.0.x
14
+ - gemfiles/Gemfile-rails.4.1.x
15
+ - gemfiles/Gemfile-rails.4.2.x
16
+
17
+ sudo: false
18
+
12
19
  matrix:
13
- exclude:
14
- - rvm: 2.0.0
20
+ include:
21
+ - rvm: 1.8.7
15
22
  gemfile: gemfiles/Gemfile-rails.3.0.x
16
- - rvm: 2.0.0
23
+ - rvm: 1.8.7
17
24
  gemfile: gemfiles/Gemfile-rails.3.1.x
18
- - rvm: ruby-head
25
+ - rvm: 1.8.7
26
+ gemfile: gemfiles/Gemfile-rails.3.2.x
27
+ - rvm: 1.9.3
19
28
  gemfile: gemfiles/Gemfile-rails.3.0.x
20
- - rvm: ruby-head
29
+ - rvm: 1.9.3
21
30
  gemfile: gemfiles/Gemfile-rails.3.1.x
31
+ exclude:
32
+ - rvm: ruby-head
33
+ gemfile: gemfiles/Gemfile-rails.3.2.x
34
+ allow_failures:
35
+ - rvm: ruby-head
data/Gemfile CHANGED
@@ -2,7 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '~> 3.2.0'
5
+ gem 'rails', '~> 4.0.0'
6
6
  gem 'rspec-rails'
7
7
  gem 'capybara', '>= 2'
8
8
  gem 'sqlite3'
9
+ gem 'jbuilder'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ActiveDecorator
2
2
 
3
- A simple and Rubyish view helper for Rails 3. Keep your helpers and views Object-Oriented!
3
+ A simple and Rubyish view helper for Rails 3 and Rails 4. Keep your helpers and views Object-Oriented!
4
4
 
5
5
 
6
6
  ## Features ##
@@ -14,7 +14,7 @@ A simple and Rubyish view helper for Rails 3. Keep your helpers and views Object
14
14
 
15
15
  ## Supported versions ##
16
16
 
17
- Rails 3.0.x, 3.1.x, 3.2.x, and 4.0 (edge)
17
+ Rails 3.0.x, 3.1.x, 3.2.x, 4.0.x, and 4.1 (edge)
18
18
 
19
19
 
20
20
  ## Supported ORMs ##
@@ -32,34 +32,36 @@ You can use the generator for doing this ( `% rails g decorator user` )
32
32
 
33
33
  ## Examples ##
34
34
 
35
- # app/models/user.rb
36
- class User < ActiveRecord::Base
37
- # first_name:string last_name:string website:string
38
- end
39
-
40
- # app/decorators/user_decorator.rb
41
- module UserDecorator
42
- def full_name
43
- "#{first_name} #{last_name}"
44
- end
45
-
46
- def link
47
- link_to full_name, website
48
- end
49
- end
50
-
51
- # app/controllers/users_controller.rb
52
- class UsersController < ApplicationController
53
- def index
54
- @users = User.all
55
- end
56
- end
57
-
58
- # app/views/users/index.html.erb
59
- <% @users.each do |user| %>
60
- <%= user.link %><br>
61
- <% end %>
62
-
35
+ ```ruby
36
+ # app/models/user.rb
37
+ class User < ActiveRecord::Base
38
+ # first_name:string last_name:string website:string
39
+ end
40
+
41
+ # app/decorators/user_decorator.rb
42
+ module UserDecorator
43
+ def full_name
44
+ "#{first_name} #{last_name}"
45
+ end
46
+
47
+ def link
48
+ link_to full_name, website
49
+ end
50
+ end
51
+
52
+ # app/controllers/users_controller.rb
53
+ class UsersController < ApplicationController
54
+ def index
55
+ @users = User.all
56
+ end
57
+ end
58
+ ```
59
+ ```erb
60
+ # app/views/users/index.html.erb
61
+ <% @users.each do |user| %>
62
+ <%= user.link %><br>
63
+ <% end %>
64
+ ```
63
65
 
64
66
  ## Contributing to ActiveDecorator ##
65
67
 
@@ -1,8 +1,16 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'active_decorator', :path => '..'
4
4
 
5
5
  gem 'rails', '~> 3.0.0'
6
- gem 'rspec-rails'
7
- gem 'capybara'
6
+ gem 'rspec-rails', '~> 2.14.0'
7
+ gem 'capybara', '~> 2.0.0'
8
+ # rubyzip >=1 doesn't support ruby 1.8
9
+ gem 'rubyzip', '< 1.0.0'
8
10
  gem 'sqlite3'
11
+ gem 'nokogiri', '~> 1.5.0'
12
+ if RUBY_VERSION <= '1.8.7'
13
+ gem 'jbuilder', '< 2'
14
+ else
15
+ gem 'jbuilder'
16
+ end
@@ -1,8 +1,19 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'active_decorator', :path => '..'
4
4
 
5
5
  gem 'rails', '~> 3.1.0'
6
- gem 'rspec-rails'
7
- gem 'capybara'
6
+ gem 'rspec-rails', '~> 2.14.0'
7
+ if RUBY_VERSION <= '1.8.7'
8
+ gem 'i18n', '~> 0.6.11'
9
+ end
10
+ gem 'capybara', '~> 2.0.0'
11
+ # rubyzip >=1 doesn't support ruby 1.8
12
+ gem 'rubyzip', '< 1.0.0'
8
13
  gem 'sqlite3'
14
+ gem 'nokogiri', '~> 1.5.0'
15
+ if RUBY_VERSION <= '1.8.7'
16
+ gem 'jbuilder', '< 2'
17
+ else
18
+ gem 'jbuilder'
19
+ end
@@ -0,0 +1,20 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'active_decorator', :path => '..'
4
+
5
+ gem 'rails', '~> 3.2.0'
6
+ gem 'rspec-rails', '~> 2.14.0'
7
+ if RUBY_VERSION <= '1.8.7'
8
+ gem 'i18n', '~> 0.6.11'
9
+ end
10
+ gem 'capybara', '~> 2.0.0'
11
+ # rubyzip >=1 doesn't support ruby 1.8
12
+ gem 'rubyzip', '< 1.0.0'
13
+ gem 'sqlite3'
14
+ gem 'nokogiri', '~> 1.5.0'
15
+ if RUBY_VERSION <= '1.8.7'
16
+ gem 'jbuilder', '< 2'
17
+ else
18
+ gem 'jbuilder'
19
+ end
20
+ gem 'test-unit'
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'active_decorator', :path => '..'
4
+
5
+ gem 'rails', '~> 4.0.0'
6
+ gem 'rspec-rails'
7
+ gem 'capybara'
8
+ gem 'sqlite3'
9
+ gem 'jbuilder'
10
+ gem 'test-unit'
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'active_decorator', :path => '..'
4
+
5
+ gem 'rails', '~> 4.1.0'
6
+ gem 'rspec-rails'
7
+ gem 'capybara'
8
+ gem 'sqlite3'
9
+ gem 'jbuilder'
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'active_decorator', :path => '..'
4
+
5
+ gem 'rails', '~> 4.2.0'
6
+ gem 'rspec-rails'
7
+ gem 'capybara'
8
+ gem 'sqlite3'
9
+ gem 'jbuilder'
@@ -10,9 +10,10 @@ module ActiveDecorator
10
10
  end
11
11
 
12
12
  def decorate(obj)
13
+ return if defined?(Jbuilder) && Jbuilder === obj
13
14
  return if obj.nil?
14
15
 
15
- if Array === obj
16
+ if obj.is_a?(Array)
16
17
  obj.each do |r|
17
18
  decorate r
18
19
  end
@@ -38,8 +39,12 @@ module ActiveDecorator
38
39
 
39
40
  decorator_name = "#{model_class.name}Decorator"
40
41
  d = decorator_name.constantize
41
- d.send :include, ActiveDecorator::Helpers
42
- @@decorators[model_class] = d
42
+ unless Class === d
43
+ d.send :include, ActiveDecorator::Helpers
44
+ @@decorators[model_class] = d
45
+ else
46
+ @@decorators[model_class] = nil
47
+ end
43
48
  rescue NameError
44
49
  @@decorators[model_class] = nil
45
50
  end
@@ -13,6 +13,7 @@ module ActiveDecorator
13
13
  end
14
14
  ActiveSupport.on_load(:action_mailer) do
15
15
  require 'active_decorator/monkey/abstract_controller/rendering'
16
+ ActionMailer::Base.send :include, ActiveDecorator::ViewContext::Filter
16
17
  end
17
18
  end
18
19
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveDecorator
2
- VERSION = '0.3.4'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require 'spec_helper'
2
+ require '<%= File.exists?('spec/rails_helper.rb') ? 'rails_helper' : 'spec_helper' %>'
3
3
 
4
4
  describe <%= singular_name.camelize %>Decorator do
5
5
  let(:<%= singular_name %>) { <%= class_name %>.new.extend <%= singular_name.camelize %>Decorator }
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe MoviesController, :type => :controller do
4
+ let(:movie){ Movie.create }
5
+
6
+ it 'reveals fakes' do
7
+ expect{ get :show, :id => movie.id }.not_to raise_error
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ json.name @author.name
2
+ json.books @author.books, :partial => 'books/book', :as => :book
@@ -0,0 +1,2 @@
1
+ json.title book.title
2
+ json.reverse_title book.reverse_title
@@ -0,0 +1,4 @@
1
+ <% @books.each do |book| %>
2
+ <%= book.title %>
3
+ <%= book.reverse_title %>
4
+ <% end %>
@@ -1,6 +1,7 @@
1
1
  require 'active_record'
2
2
  require 'action_controller/railtie'
3
3
  require 'action_view/railtie'
4
+ require 'jbuilder'
4
5
 
5
6
  # config
6
7
  ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
@@ -10,6 +11,8 @@ module ActiveDecoratorTestApp
10
11
  config.secret_token = '"confusion" will be my epitaph.'
11
12
  config.session_store :cookie_store, :key => '_myapp_session'
12
13
  config.active_support.deprecation = :log
14
+ config.eager_load = false
15
+ config.action_dispatch.show_exceptions = false
13
16
  end
14
17
  end
15
18
  ActiveDecoratorTestApp::Application.initialize!
@@ -17,8 +20,9 @@ ActiveDecoratorTestApp::Application.initialize!
17
20
  # routes
18
21
  ActiveDecoratorTestApp::Application.routes.draw do
19
22
  resources :authors, :only => [:index, :show] do
20
- resources :books, :only => :show
23
+ resources :books, :only => [:index, :show]
21
24
  end
25
+ resources :movies, :only => :show
22
26
  end
23
27
 
24
28
  # models
@@ -28,6 +32,8 @@ end
28
32
  class Book < ActiveRecord::Base
29
33
  belongs_to :author
30
34
  end
35
+ class Movie < ActiveRecord::Base
36
+ end
31
37
 
32
38
  # helpers
33
39
  module ApplicationHelper; end
@@ -60,16 +66,29 @@ module BookDecorator
60
66
  end
61
67
  end
62
68
 
69
+ # decorator fake
70
+ class MovieDecorator; end
71
+
63
72
  # controllers
64
73
  class ApplicationController < ActionController::Base
65
74
  self.append_view_path File.dirname(__FILE__)
66
75
  end
67
76
  class AuthorsController < ApplicationController
68
77
  def index
69
- if params[:variable_type] == 'array'
70
- @authors = Author.all
78
+ if Author.respond_to?(:scoped)
79
+ # ActiveRecord 3.x
80
+ if params[:variable_type] == 'array'
81
+ @authors = Author.all
82
+ else
83
+ @authors = Author.scoped
84
+ end
71
85
  else
72
- @authors = Author.scoped
86
+ # ActiveRecord 4.x
87
+ if params[:variable_type] == 'array'
88
+ @authors = Author.all.to_a
89
+ else
90
+ @authors = Author.all
91
+ end
73
92
  end
74
93
  end
75
94
 
@@ -78,15 +97,26 @@ class AuthorsController < ApplicationController
78
97
  end
79
98
  end
80
99
  class BooksController < ApplicationController
100
+ def index
101
+ @author = Author.find params[:author_id]
102
+ @books = @author.books
103
+ end
104
+
81
105
  def show
82
106
  @book = Author.find(params[:author_id]).books.find(params[:id])
83
107
  end
84
108
  end
109
+ class MoviesController < ApplicationController
110
+ def show
111
+ @movie = Movie.find params[:id]
112
+ end
113
+ end
85
114
 
86
115
  # migrations
87
116
  class CreateAllTables < ActiveRecord::Migration
88
117
  def self.up
89
118
  create_table(:authors) {|t| t.string :name}
90
119
  create_table(:books) {|t| t.string :title; t.references :author}
120
+ create_table(:movies) {|t| t.string :name}
91
121
  end
92
122
  end
@@ -0,0 +1 @@
1
+ <%= @movie.name %>
@@ -3,10 +3,13 @@ require 'spec_helper'
3
3
  feature 'decorating controller ivar' do
4
4
  background do
5
5
  @matz = Author.create! :name => 'matz'
6
+ @matz.books.create! :title => 'the world of code'
6
7
  Author.create! :name => 'takahashim'
7
8
  end
9
+
8
10
  after do
9
11
  Author.delete_all
12
+ Book.delete_all
10
13
  end
11
14
 
12
15
  scenario 'decorating a model object in ivar' do
@@ -26,4 +29,10 @@ feature 'decorating controller ivar' do
26
29
  page.should have_content 'takahashim'
27
30
  page.should have_content 'takahashim'.reverse
28
31
  end
32
+
33
+ scenario 'decorating model association proxy in ivar' do
34
+ visit "/authors/#{@matz.id}/books"
35
+ page.should have_content 'the world of code'
36
+ page.should have_content 'the world of code'.reverse
37
+ end
29
38
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'decorating partial object in Jbuilder' do
4
+ background do
5
+ Author.create! :name => 'aamine'
6
+ nari = Author.create! :name => 'nari'
7
+ nari.books.create! :title => 'the gc book'
8
+ end
9
+ after do
10
+ Book.delete_all
11
+ Author.delete_all
12
+ end
13
+
14
+ scenario 'decorating objects in Jbuilder partials' do
15
+ visit "/authors/#{Author.last.id}.json"
16
+ page.source.should eq '{"name":"nari","books":[{"title":"the gc book","reverse_title":"koob cg eht"}]}'
17
+ end
18
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,11 +11,16 @@ require 'rspec/rails'
11
11
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
12
 
13
13
  RSpec.configure do |config|
14
+ config.expect_with :rspec do |c|
15
+ c.syntax = [:should, :expect]
16
+ end
17
+
14
18
  config.before :all do
15
19
  CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'authors'
16
20
  end
17
21
  config.before :each do
18
22
  Book.delete_all
19
23
  Author.delete_all
24
+ Movie.delete_all
20
25
  end
21
26
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Akira Matsuda
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
11
+ date: 2015-01-13 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A simple and Rubyish view helper for Rails 3
15
14
  email:
@@ -18,9 +17,9 @@ executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
- - .gitignore
22
- - .rspec
23
- - .travis.yml
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
24
23
  - Gemfile
25
24
  - MIT-LICENSE
26
25
  - README.md
@@ -28,6 +27,10 @@ files:
28
27
  - active_decorator.gemspec
29
28
  - gemfiles/Gemfile-rails.3.0.x
30
29
  - gemfiles/Gemfile-rails.3.1.x
30
+ - gemfiles/Gemfile-rails.3.2.x
31
+ - gemfiles/Gemfile-rails.4.0.x
32
+ - gemfiles/Gemfile-rails.4.1.x
33
+ - gemfiles/Gemfile-rails.4.2.x
31
34
  - lib/active_decorator.rb
32
35
  - lib/active_decorator/decorator.rb
33
36
  - lib/active_decorator/helpers.rb
@@ -42,48 +45,59 @@ files:
42
45
  - lib/generators/rspec/templates/decorator_spec.rb
43
46
  - lib/generators/test_unit/decorator_generator.rb
44
47
  - lib/generators/test_unit/templates/decorator_test.rb
48
+ - spec/controllers/fake_detection_spec.rb
45
49
  - spec/fake_app/authors/index.html.erb
46
50
  - spec/fake_app/authors/show.html.erb
51
+ - spec/fake_app/authors/show.json.jbuilder
47
52
  - spec/fake_app/books/_book.html.erb
53
+ - spec/fake_app/books/_book.json.jbuilder
48
54
  - spec/fake_app/books/_book_locals.html.erb
55
+ - spec/fake_app/books/index.html.erb
49
56
  - spec/fake_app/books/show.html.erb
50
57
  - spec/fake_app/fake_app.rb
58
+ - spec/fake_app/movies/show.html.erb
51
59
  - spec/features/action_view_helpers_spec.rb
52
60
  - spec/features/controller_ivar_spec.rb
61
+ - spec/features/jbuilder_spec.rb
53
62
  - spec/features/partial_spec.rb
54
63
  - spec/spec_helper.rb
55
64
  homepage: https://github.com/amatsuda/active_decorator
56
65
  licenses: []
66
+ metadata: {}
57
67
  post_install_message:
58
68
  rdoc_options: []
59
69
  require_paths:
60
70
  - lib
61
71
  required_ruby_version: !ruby/object:Gem::Requirement
62
- none: false
63
72
  requirements:
64
- - - ! '>='
73
+ - - ">="
65
74
  - !ruby/object:Gem::Version
66
75
  version: '0'
67
76
  required_rubygems_version: !ruby/object:Gem::Requirement
68
- none: false
69
77
  requirements:
70
- - - ! '>='
78
+ - - ">="
71
79
  - !ruby/object:Gem::Version
72
80
  version: '0'
73
81
  requirements: []
74
82
  rubyforge_project: active_decorator
75
- rubygems_version: 1.8.23
83
+ rubygems_version: 2.4.5
76
84
  signing_key:
77
- specification_version: 3
85
+ specification_version: 4
78
86
  summary: A simple and Rubyish view helper for Rails 3
79
87
  test_files:
88
+ - spec/controllers/fake_detection_spec.rb
80
89
  - spec/fake_app/authors/index.html.erb
81
90
  - spec/fake_app/authors/show.html.erb
91
+ - spec/fake_app/authors/show.json.jbuilder
82
92
  - spec/fake_app/books/_book.html.erb
93
+ - spec/fake_app/books/_book.json.jbuilder
83
94
  - spec/fake_app/books/_book_locals.html.erb
95
+ - spec/fake_app/books/index.html.erb
84
96
  - spec/fake_app/books/show.html.erb
85
97
  - spec/fake_app/fake_app.rb
98
+ - spec/fake_app/movies/show.html.erb
86
99
  - spec/features/action_view_helpers_spec.rb
87
100
  - spec/features/controller_ivar_spec.rb
101
+ - spec/features/jbuilder_spec.rb
88
102
  - spec/features/partial_spec.rb
89
103
  - spec/spec_helper.rb