source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper.rb | Ruby | mit | 5,266 | master | 1,757 | require 'action_view'
require 'active_model/naming'
require 'active_model/serialization'
require 'active_model/serializers/json'
require 'active_model/serializers/xml'
require 'active_support/inflector'
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_supp... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/generators/controller_override.rb | Ruby | mit | 5,266 | master | 488 | require "rails/generators"
require "rails/generators/rails/controller/controller_generator"
require "rails/generators/rails/scaffold_controller/scaffold_controller_generator"
module Rails
module Generators
class ControllerGenerator
hook_for :decorator, type: :boolean, default: true do |generator|
i... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/generators/draper/install_generator.rb | Ruby | mit | 5,266 | master | 366 | module Draper
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("templates", __dir__)
desc 'Creates an ApplicationDecorator, if none exists.'
def create_application_decorator
file = 'application_decorator.rb'
copy_file file, "app/de... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/generators/draper/templates/application_decorator.rb | Ruby | mit | 5,266 | master | 262 | class ApplicationDecorator < Draper::Decorator
# Define methods for all decorated objects.
# Helpers are accessed through `helpers` (aka `h`). For example:
#
# def percent_amount
# h.number_to_percentage object.amount, precision: 2
# end
end |
github | drapergem/draper | https://github.com/drapergem/draper | lib/generators/test_unit/decorator_generator.rb | Ruby | mit | 5,266 | master | 380 | module TestUnit
module Generators
class DecoratorGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path("templates", __dir__)
check_class_collision suffix: "DecoratorTest"
def create_test_file
template 'decorator_test.rb', File.join('test/decorators', class_path, "#{sin... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/generators/rails/decorator_generator.rb | Ruby | mit | 5,266 | master | 738 | module Rails
module Generators
class DecoratorGenerator < NamedBase
source_root File.expand_path("templates", __dir__)
check_class_collision suffix: "Decorator"
class_option :parent, type: :string, desc: "The parent class for the generated decorator"
def create_decorator_file
tem... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/generators/rails/templates/decorator.rb | Ruby | mit | 5,266 | master | 509 | <%- module_namespacing do -%>
<%- if parent_class_name.present? -%>
class <%= class_name %>Decorator < <%= parent_class_name %>
<%- else -%>
class <%= class_name %>
<%- end -%>
delegate_all
# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override att... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/generators/rspec/decorator_generator.rb | Ruby | mit | 5,266 | master | 325 | module Rspec
module Generators
class DecoratorGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path("templates", __dir__)
def create_spec_file
template 'decorator_spec.rb', File.join('spec/decorators', class_path, "#{singular_name}_decorator_spec.rb")
end
end
end... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/generators/mini_test/decorator_generator.rb | Ruby | mit | 5,266 | master | 573 | require 'generators/mini_test'
module MiniTest
module Generators
class DecoratorGenerator < Base
def self.source_root
File.expand_path("templates", __dir__)
end
class_option :spec, type: :boolean, default: false, desc: "Use MiniTest::Spec DSL"
check_class_collision suffix: "Deco... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/lazy_helpers.rb | Ruby | mit | 5,266 | master | 421 | module Draper
# Include this module in your decorators to get direct access to the helpers
# so that you can stop typing `h.` everywhere, at the cost of mixing in a
# bazillion methods.
module LazyHelpers
# Sends missing methods to the {HelperProxy}.
ruby2_keywords def method_missing(method, *args, &blo... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/railtie.rb | Ruby | mit | 5,266 | master | 1,866 | require 'rails/railtie'
module ActiveModel
class Railtie < Rails::Railtie
generators do |app|
Rails::Generators.configure! app.config.generators
require_relative '../generators/controller_override'
end
end
end
module Draper
class Railtie < Rails::Railtie
config.after_initialize do |app|
... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/decorates_assigned.rb | Ruby | mit | 5,266 | master | 1,591 | module Draper
module DecoratesAssigned
# @overload decorates_assigned(*variables, options = {})
# Defines a helper method to access decorated instance variables.
#
# @example
# # app/controllers/articles_controller.rb
# class ArticlesController < ApplicationController
# d... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/factory.rb | Ruby | mit | 5,266 | master | 2,866 | module Draper
class Factory
# Creates a decorator factory.
#
# @option options [Decorator, CollectionDecorator] :with (nil)
# decorator class to use. If nil, it is inferred from the object
# passed to {#decorate}.
# @option options [Hash, #call] context
# extra data to be stored in c... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/view_helpers.rb | Ruby | mit | 5,266 | master | 969 | module Draper
# Provides the {#helpers} method used in {Decorator} and {CollectionDecorator}
# to call the Rails helpers.
module ViewHelpers
extend ActiveSupport::Concern
module ClassMethods
# Access the helpers proxy to call built-in and user-defined
# Rails helpers from a class context.
... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/view_context.rb | Ruby | mit | 5,266 | master | 2,788 | require 'draper/view_context/build_strategy'
require 'request_store'
module Draper
module ViewContext
# Hooks into a controller or mailer to save the view context in {current}.
def view_context
super.tap do |context|
Draper::ViewContext.current = context
end
end
# Set the current... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/undecorate.rb | Ruby | mit | 5,266 | master | 335 | module Draper
def self.undecorate(object)
if object.respond_to?(:decorated?) && object.decorated?
object.object
else
object
end
end
def self.undecorate_chain(object)
if object.respond_to?(:decorated?) && object.decorated?
undecorate_chain(object.object)
else
object
... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/decorator.rb | Ruby | mit | 5,266 | master | 8,839 | require 'draper/compatibility/global_id'
module Draper
class Decorator
include Draper::ViewHelpers
include Draper::Compatibility::GlobalID if defined?(GlobalID)
extend Draper::Delegation
include ActiveModel::Serialization
include ActiveModel::Serializers::JSON
include ActiveModel::Serializer... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/decoratable.rb | Ruby | mit | 5,266 | master | 2,868 | require 'draper/decoratable/equality'
require 'draper/compatibility/broadcastable'
module Draper
# Provides shortcuts to decorate objects directly, so you can do
# `@product.decorate` instead of `ProductDecorator.new(@product)`.
#
# This module is included by default into `ActiveRecord::Base` and
# `Mongoid:... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/finders.rb | Ruby | mit | 5,266 | master | 990 | module Draper
# Provides automatically-decorated finder methods for your decorators. You
# do not have to extend this module directly; it is extended by
# {Decorator.decorates_finders}.
module Finders
def find(id, options = {})
decorate(object_class.find(id), options)
end
def all(options = {}... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/helper_proxy.rb | Ruby | mit | 5,266 | master | 959 | module Draper
# Provides access to helper methods - both Rails built-in helpers, and those
# defined in your application.
class HelperProxy
# @overload initialize(view_context)
def initialize(view_context)
@view_context = view_context
end
# Sends helper methods to the view context.
ruby... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/automatic_delegation.rb | Ruby | mit | 5,266 | master | 2,322 | module Draper
module AutomaticDelegation
extend ActiveSupport::Concern
# Delegates missing instance methods to the source object. Note: This will delegate `super`
# method calls to `object` as well. Calling `super` will first try to call the method on
# the parent decorator class. If no method exists... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/configuration.rb | Ruby | mit | 5,266 | master | 483 | module Draper
module Configuration
def configure
yield self
end
def default_controller
@@default_controller ||= ApplicationController
end
def default_controller=(controller)
@@default_controller = controller
end
def default_query_methods_strategy
@@default_query_... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/decorated_association.rb | Ruby | mit | 5,266 | master | 804 | module Draper
# @private
class DecoratedAssociation
def initialize(owner, association, options)
options.assert_valid_keys(:with, :scope, :context)
@owner = owner
@association = association
@scope = options[:scope]
decorator_class = options[:with]
context = options.fetch(:c... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/delegation.rb | Ruby | mit | 5,266 | master | 416 | module Draper
module Delegation
# @overload delegate(*methods, options = {})
# Overrides {http://api.rubyonrails.org/classes/Module.html#method-i-delegate Module.delegate}
# to make `:object` the default delegation target.
#
# @return [void]
def delegate(*methods)
options = methods... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/query_methods.rb | Ruby | mit | 5,266 | master | 741 | require_relative 'query_methods/load_strategy'
module Draper
module QueryMethods
# Proxies missing query methods to the source class if the strategy allows.
ruby2_keywords def method_missing(method, *args, &block)
return super unless strategy.allowed? method
object.send(method, *args, &block).de... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/test_case.rb | Ruby | mit | 5,266 | master | 920 | module Draper
require 'active_support/test_case'
class TestCase < ::ActiveSupport::TestCase
module ViewContextTeardown
def before_setup
Draper::ViewContext.clear!
super
end
end
module Behavior
if defined?(::Devise)
require 'draper/test/devise_helper'
i... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/collection_decorator.rb | Ruby | mit | 5,266 | master | 2,426 | module Draper
class CollectionDecorator
include Enumerable
include Draper::ViewHelpers
include Draper::QueryMethods
extend Draper::Delegation
# @return the collection being decorated.
attr_reader :object
# @return [Class] the decorator class used to decorate each item, as set by
# ... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/tasks/test.rake | Ruby | mit | 5,266 | master | 212 | require 'rake/testtask'
require 'rails/test_unit/railtie'
namespace :test do
Rake::TestTask.new(decorators: "test:prepare") do |t|
t.libs << "test"
t.pattern = "test/decorators/**/*_test.rb"
end
end |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/decoratable/collection_proxy.rb | Ruby | mit | 5,266 | master | 437 | module Draper
module Decoratable
module CollectionProxy
# Decorates a collection of objects. Used at the end of a scope chain.
#
# @example
# company.products.popular.decorate
# @param [Hash] options
# see {Decorator.decorate_collection}.
def decorate(options = {})
... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/decoratable/equality.rb | Ruby | mit | 5,266 | master | 715 | module Draper
module Decoratable
module Equality
# Compares self with a possibly-decorated object.
#
# @return [Boolean]
def ==(other)
super || Equality.test_for_decorator(self, other)
end
# Compares an object to a possibly-decorated object.
#
# @return [Bo... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/compatibility/broadcastable.rb | Ruby | mit | 5,266 | master | 749 | # frozen_string_literal: true
module Draper
module Compatibility
# It would look consistent to use decorated objects inside templates broadcasted with
# Turbo::Broadcastable.
#
# This compatibility patch fixes the issue by overriding the original defaults to decorate the
# object, that's passed t... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/compatibility/api_only.rb | Ruby | mit | 5,266 | master | 1,119 | module Draper
module Compatibility
# Draper expects your `ApplicationController` to include `ActionView::Rendering`. The
# `ApplicationController` generated by Rails 5 API-only applications (created with
# `rails new --api`) don't by default. However, including `ActionView::Rendering` in
# `Applicaton... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/compatibility/global_id.rb | Ruby | mit | 5,266 | master | 1,075 | module Draper
module Compatibility
# [Active Job](http://edgeguides.rubyonrails.org/active_job_basics.html) allows you to pass
# ActiveRecord objects to background tasks directly and performs the necessary serialization
# and deserialization. In order to do this, arguments to a background job must impleme... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/query_methods/load_strategy.rb | Ruby | mit | 5,266 | master | 406 | module Draper
module QueryMethods
module LoadStrategy
def self.new(name)
const_get(name.to_s.camelize).new
end
class ActiveRecord
def allowed?(method)
::ActiveRecord::Relation::VALUE_METHODS.include? method
end
end
class Mongoid
def allowed... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/view_context/build_strategy.rb | Ruby | mit | 5,266 | master | 1,070 | module Draper
module ViewContext
# @private
module BuildStrategy
def self.new(name, &block)
const_get(name.to_s.camelize).new(&block)
end
class Fast
def initialize(&block)
@view_context_class = Class.new(ActionView::Base, &block)
end
def call
... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/test/devise_helper.rb | Ruby | mit | 5,266 | master | 599 | module Draper
module DeviseHelper
def sign_in(resource_or_scope, resource = nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
_stub_current_scope scope, resource || resource_or_scope
end
def sign_out(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/test/rspec_integration.rb | Ruby | mit | 5,266 | master | 436 | module Draper
module DecoratorExampleGroup
include Draper::TestCase::Behavior
extend ActiveSupport::Concern
included { metadata[:type] = :decorator }
end
RSpec.configure do |config|
config.include DecoratorExampleGroup, file_path: %r{spec/decorators}, type: :decorator
[:decorator, :controll... |
github | drapergem/draper | https://github.com/drapergem/draper | lib/draper/test/minitest_integration.rb | Ruby | mit | 5,266 | master | 210 | class Draper::TestCase
register_spec_type(self) do |desc|
desc < Draper::Decorator || desc < Draper::CollectionDecorator if desc.is_a?(Class)
end
register_spec_type(/Decorator( ?Test)?\z/i, self)
end |
github | drapergem/draper | https://github.com/drapergem/draper | spec/spec_helper.rb | Ruby | mit | 5,266 | master | 1,348 | require 'simplecov'
SimpleCov.start do
add_filter 'spec'
add_group 'Draper', 'lib/draper'
add_group 'Generators', 'lib/generators'
end
require 'bundler/setup'
require 'draper'
require 'action_controller'
require 'action_controller/test_case'
RSpec.configure do |config|
config.expect_with(:rspec) {|c| c.syntax... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/integration/integration_spec.rb | Ruby | mit | 5,266 | master | 2,206 | require 'spec_helper'
require 'support/dummy_app'
require 'support/matchers/have_text'
SimpleCov.command_name 'test:integration'
app = DummyApp.new(ENV["RAILS_ENV"])
spec_types = {
view: ["/posts/1", "PostsController"],
mailer: ["/posts/1/mail", "PostMailer"]
}
app.start_server do
spec_types.each do |type, (pat... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/finders_spec.rb | Ruby | mit | 5,266 | master | 5,477 | require 'spec_helper'
module Draper
describe Finders do
protect_class ProductDecorator
before { ProductDecorator.decorates_finders }
describe ".find" do
it "proxies to the model class" do
expect(Product).to receive(:find).with(1)
ProductDecorator.find(1)
end
it "decora... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/decoratable_spec.rb | Ruby | mit | 5,266 | master | 7,414 | require 'spec_helper'
require 'support/shared_examples/decoratable_equality'
module Draper
describe Decoratable do
describe "#decorate" do
it "returns a decorator for self" do
product = Product.new
decorator = product.decorate
expect(decorator).to be_a ProductDecorator
expe... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/undecorate_chain_spec.rb | Ruby | mit | 5,266 | master | 630 | require 'spec_helper'
describe Draper, '.undecorate_chain' do
let!(:object) { Model.new }
let!(:decorated_inner) { Class.new(Draper::Decorator).new(object) }
let!(:decorated_outer) { Class.new(Draper::Decorator).new(decorated_inner) }
it 'undecorates full chain of decorated objects' do
expect(Draper.undec... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/factory_spec.rb | Ruby | mit | 5,266 | master | 8,556 | require 'spec_helper'
module Draper
describe Factory do
describe "#initialize" do
it "accepts valid options" do
valid_options = {with: Decorator, context: {foo: "bar"}}
expect{Factory.new(valid_options)}.not_to raise_error
end
it "rejects invalid options" do
expect{Fact... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/decorates_assigned_spec.rb | Ruby | mit | 5,266 | master | 2,023 | require 'spec_helper'
module Draper
describe DecoratesAssigned do
let(:controller_class) do
Class.new do
extend DecoratesAssigned
def self.helper_method(method)
helper_methods << method
end
def self.helper_methods
@helper_methods ||= []
end
... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/lazy_helpers_spec.rb | Ruby | mit | 5,266 | master | 558 | require 'spec_helper'
module Draper
describe LazyHelpers do
describe "#method_missing" do
let(:decorator) do
Struct.new(:helpers){include Draper::LazyHelpers}.new(double)
end
it "proxies methods to #helpers" do
allow(decorator.helpers).to receive(:foo) { |arg| arg }
exp... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/undecorate_spec.rb | Ruby | mit | 5,266 | master | 499 | require 'spec_helper'
describe Draper, '.undecorate' do
it 'undecorates a decorated object' do
object = Model.new
decorator = Draper::Decorator.new(object)
expect(Draper.undecorate(decorator)).to equal object
end
it 'passes a non-decorated object through' do
object = Model.new
expect(Draper.... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/decorated_association_spec.rb | Ruby | mit | 5,266 | master | 3,044 | require 'spec_helper'
module Draper
describe DecoratedAssociation do
describe "#initialize" do
it "accepts valid options" do
valid_options = {with: Decorator, scope: :foo, context: {}}
expect{DecoratedAssociation.new(Decorator.new(Model.new), :association, valid_options)}.not_to raise_error... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/helper_proxy_spec.rb | Ruby | mit | 5,266 | master | 1,821 | require 'spec_helper'
module Draper
describe HelperProxy do
describe "#initialize" do
it "sets the view context" do
view_context = double
helper_proxy = HelperProxy.new(view_context)
expect(helper_proxy.send(:view_context)).to be view_context
end
end
describe "#metho... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/query_methods_spec.rb | Ruby | mit | 5,266 | master | 2,914 | require 'spec_helper'
require_relative '../dummy/app/decorators/post_decorator'
Post = Struct.new(:id) { }
module Draper
describe QueryMethods do
let(:fake_strategy) { instance_double(QueryMethods::LoadStrategy::ActiveRecord) }
before { allow(QueryMethods::LoadStrategy).to receive(:new).and_return(fake_str... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/collection_decorator_spec.rb | Ruby | mit | 5,266 | master | 9,607 | require 'spec_helper'
require 'support/shared_examples/view_helpers'
module Draper
describe CollectionDecorator do
it_behaves_like "view helpers", CollectionDecorator.new([])
describe "#initialize" do
describe "options validation" do
it "does not raise error on valid options" do
vali... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/configuration_spec.rb | Ruby | mit | 5,266 | master | 1,332 | require 'spec_helper'
module Draper
RSpec.describe Configuration do
it 'yields Draper on configure' do
Draper.configure { |config| expect(config).to be Draper }
end
describe '#default_controller' do
it 'defaults default_controller to ApplicationController' do
expect(Draper.default_co... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/decorator_spec.rb | Ruby | mit | 5,266 | master | 29,237 | require 'spec_helper'
require 'support/shared_examples/view_helpers'
module Draper
describe Decorator do
it_behaves_like "view helpers", Decorator.new(Model.new)
describe "#initialize" do
describe "options validation" do
it "does not raise error on valid options" do
valid_options = {... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/draper_spec.rb | Ruby | mit | 5,266 | master | 721 | require 'spec_helper'
require 'support/shared_examples/view_helpers'
SimpleCov.command_name 'test:unit'
module Draper
describe Draper do
describe '.setup_action_controller' do
it 'includes api only compatability if base is ActionController::API' do
base = ActionController::API
Draper.setup... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/view_context_spec.rb | Ruby | mit | 5,266 | master | 6,321 | require 'spec_helper'
module Draper
describe ViewContext do
describe "#view_context" do
let(:base) { Class.new { def view_context; :controller_view_context; end } }
let(:controller) { Class.new(base) { include ViewContext } }
it "saves the superclass's view context" do
expect(ViewConte... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/query_methods/load_strategy_spec.rb | Ruby | mit | 5,266 | master | 721 | require 'spec_helper'
require 'active_record'
module Draper
module QueryMethods
describe LoadStrategy do
describe '#new' do
subject { described_class.new(:active_record) }
it { is_expected.to be_an_instance_of(LoadStrategy::ActiveRecord) }
end
end
describe LoadStrategy::Acti... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/view_context/build_strategy_spec.rb | Ruby | mit | 5,266 | master | 3,777 | require 'spec_helper'
def fake_view_context
double("ViewContext")
end
def fake_controller(view_context = fake_view_context)
double("Controller", view_context: view_context, request: double("Request"))
end
module Draper
describe ViewContext::BuildStrategy::Full do
describe "#call" do
context "when a c... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/draper/decoratable/equality_spec.rb | Ruby | mit | 5,266 | master | 255 | require 'spec_helper'
require 'support/shared_examples/decoratable_equality'
module Draper
describe Decoratable::Equality do
describe "#==" do
it_behaves_like "decoration-aware #==", Object.new.extend(Decoratable::Equality)
end
end
end |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/Rakefile | Ruby | mit | 5,266 | master | 270 | #!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Dummy::Application.load_tasks |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/lib/tasks/test.rake | Ruby | mit | 5,266 | master | 332 | require 'rake/testtask'
require 'rspec/core/rake_task'
Rake::Task[:test].clear
Rake::TestTask.new :test do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
end
RSpec::Core::RakeTask.new :spec
RSpec::Core::RakeTask.new :fast_spec do |t|
t.pattern = "fast_spec/**/*_spec.rb"
end
task default: [:test, :spec, ... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/db/schema.rb | Ruby | mit | 5,266 | master | 1,198 | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/config/routes.rb | Ruby | mit | 5,266 | master | 211 | Dummy::Application.routes.draw do
scope "(:locale)", locale: /en|zh/ do
resources :posts, only: [:show] do
get "mail", on: :member
end
end
devise_for :users, :admins if defined?(Devise)
end |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/config/application.rb | Ruby | mit | 5,266 | master | 1,458 | require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Kernel.silence_warnings do
Bundler.require(*Rails.groups)
end
module Dummy
class Application < Rails::Application
config.load_defaults Rails::VERSION::... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/config/environments/development.rb | Ruby | mit | 5,266 | master | 2,877 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded any time
# it changes. This slows down response time but is perfect for developme... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/config/environments/test.rb | Ruby | mit | 5,266 | master | 3,049 | require "active_support/core_ext/integer/time"
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data the... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/config/environments/production.rb | Ruby | mit | 5,266 | master | 4,565 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.enable_reloading = false
# Eager load code on boot. This eager loads most of Rails and
# your app... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/config/initializers/inflections.rb | Ruby | mit | 5,266 | master | 533 | # Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', ... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/config/initializers/secret_token.rb | Ruby | mit | 5,266 | master | 671 | # Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attac... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/spec_helper.rb | Ruby | mit | 5,266 | master | 4,595 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require ... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/rails_helper.rb | Ruby | mit | 5,266 | master | 2,977 | # This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
requ... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/jobs/publish_post_job_spec.rb | Ruby | mit | 5,266 | master | 312 | require 'rails_helper'
RSpec.describe PublishPostJob, type: :job do
let(:post) { Post.create.decorate }
subject(:job) { described_class.perform_later(post) }
it 'queues the job' do
expect { job }.to have_enqueued_job(described_class).with { |post|
expect(post).to be_decorated
}
end
end |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/models/post_spec.rb | Ruby | mit | 5,266 | master | 2,145 | require 'rails_helper'
require 'shared_examples/decoratable'
RSpec.describe Post do
let(:record) { described_class.create! }
it_behaves_like 'a decoratable model'
it { should be_a ApplicationRecord }
describe '#to_gid_param' do
let(:post) { Post.create }
subject { post.to_gid_param }
it { is_ex... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/shared_examples/decoratable.rb | Ruby | mit | 5,266 | master | 573 | shared_examples_for "a decoratable model" do
describe ".decorate" do
it "applies a collection decorator to a scope" do
described_class.create
decorated = described_class.limit(1).decorate
expect(decorated.size).to eq(1)
expect(decorated).to be_decorated
end
end
describe "#==" do
... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/decorators/active_model_serializers_spec.rb | Ruby | mit | 5,266 | master | 435 | require 'rails_helper'
describe Draper::CollectionDecorator do
describe "#active_model_serializer" do
it "returns ActiveModel::Serializer::CollectionSerializer" do
collection_decorator = Draper::CollectionDecorator.new([])
collection_serializer = ActiveModel::Serializer.serializer_for(collection_dec... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/decorators/helpers_spec.rb | Ruby | mit | 5,266 | master | 558 | require 'spec_helper'
describe "A decorator spec" do
it "can access helpers through `helper`" do
expect(helper.content_tag(:p, "Help!")).to eq "<p>Help!</p>"
end
it "can access helpers through `helpers`" do
expect(helpers.content_tag(:p, "Help!")).to eq "<p>Help!</p>"
end
it "can access helpers thr... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/decorators/devise_spec.rb | Ruby | mit | 5,266 | master | 1,085 | require 'spec_helper'
if defined?(Devise)
describe "A decorator spec" do
it "can sign in a real user" do
user = User.new
sign_in user
expect(helper.current_user).to be user
end
it "can sign in a mock user" do
user = double("User")
sign_in :user, user
expect(helper.c... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/decorators/post_decorator_spec.rb | Ruby | mit | 5,266 | master | 2,455 | require 'rails_helper'
describe PostDecorator do
let(:decorator) { PostDecorator.new(object) }
let(:object) { Post.create }
it "can use built-in helpers" do
expect(decorator.truncated).to eq "Once upon a..."
end
it "can use built-in private helpers" do
expect(decorator.html_escaped).to eq "<scri... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/decorators/view_context_spec.rb | Ruby | mit | 5,266 | master | 490 | require 'spec_helper'
def it_does_not_leak_view_context
2.times do
it "has an independent view context" do
expect(Draper::ViewContext.current).not_to be :leaked
Draper::ViewContext.current = :leaked
end
end
end
describe "A decorator spec", type: :decorator do
it_does_not_leak_view_context
en... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/spec/mailers/post_mailer_spec.rb | Ruby | mit | 5,266 | master | 782 | require 'rails_helper'
describe PostMailer do
describe "#decorated_email" do
let(:email_body) { Capybara.string(email.body.to_s) }
let(:email) { PostMailer.decorated_email(post).deliver }
let(:post) { Post.create }
it "decorates" do
expect(email_body).to have_content "Today"
end
it "c... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/app/mailers/post_mailer.rb | Ruby | mit | 5,266 | master | 387 | class PostMailer < ApplicationMailer
default from: "from@example.com"
layout "application"
# Mailers don't import app/helpers automatically
helper :application
def decorated_email(post)
@post = post.decorate
mail to: "to@example.com", subject: "A decorated post"
end
private
def goodnight_moo... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/app/decorators/post_decorator.rb | Ruby | mit | 5,266 | master | 1,061 | class PostDecorator < Draper::Decorator
# don't delegate_all here because it helps to identify things we
# have to delegate for ActiveModel compatibility
# need to delegate attribute methods for AM::Serialization
# need to delegate id and new_record? for AR::Base#== (Rails 3.0 only)
delegate :id, :created_at... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/app/decorators/comment_decorator.rb | Ruby | mit | 5,266 | master | 358 | class CommentDecorator < Draper::Decorator
delegate_all
# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override attributes, for example:
#
# def created_at
# helpers.content_tag :span, class: 'time' do
# object.created_at.strftime("%a ... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/app/controllers/posts_controller.rb | Ruby | mit | 5,266 | master | 365 | class PostsController < BaseController
decorates_assigned :post
def show
@post = Post.find(params[:id])
end
def mail
post = Post.find(params[:id])
email = PostMailer.decorated_email(post).deliver
render html: email.body.to_s.html_safe
end
private
def goodnight_moon
"Goodnight, moon... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/test/decorators/test_unit/view_context_test.rb | Ruby | mit | 5,266 | master | 545 | require 'test_helper'
def it_does_not_leak_view_context
2.times do |n|
define_method("test_has_independent_view_context_#{n}") do
refute_equal :leaked, Draper::ViewContext.current
Draper::ViewContext.current = :leaked
end
end
end
class DecoratorTest < Draper::TestCase
it_does_not_leak_view_c... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/test/decorators/test_unit/helpers_test.rb | Ruby | mit | 5,266 | master | 539 | require 'test_helper'
class HelpersTest < Draper::TestCase
def test_access_helpers_through_helper
assert_equal "<p>Help!</p>", helper.content_tag(:p, "Help!")
end
def test_access_helpers_through_helpers
assert_equal "<p>Help!</p>", helpers.content_tag(:p, "Help!")
end
def test_access_helpers_throug... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/test/decorators/test_unit/devise_test.rb | Ruby | mit | 5,266 | master | 1,034 | require 'test_helper'
if defined?(Devise)
class DeviseTest < Draper::TestCase
def test_sign_in_a_real_user
user = User.new
sign_in user
assert_same user, helper.current_user
end
def test_sign_in_a_mock_user
user = Object.new
sign_in :user, user
assert_same user, hel... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/test/decorators/minitest/devise_test.rb | Ruby | mit | 5,266 | master | 1,054 | require 'minitest_helper'
if defined?(Devise)
describe "A decorator test" do
it "can sign in a real user" do
user = User.new
sign_in user
assert_same user, helper.current_user
end
it "can sign in a mock user" do
user = Object.new
sign_in :user, user
assert_same user... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/test/decorators/minitest/view_context_test.rb | Ruby | mit | 5,266 | master | 507 | require 'minitest_helper'
def it_does_not_leak_view_context
2.times do
it "has an independent view context" do
refute_equal :leaked, Draper::ViewContext.current
Draper::ViewContext.current = :leaked
end
end
end
describe "A decorator test" do
it_does_not_leak_view_context
end
describe "A con... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/test/decorators/minitest/helpers_test.rb | Ruby | mit | 5,266 | master | 561 | require 'minitest_helper'
describe "A decorator test" do
it "can access helpers through `helper`" do
assert_equal "<p>Help!</p>", helper.content_tag(:p, "Help!")
end
it "can access helpers through `helpers`" do
assert_equal "<p>Help!</p>", helpers.content_tag(:p, "Help!")
end
it "can access helpers... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/test/decorators/minitest/spec_type_test.rb | Ruby | mit | 5,266 | master | 887 | require 'minitest_helper'
def it_is_a_decorator_test
it "is a decorator test" do
assert_kind_of Draper::TestCase, self
end
end
def it_is_not_a_decorator_test
it "is not a decorator test" do
refute_kind_of Draper::TestCase, self
end
end
ProductDecorator = Class.new(Draper::Decorator)
ProductsDecorator... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/dummy/fast_spec/post_decorator_spec.rb | Ruby | mit | 5,266 | master | 1,024 | require 'draper'
require 'active_model/naming'
require_relative '../app/decorators/post_decorator'
Draper::ViewContext.test_strategy :fast
Post = Struct.new(:id) { extend ActiveModel::Naming }
describe PostDecorator do
let(:decorator) { PostDecorator.new(object) }
let(:object) { Post.new(42) }
it "can use bu... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/support/dummy_app.rb | Ruby | mit | 5,266 | master | 1,815 | require 'socket'
require 'net/http'
# Adapted from code by Jon Leighton
# https://github.com/jonleighton/focused_controller/blob/ec7ccf1/test/acceptance/app_test.rb
class DummyApp
def initialize(environment)
raise ArgumentError, "Environment must be development or production" unless ["development", "production... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/support/matchers/have_text.rb | Ruby | mit | 5,266 | master | 877 | require 'capybara'
module HaveTextMatcher
def have_text(text)
HaveText.new(text)
end
class HaveText
def initialize(text)
@text = text
end
def in(css)
@css = css
self
end
def matches?(subject)
@subject = Capybara.string(subject)
@subject.has_css?(@css || "... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/support/shared_examples/view_helpers.rb | Ruby | mit | 5,266 | master | 1,377 | shared_examples_for "view helpers" do |subject|
describe "#helpers" do
it "returns the current view context" do
allow(Draper::ViewContext).to receive_messages current: :current_view_context
expect(subject.helpers).to be :current_view_context
end
it "is aliased to #h" do
allow(Draper::Vi... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/support/shared_examples/decoratable_equality.rb | Ruby | mit | 5,266 | master | 1,161 | shared_examples_for "decoration-aware #==" do |subject|
it "is true for itself" do
expect(subject == subject).to be_truthy
end
it "is false for another object" do
expect(subject == Object.new).to be_falsey
end
it "is true for a decorated version of itself" do
decorated = double(object: subject, ... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/generators/controller/controller_generator_spec.rb | Ruby | mit | 5,266 | master | 654 | require 'spec_helper'
require 'dummy/config/environment'
require 'ammeter/init'
require 'generators/controller_override'
require 'generators/rails/decorator_generator'
SimpleCov.command_name 'test:generator'
describe Rails::Generators::ControllerGenerator do
destination File.expand_path("../tmp", __FILE__)
before... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/generators/decorator/decorator_generator_spec.rb | Ruby | mit | 5,266 | master | 2,938 | require 'spec_helper'
require 'dummy/config/environment'
require 'ammeter/init'
require 'generators/rails/decorator_generator'
describe Rails::Generators::DecoratorGenerator do
destination File.expand_path("../tmp", __FILE__)
before { prepare_destination }
after(:all) { FileUtils.rm_rf destination_root }
des... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/generators/install/install_generator_spec.rb | Ruby | mit | 5,266 | master | 523 | require 'spec_helper'
require 'dummy/config/environment'
require 'ammeter/init'
require 'generators/draper/install_generator'
describe Draper::Generators::InstallGenerator do
destination File.expand_path('../tmp', __FILE__)
before { prepare_destination }
after(:all) { FileUtils.rm_rf destination_root }
descr... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/performance/benchmark.rb | Ruby | mit | 5,266 | master | 1,448 | require 'rubygems'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
Bundler.require :default
require "benchmark"
require "draper"
require "./performance/models"
require "./performance/decorators"
Benchmark.bm do |bm|
puts "\n[ Exclus... |
github | drapergem/draper | https://github.com/drapergem/draper | spec/performance/decorators.rb | Ruby | mit | 5,266 | master | 819 | require "./performance/models"
class ProductDecorator < Draper::Decorator
def awesome_title
"Awesome Title"
end
# Original #method_missing
def method_missing(method, *args, &block)
if allow?(method)
begin
model.send(method, *args, &block)
rescue NoMethodError
super
en... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.