active_decorator 0.1.0
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.
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +66 -0
- data/Rakefile +12 -0
- data/active_decorator.gemspec +27 -0
- data/lib/active_decorator.rb +4 -0
- data/lib/active_decorator/decorator.rb +50 -0
- data/lib/active_decorator/helpers.rb +21 -0
- data/lib/active_decorator/railtie.rb +17 -0
- data/lib/active_decorator/version.rb +3 -0
- data/lib/generators/rails/decorator_generator.rb +26 -0
- data/lib/generators/rails/templates/decorator.rb +3 -0
- data/lib/generators/rspec/decorator_generator.rb +11 -0
- data/lib/generators/rspec/templates/decorator_spec.rb +8 -0
- data/lib/generators/test_unit/decorator_generator.rb +11 -0
- data/lib/generators/test_unit/templates/decorator_test.rb +12 -0
- data/lib/monkey/abstract_controller/rendering.rb +13 -0
- data/lib/monkey/action_view/partial_renderer.rb +19 -0
- data/spec/fake_app/authors/index.html.erb +16 -0
- data/spec/fake_app/authors/show.html.erb +2 -0
- data/spec/fake_app/books/_book.html.erb +2 -0
- data/spec/fake_app/books/_book_locals.html.erb +2 -0
- data/spec/fake_app/books/show.html.erb +1 -0
- data/spec/fake_app/fake_app.rb +88 -0
- data/spec/requests/action_view_helpers_spec.rb +15 -0
- data/spec/requests/controller_ivar_spec.rb +29 -0
- data/spec/requests/partial_spec.rb +31 -0
- data/spec/spec_helper.rb +21 -0
- metadata +130 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Akira Matsuda
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# ActiveDecorator
|
2
|
+
|
3
|
+
A simple and Rubyish view helper for ActiveRecord models. Keep your helpers and views Object-Oriented!
|
4
|
+
|
5
|
+
|
6
|
+
## Features ##
|
7
|
+
|
8
|
+
1. automatically mixes decorator module into corresponding model only when:
|
9
|
+
1. passing a model or collection of models or an instance of ActiveRecord::Relation from controllers to views
|
10
|
+
2. rendering partials with models (using `:collection` or `:object` or `:locals` explicitly or implicitly)
|
11
|
+
2. the decorator module runs in the model's context. So, you can directly call any attributes or methods in the decorator module
|
12
|
+
3. since decorators are considered as sort of helpers, you can also call any ActionView's helper methods such as `content_tag` or `link_to`
|
13
|
+
|
14
|
+
|
15
|
+
## Supported versions ##
|
16
|
+
|
17
|
+
Rails 3.0.x, 3.1.x, and 3.2 (edge)
|
18
|
+
|
19
|
+
|
20
|
+
## Usage ##
|
21
|
+
|
22
|
+
1. bundle 'active_decorator' gem
|
23
|
+
2. create a decorator module for each AR model. For example, a decorator for a model `User` should be named `UserDecorator`.
|
24
|
+
You can use the generator for doing this ( `% rails g decorator user` )
|
25
|
+
3. Then it's all done. Without altering any single line of the existing code, the decorator modules will be automatically mixed into your models only in the view context.
|
26
|
+
|
27
|
+
|
28
|
+
## Examples ##
|
29
|
+
|
30
|
+
# app/models/user.rb
|
31
|
+
class User < ActiveRecord::Base
|
32
|
+
# first_name:string last_name:string website:string
|
33
|
+
end
|
34
|
+
|
35
|
+
# app/decorators/user_decorator.rb
|
36
|
+
module UserDecorator
|
37
|
+
def full_name
|
38
|
+
"#{first_name} #{last_name}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def link
|
42
|
+
link_to full_name, website
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# app/controllers/users_controller.rb
|
47
|
+
class UsersController < ApplicationController
|
48
|
+
def index
|
49
|
+
User.all
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# app/views/users/index.html.erb
|
54
|
+
<% @users.each do |user| %>
|
55
|
+
<%= user.link %><br>
|
56
|
+
<% end %>
|
57
|
+
|
58
|
+
|
59
|
+
## Contributing to ActiveDecorator ##
|
60
|
+
|
61
|
+
* Fork, fix, then send me a pull request.
|
62
|
+
|
63
|
+
|
64
|
+
## Copyright ##
|
65
|
+
|
66
|
+
Copyright (c) 2011 Akira Matsuda. See MIT-LICENSE for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require 'rspec/core'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
9
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :spec
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "active_decorator/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "active_decorator"
|
7
|
+
s.version = ActiveDecorator::VERSION
|
8
|
+
s.authors = ["Akira Matsuda"]
|
9
|
+
s.email = ["ronnie@dio.jp"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{A simple and Rubyish view helper for ActiveRecord models}
|
12
|
+
s.description = %q{A simple and Rubyish view helper for ActiveRecord models}
|
13
|
+
|
14
|
+
s.rubyforge_project = "active_decorator"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency 'rails'
|
23
|
+
s.add_development_dependency 'rspec-rails'
|
24
|
+
s.add_development_dependency 'capybara'
|
25
|
+
s.add_development_dependency 'sqlite3'
|
26
|
+
# s.add_runtime_dependency "rest-client"
|
27
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'active_decorator/helpers'
|
3
|
+
|
4
|
+
module ActiveDecorator
|
5
|
+
class Decorator
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@@decorators = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def decorate_if_model(obj)
|
13
|
+
case obj
|
14
|
+
when ActiveRecord::Base
|
15
|
+
decorate obj
|
16
|
+
when ActiveRecord::Relation
|
17
|
+
class << obj
|
18
|
+
def to_a_with_decorator
|
19
|
+
arr = to_a_without_decorator
|
20
|
+
arr.each do |model|
|
21
|
+
ActiveDecorator::Decorator.instance.decorate model
|
22
|
+
end
|
23
|
+
end
|
24
|
+
alias_method_chain :to_a, :decorator
|
25
|
+
end
|
26
|
+
when Array
|
27
|
+
obj.each do |r|
|
28
|
+
decorate_if_model r
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def decorate(model)
|
34
|
+
d = decorator_for model.class
|
35
|
+
return model unless d
|
36
|
+
model.extend d unless model.is_a? d
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def decorator_for(model_class)
|
41
|
+
return @@decorators[model_class] if @@decorators.has_key? model_class
|
42
|
+
|
43
|
+
decorator_name = "#{model_class.name}Decorator"
|
44
|
+
d = decorator_name.constantize
|
45
|
+
d.send :include, ActiveDecorator::Helpers
|
46
|
+
@@decorators[model_class] = d
|
47
|
+
rescue NameError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
|
3
|
+
module ActiveDecorator
|
4
|
+
module Helpers
|
5
|
+
def method_missing(method, *args, &block)
|
6
|
+
super
|
7
|
+
#TODO need to make sure who raised the error?
|
8
|
+
rescue NoMethodError => no_method_error
|
9
|
+
begin
|
10
|
+
@@_decorator_view_proxy ||= DecoratorViewProxy.new
|
11
|
+
@@_decorator_view_proxy.send method, *args, block
|
12
|
+
rescue NoMethodError
|
13
|
+
raise no_method_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class DecoratorViewProxy
|
18
|
+
include ::ActionView::Helpers
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module ActiveDecorator
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
initializer 'active_decorator' do
|
6
|
+
ActiveSupport.on_load(:action_view) do
|
7
|
+
require 'monkey/action_view/partial_renderer'
|
8
|
+
end
|
9
|
+
ActiveSupport.on_load(:action_controller) do
|
10
|
+
require 'monkey/abstract_controller/rendering'
|
11
|
+
end
|
12
|
+
ActiveSupport.on_load(:action_mailer) do
|
13
|
+
require 'monkey/abstract_controller/rendering'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
class DecoratorGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
desc <<DESC
|
7
|
+
Description:
|
8
|
+
Stubs out a decorator module in app/decorators directory.
|
9
|
+
|
10
|
+
Examples:
|
11
|
+
`rails g decorator book`
|
12
|
+
|
13
|
+
This creates:
|
14
|
+
app/decorators/book_decorator.rb
|
15
|
+
DESC
|
16
|
+
|
17
|
+
def create_decorator_file
|
18
|
+
empty_directory 'app/decorators'
|
19
|
+
|
20
|
+
template 'decorator.rb', File.join('app/decorators', "#{singular_name}_decorator.rb")
|
21
|
+
end
|
22
|
+
|
23
|
+
hook_for :test_framework
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Rspec
|
2
|
+
class DecoratorGenerator < ::Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
def create_spec_file
|
6
|
+
empty_directory 'spec/decorators'
|
7
|
+
|
8
|
+
template 'decorator_spec.rb', File.join('spec/decorators', "#{singular_name}_decorator_spec.rb")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe <%= singular_name.camelize %>Decorator do
|
5
|
+
let(:<%= singular_name %>) { <%= class_name %>.new.extend <%= singular_name.camelize %>Decorator }
|
6
|
+
subject { <%= singular_name %> }
|
7
|
+
it { should be_a <%= class_name %> }
|
8
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module TestUnit
|
2
|
+
class DecoratorGenerator < ::Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
def create_test_file
|
6
|
+
empty_directory 'test/decorators'
|
7
|
+
|
8
|
+
template 'decorator_test.rb', File.join('test/decorators', "#{singular_name}_decorator_test.rb")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class <%= singular_name.camelize %>DecoratorTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
@<%= singular_name %> = <%= class_name %>.new.extend <%= singular_name.camelize %>Decorator
|
7
|
+
end
|
8
|
+
|
9
|
+
# test "the truth" do
|
10
|
+
# assert true
|
11
|
+
# end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module AbstractController
|
2
|
+
module Rendering
|
3
|
+
def view_assigns_with_decorator
|
4
|
+
hash = view_assigns_without_decorator
|
5
|
+
hash.values.each do |v|
|
6
|
+
ActiveDecorator::Decorator.instance.decorate_if_model v
|
7
|
+
end
|
8
|
+
hash
|
9
|
+
end
|
10
|
+
|
11
|
+
alias_method_chain :view_assigns, :decorator
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ActionView
|
2
|
+
class PartialRenderer < AbstractRenderer #:nodoc:
|
3
|
+
def setup_with_decorator(context, options, block)
|
4
|
+
setup_without_decorator context, options, block
|
5
|
+
|
6
|
+
@locals.values.each do |v|
|
7
|
+
ActiveDecorator::Decorator.instance.decorate_if_model v
|
8
|
+
end if @locals.present?
|
9
|
+
ActiveDecorator::Decorator.instance.decorate_if_model @object
|
10
|
+
@collection.each do |v|
|
11
|
+
ActiveDecorator::Decorator.instance.decorate_if_model v
|
12
|
+
end if @collection.present?
|
13
|
+
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
alias_method_chain :setup, :decorator
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% @authors.each do |author| %>
|
2
|
+
<%= author.name %>
|
3
|
+
<%= author.reverse_name %>
|
4
|
+
|
5
|
+
<% if params[:partial] == 'collection' %>
|
6
|
+
<%= render author.books %>
|
7
|
+
<% elsif params[:partial] == 'locals' %>
|
8
|
+
<% author.books.each do |book| %>
|
9
|
+
<%= render :partial => 'books/book_locals', :locals => {:b => book} %>
|
10
|
+
<% end %>
|
11
|
+
<% else %>
|
12
|
+
<% author.books.each do |book| %>
|
13
|
+
<%= render book %>
|
14
|
+
<% end %>
|
15
|
+
<% end %>
|
16
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @book.link %>
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'action_controller/railtie'
|
3
|
+
require 'action_view/railtie'
|
4
|
+
|
5
|
+
# config
|
6
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
7
|
+
|
8
|
+
module ActiveDecoratorTestApp
|
9
|
+
class Application < Rails::Application
|
10
|
+
config.secret_token = '"confusion" will be my epitaph.'
|
11
|
+
config.session_store :cookie_store, :key => '_myapp_session'
|
12
|
+
config.active_support.deprecation = :log
|
13
|
+
end
|
14
|
+
end
|
15
|
+
ActiveDecoratorTestApp::Application.initialize!
|
16
|
+
|
17
|
+
# routes
|
18
|
+
ActiveDecoratorTestApp::Application.routes.draw do
|
19
|
+
resources :authors, :only => [:index, :show] do
|
20
|
+
resources :books, :only => :show
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# models
|
25
|
+
class Author < ActiveRecord::Base
|
26
|
+
has_many :books
|
27
|
+
end
|
28
|
+
class Book < ActiveRecord::Base
|
29
|
+
belongs_to :author
|
30
|
+
end
|
31
|
+
|
32
|
+
# helpers
|
33
|
+
module ApplicationHelper; end
|
34
|
+
|
35
|
+
# decorators
|
36
|
+
module AuthorDecorator
|
37
|
+
def reverse_name
|
38
|
+
name.reverse
|
39
|
+
end
|
40
|
+
|
41
|
+
def capitalized_name
|
42
|
+
name.capitalize
|
43
|
+
end
|
44
|
+
end
|
45
|
+
module BookDecorator
|
46
|
+
def reverse_title
|
47
|
+
title.reverse
|
48
|
+
end
|
49
|
+
|
50
|
+
def upcased_title
|
51
|
+
title.upcase
|
52
|
+
end
|
53
|
+
|
54
|
+
def link
|
55
|
+
link_to title, 'http://example.com'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# controllers
|
60
|
+
class ApplicationController < ActionController::Base
|
61
|
+
self.append_view_path File.dirname(__FILE__)
|
62
|
+
end
|
63
|
+
class AuthorsController < ApplicationController
|
64
|
+
def index
|
65
|
+
if params[:variable_type] == 'array'
|
66
|
+
@authors = Author.all
|
67
|
+
else
|
68
|
+
@authors = Author.scoped
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def show
|
73
|
+
@author = Author.find params[:id]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
class BooksController < ApplicationController
|
77
|
+
def show
|
78
|
+
@book = Author.find(params[:author_id]).books.find(params[:id])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# migrations
|
83
|
+
class CreateAllTables < ActiveRecord::Migration
|
84
|
+
def self.up
|
85
|
+
create_table(:authors) {|t| t.string :name}
|
86
|
+
create_table(:books) {|t| t.string :title; t.references :author}
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'fallback to helpers' do
|
4
|
+
background do
|
5
|
+
aamine = Author.create! :name => 'aamine'
|
6
|
+
@rhg = aamine.books.create! :title => 'RHG'
|
7
|
+
end
|
8
|
+
|
9
|
+
scenario 'invoking action_view helper methods' do
|
10
|
+
visit "/authors/#{@rhg.author.id}/books/#{@rhg.id}"
|
11
|
+
within 'a' do
|
12
|
+
page.should have_content 'RHG'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'decorating controller ivar' do
|
4
|
+
background do
|
5
|
+
@matz = Author.create! :name => 'matz'
|
6
|
+
Author.create! :name => 'takahashim'
|
7
|
+
end
|
8
|
+
after do
|
9
|
+
Author.delete_all
|
10
|
+
end
|
11
|
+
|
12
|
+
scenario 'decorating a model object in ivar' do
|
13
|
+
visit "/authors/#{@matz.id}"
|
14
|
+
page.should have_content 'matz'
|
15
|
+
page.should have_content 'matz'.capitalize
|
16
|
+
end
|
17
|
+
|
18
|
+
scenario 'decorating model scope in ivar' do
|
19
|
+
visit '/authors'
|
20
|
+
page.should have_content 'takahashim'
|
21
|
+
page.should have_content 'takahashim'.reverse
|
22
|
+
end
|
23
|
+
|
24
|
+
scenario "decorating models' array in ivar" do
|
25
|
+
visit '/authors?variable_type=array'
|
26
|
+
page.should have_content 'takahashim'
|
27
|
+
page.should have_content 'takahashim'.reverse
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'decorating partial object' 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 implicit @object' do
|
15
|
+
visit '/authors'
|
16
|
+
page.should have_content 'the gc book'
|
17
|
+
page.should have_content 'the gc book'.reverse
|
18
|
+
end
|
19
|
+
|
20
|
+
scenario 'decorating implicit @collection' do
|
21
|
+
visit '/authors?partial=collection'
|
22
|
+
page.should have_content 'the gc book'
|
23
|
+
page.should have_content 'the gc book'.reverse
|
24
|
+
end
|
25
|
+
|
26
|
+
scenario 'decorating objects in @locals' do
|
27
|
+
visit '/authors?partial=locals'
|
28
|
+
page.should have_content 'the gc book'
|
29
|
+
page.should have_content 'the gc book'.upcase
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
# load Rails first
|
4
|
+
require 'rails'
|
5
|
+
require 'active_decorator'
|
6
|
+
# needs to load the app before loading rspec/rails => capybara
|
7
|
+
require 'fake_app/fake_app'
|
8
|
+
require 'rspec/rails'
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.before :all do
|
15
|
+
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'authors'
|
16
|
+
end
|
17
|
+
config.before :each do
|
18
|
+
Book.delete_all
|
19
|
+
Author.delete_all
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_decorator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Akira Matsuda
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &70282934150240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70282934150240
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec-rails
|
27
|
+
requirement: &70282934149800 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70282934149800
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: capybara
|
38
|
+
requirement: &70282934149380 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70282934149380
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sqlite3
|
49
|
+
requirement: &70282934148940 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70282934148940
|
58
|
+
description: A simple and Rubyish view helper for ActiveRecord models
|
59
|
+
email:
|
60
|
+
- ronnie@dio.jp
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- .travis.yml
|
68
|
+
- Gemfile
|
69
|
+
- MIT-LICENSE
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- active_decorator.gemspec
|
73
|
+
- lib/active_decorator.rb
|
74
|
+
- lib/active_decorator/decorator.rb
|
75
|
+
- lib/active_decorator/helpers.rb
|
76
|
+
- lib/active_decorator/railtie.rb
|
77
|
+
- lib/active_decorator/version.rb
|
78
|
+
- lib/generators/rails/decorator_generator.rb
|
79
|
+
- lib/generators/rails/templates/decorator.rb
|
80
|
+
- lib/generators/rspec/decorator_generator.rb
|
81
|
+
- lib/generators/rspec/templates/decorator_spec.rb
|
82
|
+
- lib/generators/test_unit/decorator_generator.rb
|
83
|
+
- lib/generators/test_unit/templates/decorator_test.rb
|
84
|
+
- lib/monkey/abstract_controller/rendering.rb
|
85
|
+
- lib/monkey/action_view/partial_renderer.rb
|
86
|
+
- spec/fake_app/authors/index.html.erb
|
87
|
+
- spec/fake_app/authors/show.html.erb
|
88
|
+
- spec/fake_app/books/_book.html.erb
|
89
|
+
- spec/fake_app/books/_book_locals.html.erb
|
90
|
+
- spec/fake_app/books/show.html.erb
|
91
|
+
- spec/fake_app/fake_app.rb
|
92
|
+
- spec/requests/action_view_helpers_spec.rb
|
93
|
+
- spec/requests/controller_ivar_spec.rb
|
94
|
+
- spec/requests/partial_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
homepage: ''
|
97
|
+
licenses: []
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project: active_decorator
|
116
|
+
rubygems_version: 1.8.10
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: A simple and Rubyish view helper for ActiveRecord models
|
120
|
+
test_files:
|
121
|
+
- spec/fake_app/authors/index.html.erb
|
122
|
+
- spec/fake_app/authors/show.html.erb
|
123
|
+
- spec/fake_app/books/_book.html.erb
|
124
|
+
- spec/fake_app/books/_book_locals.html.erb
|
125
|
+
- spec/fake_app/books/show.html.erb
|
126
|
+
- spec/fake_app/fake_app.rb
|
127
|
+
- spec/requests/action_view_helpers_spec.rb
|
128
|
+
- spec/requests/controller_ivar_spec.rb
|
129
|
+
- spec/requests/partial_spec.rb
|
130
|
+
- spec/spec_helper.rb
|