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 | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | spec/support/macros/define_constant.rb | Ruby | mit | 8,193 | main | 1,507 | require "active_record"
module DefineConstantMacros
def define_class(path, base = Object, &block)
const = stub_const(path, Class.new(base))
const.class_eval(&block) if block
const
end
def define_model(name, columns = {}, &block)
model = define_class(name, ActiveRecord::Base, &block)
create_t... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | spec/support/macros/deprecation.rb | Ruby | mit | 8,193 | main | 230 | require "active_support"
RSpec.configure do |config|
config.around :example, silence_deprecation: true do |example|
with_temporary_assignment(FactoryBot::Deprecation, :silenced, true) do
example.run
end
end
end |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | spec/support/matchers/raise_did_you_mean_error.rb | Ruby | mit | 8,193 | main | 536 | RSpec::Matchers.define :raise_did_you_mean_error do
supports_block_expectations
match do |actual|
# detailed_message introduced in Ruby 3.2 for cleaner integration with
# did_you_mean. See https://bugs.ruby-lang.org/issues/18564
matcher = if KeyError.method_defined?(:detailed_message)
raise_error... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | spec/support/matchers/declaration.rb | Ruby | mit | 8,193 | main | 1,621 | module DeclarationMatchers
def have_dynamic_declaration(name)
DeclarationMatcher.new(:dynamic).named(name)
end
def have_association_declaration(name)
DeclarationMatcher.new(:association).named(name)
end
def have_implicit_declaration(name)
DeclarationMatcher.new(:implicit).named(name)
end
cl... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | spec/support/matchers/trait.rb | Ruby | mit | 8,193 | main | 260 | RSpec::Matchers.define :have_trait do |trait_name|
match do |instance|
instance.defined_traits.any? do |trait|
trait.name == trait_name.to_s && trait.send(:block) == @block
end
end
chain :with_block do |block|
@block = block
end
end |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | spec/support/matchers/delegate.rb | Ruby | mit | 8,193 | main | 1,099 | RSpec::Matchers.define :delegate do |delegated_method|
chain :to do |target_method|
@target_method = target_method
end
chain :as do |method_on_target|
@method_on_target = method_on_target
end
chain :with_arguments do |args|
@args = args
end
match do |instance|
@instance = instance
@... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | spec/support/matchers/callback.rb | Ruby | mit | 8,193 | main | 227 | RSpec::Matchers.define :have_callback do |callback_name|
match do |instance|
instance.callbacks.include?(FactoryBot::Callback.new(callback_name, @block))
end
chain :with_block do |block|
@block = block
end
end |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | spec/support/shared_examples/strategy.rb | Ruby | mit | 8,193 | main | 3,113 | shared_examples_for "strategy without association support" do
let(:factory) { double("associate_factory") }
let(:attribute) { FactoryBot::Attribute::Association.new(:user, :user, {}) }
def association_named(name, overrides)
runner = FactoryBot::FactoryRunner.new(name, :build, [overrides])
subject.associa... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | features/support/factories.rb | Ruby | mit | 8,193 | main | 345 | ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
database: ":memory:"
)
class CreateSchema < ActiveRecord::Migration[5.0]
def self.up
create_table :categories, force: true do |t|
t.string :name
end
end
end
CreateSchema.suppress_messages { CreateSchema.migrate(:up) }
class Category <... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | features/support/env.rb | Ruby | mit | 8,193 | main | 236 | PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
require "simplecov" if RUBY_ENGINE == "ruby"
$: << File.join(PROJECT_ROOT, "lib")
require "active_record"
require "factory_bot"
require "aruba/cucumber" |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | features/step_definitions/database_steps.rb | Ruby | mit | 8,193 | main | 220 | Then(/^I should find the following for the last category:$/) do |table|
table.hashes.first.each do |key, value|
expect(Category.last.attributes[key].to_s).to eq value
end
end
Before do
Category.delete_all
end |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | features/step_definitions/factory_bot_steps.rb | Ruby | mit | 8,193 | main | 1,033 | module FactoryBotDefinitionsHelper
def append_file_to_factory_bot_definitions_path(path_to_file)
FactoryBot.definition_file_paths ||= []
FactoryBot.definition_file_paths << path_to_file
end
end
World(FactoryBotDefinitionsHelper)
When(/^"([^"]*)" is added to FactoryBot's file definitions path$/) do |file_n... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot.rb | Ruby | mit | 8,193 | main | 4,244 | require "set"
require "active_support"
require "active_support/core_ext/module/delegation"
require "active_support/core_ext/module/attribute_accessors"
require "active_support/deprecation"
require "active_support/notifications"
require "factory_bot/internal"
require "factory_bot/definition_hierarchy"
require "factory_... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/definition_hierarchy.rb | Ruby | mit | 8,193 | main | 872 | module FactoryBot
class DefinitionHierarchy
delegate :callbacks, :constructor, :to_create, to: Internal
def self.build_from_definition(definition)
build_to_create(&definition.to_create)
build_constructor(&definition.constructor)
add_callbacks definition.callbacks
end
def self.add_c... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/attribute_list.rb | Ruby | mit | 8,193 | main | 1,577 | module FactoryBot
# @api private
class AttributeList
include Enumerable
def initialize(name = nil, attributes = [])
@name = name
@attributes = attributes
end
def define_attribute(attribute)
ensure_attribute_not_self_referencing! attribute
ensure_attribute_not_defined! attri... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/registry.rb | Ruby | mit | 8,193 | main | 1,329 | require "active_support/hash_with_indifferent_access"
module FactoryBot
class Registry
include Enumerable
attr_reader :name
def initialize(name)
@name = name
@items = ActiveSupport::HashWithIndifferentAccess.new
end
def clear
@items.clear
end
def each(&block)
@... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/strategy.rb | Ruby | mit | 8,193 | main | 413 | require "factory_bot/strategy/build"
require "factory_bot/strategy/create"
require "factory_bot/strategy/attributes_for"
require "factory_bot/strategy/stub"
require "factory_bot/strategy/null"
module FactoryBot
module Strategy
def self.lookup_strategy(name_or_object)
return name_or_object if name_or_object... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/errors.rb | Ruby | mit | 8,193 | main | 1,118 | module FactoryBot
# Raised when a factory is defined that attempts to instantiate itself.
class AssociationDefinitionError < RuntimeError; end
# Raised when a trait is defined that references itself.
class TraitDefinitionError < RuntimeError; end
# Raised when a callback is defined that has an invalid name
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/definition_proxy.rb | Ruby | mit | 8,193 | main | 7,575 | module FactoryBot
class DefinitionProxy
UNPROXIED_METHODS = %w[
__send__
__id__
nil?
send
object_id
extend
instance_eval
initialize
block_given?
raise
caller
method
].freeze
(instance_methods + private_instance_methods).each do |meth... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/callbacks_observer.rb | Ruby | mit | 8,193 | main | 960 | module FactoryBot
# @api private
class CallbacksObserver
def initialize(callbacks, evaluator)
@callbacks = callbacks
@evaluator = evaluator
@completed = []
end
def update(name, result_instance)
callbacks_by_name(name).each do |callback|
if !completed?(result_instance, ca... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/attribute_assigner.rb | Ruby | mit | 8,193 | main | 6,017 | module FactoryBot
# @api private
class AttributeAssigner
def initialize(evaluator, build_class, &instance_builder)
@build_class = build_class
@instance_builder = instance_builder
@evaluator = evaluator
@attribute_list = evaluator.class.attribute_list
@attribute_names_assigned = []
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/evaluator.rb | Ruby | mit | 8,193 | main | 2,454 | require "active_support/core_ext/class/attribute"
module FactoryBot
# @api private
class Evaluator
class_attribute :attribute_lists
private_instance_methods.each do |method|
undef_method(method) unless method.match?(/^__|initialize/)
end
def initialize(build_strategy, overrides = {})
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/factory_runner.rb | Ruby | mit | 8,193 | main | 932 | module FactoryBot
class FactoryRunner
def initialize(name, strategy, traits_and_overrides)
@name = name
@strategy = strategy
@overrides = traits_and_overrides.extract_options!
@traits = traits_and_overrides
end
def run(runner_strategy = @strategy, &block)
factory = FactoryB... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/uri_manager.rb | Ruby | mit | 8,193 | main | 1,483 | module FactoryBot
# @api private
class UriManager
attr_reader :endpoints, :paths, :uri_list
delegate :size, :any?, :empty?, :each?, :include?, :first, to: :@uri_list
delegate :build_uri, to: :class
# Concatenate the parts, sripping leading/following slashes
# and returning a Symbolized String ... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/sequence.rb | Ruby | mit | 8,193 | main | 4,546 | require "timeout"
module FactoryBot
# Sequences are defined using sequence within a FactoryBot.define block.
# Sequence values are generated using next.
# @api private
class Sequence
attr_reader :name, :uri_manager, :aliases
def self.find(*uri_parts)
if uri_parts.empty?
fail ArgumentErro... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/evaluator_class_definer.rb | Ruby | mit | 8,193 | main | 513 | module FactoryBot
# @api private
class EvaluatorClassDefiner
def initialize(attributes, parent_class)
@parent_class = parent_class
@attributes = attributes
attributes.each do |attribute|
evaluator_class.define_attribute(attribute.name, &attribute.to_proc)
end
end
def ev... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/null_factory.rb | Ruby | mit | 8,193 | main | 460 | module FactoryBot
# @api private
class NullFactory
attr_reader :definition
def initialize
@definition = Definition.new(:null_factory)
end
delegate :defined_traits, :callbacks, :attributes, :constructor,
:to_create, to: :definition
def compile
end
def class_name
end
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/trait.rb | Ruby | mit | 8,193 | main | 882 | module FactoryBot
# @api private
class Trait
attr_reader :name, :uid, :definition
delegate :add_callback, :declare_attribute, :to_create, :define_trait, :constructor,
:callbacks, :attributes, :klass, :klass=, to: :@definition
def initialize(name, **options, &block)
@name = name.to_s
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/callback.rb | Ruby | mit | 8,193 | main | 633 | module FactoryBot
class Callback
attr_reader :name
def initialize(name, block)
@name = name.to_sym
@block = block
end
def run(instance, evaluator)
case block.arity
when 1, -1, -2 then syntax_runner.instance_exec(instance, &block)
when 2 then syntax_runner.instance_exec(... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/aliases.rb | Ruby | mit | 8,193 | main | 344 | module FactoryBot
class << self
attr_accessor :aliases
end
self.aliases = [
[/(.+)_id/, '\1'],
[/(.*)/, '\1_id']
]
def self.aliases_for(attribute)
aliases.map { |(pattern, replace)|
if pattern.match?(attribute)
attribute.to_s.sub(pattern, replace).to_sym
end
}.compact... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/linter.rb | Ruby | mit | 8,193 | main | 2,823 | module FactoryBot
class Linter
def initialize(factories, strategy: :create, traits: false, verbose: false)
@factories_to_lint = factories
@factory_strategy = strategy
@traits = traits
@verbose = verbose
@invalid_factories = calculate_invalid_factories
end
def lint!
if ... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/null_object.rb | Ruby | mit | 8,193 | main | 457 | module FactoryBot
# @api private
class NullObject < ::BasicObject
def initialize(methods_to_respond_to)
@methods_to_respond_to = methods_to_respond_to.map(&:to_s)
end
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
if respond_to?(name)
nil
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/internal.rb | Ruby | mit | 8,193 | main | 3,079 | module FactoryBot
# @api private
module Internal
class << self
delegate :after,
:before,
:callbacks,
:constructor,
:factories,
:initialize_with,
:inline_sequences,
:sequences,
:skip_create,
:strategies,
:to_create,
:tr... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/enum.rb | Ruby | mit | 8,193 | main | 608 | module FactoryBot
# @api private
class Enum
def initialize(attribute_name, values = nil)
@attribute_name = attribute_name
@values = values
end
def build_traits(klass)
enum_values(klass).map do |trait_name, value|
build_trait(trait_name, @attribute_name, value || trait_name)
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/decorator.rb | Ruby | mit | 8,193 | main | 494 | module FactoryBot
class Decorator < BasicObject
undef_method :==
def initialize(component)
@component = component
end
def method_missing(...) # rubocop:disable Style/MethodMissingSuper
@component.send(...)
end
def send(...)
__send__(...)
end
def respond_to_missing... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/factory.rb | Ruby | mit | 8,193 | main | 4,403 | require "active_support/core_ext/hash/keys"
require "active_support/inflector"
module FactoryBot
# @api private
class Factory
attr_reader :name, :definition
def initialize(name, options = {})
assert_valid_options(options)
@name = name.respond_to?(:to_sym) ? name.to_sym : name.to_s.underscore.t... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/find_definitions.rb | Ruby | mit | 8,193 | main | 840 | module FactoryBot
class << self
# An Array of strings specifying locations that should be searched for
# factory definitions. By default, factory_bot will attempt to require
# "factories.rb", "factories/**/*.rb", "test/factories.rb",
# "test/factories/**.rb", "spec/factories.rb", and "spec/factories/*... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/attribute.rb | Ruby | mit | 8,193 | main | 478 | require "factory_bot/attribute/dynamic"
require "factory_bot/attribute/association"
require "factory_bot/attribute/sequence"
module FactoryBot
# @api private
class Attribute
attr_reader :name, :ignored
def initialize(name, ignored)
@name = name.to_sym
@ignored = ignored
end
def to_pro... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/declaration.rb | Ruby | mit | 8,193 | main | 398 | require "factory_bot/declaration/dynamic"
require "factory_bot/declaration/association"
require "factory_bot/declaration/implicit"
module FactoryBot
# @api private
class Declaration
attr_reader :name
def initialize(name, ignored = false)
@name = name
@ignored = ignored
end
def to_attr... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/declaration_list.rb | Ruby | mit | 8,193 | main | 978 | module FactoryBot
# @api private
class DeclarationList
include Enumerable
def initialize(name = nil)
@declarations = []
@name = name
@overridable = false
end
def declare_attribute(declaration)
delete_declaration(declaration) if overridable?
@declarations << declarati... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/configuration.rb | Ruby | mit | 8,193 | main | 908 | module FactoryBot
# @api private
class Configuration
attr_reader(
:callback_names,
:factories,
:inline_sequences,
:sequences,
:strategies,
:traits
)
def initialize
@factories = Decorator::DisallowsDuplicatesRegistry.new(Registry.new("Factory"))
@sequences... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/strategy_syntax_method_registrar.rb | Ruby | mit | 8,193 | main | 1,793 | module FactoryBot
# @api private
class StrategySyntaxMethodRegistrar
def initialize(strategy_name)
@strategy_name = strategy_name
end
def define_strategy_methods
define_singular_strategy_method
define_list_strategy_method
define_pair_strategy_method
end
def self.with_in... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/evaluation.rb | Ruby | mit | 8,193 | main | 582 | module FactoryBot
class Evaluation
def initialize(evaluator, attribute_assigner, to_create, observer)
@evaluator = evaluator
@attribute_assigner = attribute_assigner
@to_create = to_create
@observer = observer
end
delegate :object, :hash, to: :@attribute_assigner
def create(r... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/definition.rb | Ruby | mit | 8,193 | main | 5,421 | module FactoryBot
# @api private
class Definition
attr_reader :defined_traits, :declarations, :name, :registered_enums, :uri_manager
attr_accessor :klass
def initialize(name, base_traits = [], **opts)
@name = name
@uri_manager = opts[:uri_manager]
@declarations = DeclarationList.new(n... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/declaration/dynamic.rb | Ruby | mit | 8,193 | main | 537 | module FactoryBot
class Declaration
# @api private
class Dynamic < Declaration
def initialize(name, ignored = false, block = nil)
super(name, ignored)
@block = block
end
def ==(other)
self.class == other.class &&
name == other.name &&
ignored == o... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/declaration/implicit.rb | Ruby | mit | 8,193 | main | 947 | module FactoryBot
class Declaration
# @api private
class Implicit < Declaration
def initialize(name, factory = nil, ignored = false)
super(name, ignored)
@factory = factory
end
def ==(other)
self.class == other.class &&
name == other.name &&
facto... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/declaration/association.rb | Ruby | mit | 8,193 | main | 1,429 | module FactoryBot
class Declaration
# @api private
class Association < Declaration
def initialize(name, *options)
super(name, false)
@options = options.dup
@overrides = options.extract_options!
@factory_name = @overrides.delete(:factory) || name
@traits = options
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/attribute/dynamic.rb | Ruby | mit | 8,193 | main | 514 | module FactoryBot
class Attribute
# @api private
class Dynamic < Attribute
def initialize(name, ignored, block)
super(name, ignored)
@block = block
end
def to_proc
block = @block
-> {
value = case block.arity
when 1, -1, -2 then instance_... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/attribute/association.rb | Ruby | mit | 8,193 | main | 586 | module FactoryBot
class Attribute
# @api private
class Association < Attribute
attr_reader :factory
def initialize(name, factory, overrides)
super(name, false)
@factory = factory
@overrides = overrides
end
def to_proc
factory = @factory
overrid... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/attribute/sequence.rb | Ruby | mit | 8,193 | main | 321 | module FactoryBot
class Attribute
# @api private
class Sequence < Attribute
def initialize(name, sequence, ignored)
super(name, ignored)
@sequence = sequence
end
def to_proc
sequence = @sequence
-> { FactoryBot.generate(sequence) }
end
end
end
end |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/syntax/methods.rb | Ruby | mit | 8,193 | main | 7,238 | module FactoryBot
module Syntax
## This module is a container for all strategy methods provided by
## FactoryBot. This includes all the default strategies provided ({Methods#build},
## {Methods#create}, {Methods#build_stubbed}, and {Methods#attributes_for}), as
## well as the complementary *_list and ... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/syntax/default.rb | Ruby | mit | 8,193 | main | 1,601 | module FactoryBot
module Syntax
module Default
include Methods
def define(&block)
DSL.run(block)
end
def modify(&block)
ModifyDSL.run(block)
end
class DSL
def factory(name, options = {}, &block)
factory = Factory.new(name, options)
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/strategy/stub.rb | Ruby | mit | 8,193 | main | 3,304 | module FactoryBot
module Strategy
class Stub
@@next_id = 1000
DISABLED_PERSISTENCE_METHODS = [
:connection,
:decrement!,
:delete,
:destroy!,
:destroy,
:increment!,
:reload,
:save!,
:save,
:toggle!,
:touch,
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/strategy/build.rb | Ruby | mit | 8,193 | main | 367 | module FactoryBot
module Strategy
class Build
def association(runner)
runner.run
end
def result(evaluation)
evaluation.notify(:before_build, nil)
evaluation.object.tap do |instance|
evaluation.notify(:after_build, instance)
end
end
def to_... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/strategy/attributes_for.rb | Ruby | mit | 8,193 | main | 260 | module FactoryBot
module Strategy
class AttributesFor
def association(runner)
runner.run(:null)
end
def result(evaluation)
evaluation.hash
end
def to_sym
:attributes_for
end
end
end
end |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/strategy/create.rb | Ruby | mit | 8,193 | main | 514 | module FactoryBot
module Strategy
class Create
def association(runner)
runner.run
end
def result(evaluation)
evaluation.notify(:before_build, nil)
evaluation.object.tap do |instance|
evaluation.notify(:after_build, instance)
evaluation.notify(:before... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/decorator/attribute_hash.rb | Ruby | mit | 8,193 | main | 387 | module FactoryBot
class Decorator
class AttributeHash < Decorator
def initialize(component, attributes = [])
super(component)
@attributes = attributes
end
def attributes
@attributes.each_with_object({}) do |attribute_name, result|
result[attribute_name] = @comp... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/decorator/disallows_duplicates_registry.rb | Ruby | mit | 8,193 | main | 332 | module FactoryBot
class Decorator
class DisallowsDuplicatesRegistry < Decorator
def register(name, item)
if registered?(name)
raise DuplicateDefinitionError, "#{@component.name} already registered: #{name}"
else
@component.register(name, item)
end
end
en... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/decorator/invocation_tracker.rb | Ruby | mit | 8,193 | main | 478 | module FactoryBot
class Decorator
class InvocationTracker < Decorator
def initialize(component)
super
@invoked_methods = []
end
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
@invoked_methods << name
super
end
... |
github | thoughtbot/factory_bot | https://github.com/thoughtbot/factory_bot | lib/factory_bot/decorator/new_constructor.rb | Ruby | mit | 8,193 | main | 246 | module FactoryBot
class Decorator
class NewConstructor < Decorator
def initialize(component, build_class)
super(component)
@build_class = build_class
end
delegate :new, to: :@build_class
end
end
end |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | omniauth.gemspec | Ruby | mit | 8,068 | master | 1,124 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'omniauth/version'
Gem::Specification.new do |spec|
spec.add_dependency 'hashie', ['>= 3.4.6']
spec.add_dependency 'rack', '>= 2.2.3'
spec.add_development_dependency 'bundler', '>= 2.0'
s... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | Gemfile | Ruby | mit | 8,068 | master | 492 | source 'https://rubygems.org'
gem 'jruby-openssl', '~> 0.10.5', platforms: :jruby
gem 'rake', '>= 12.0'
gem 'yard', '>= 0.9.11'
group :development do
gem 'benchmark-ips'
gem 'kramdown'
gem 'memory_profiler'
gem 'pry'
end
group :test do
gem 'cgi'
gem 'coveralls_reborn', '~> 0.19.0', require: false
gem '... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | Rakefile | Ruby | mit | 8,068 | master | 1,143 | require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :test => :spec
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue LoadError
task :rubocop do
warn 'RuboCop is disabled'
end
end
task :default => %i[spec rubocop]
namespace ... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | spec/omniauth_spec.rb | Ruby | mit | 8,068 | master | 5,906 | require 'helper'
describe OmniAuth do
describe '.strategies' do
it 'increases when a new strategy is made' do
expect do
class ExampleStrategy
include OmniAuth::Strategy
end
end.to change(OmniAuth.strategies, :size).by(1)
expect(OmniAuth.strategies.last).to eq(ExampleSt... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | spec/helper.rb | Ruby | mit | 8,068 | master | 1,581 | require 'simplecov'
require 'coveralls'
require 'simplecov-lcov'
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::LcovFormatter,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start do
add_filter ['/spec... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | spec/omniauth/failure_endpoint_spec.rb | Ruby | mit | 8,068 | master | 2,361 | require 'helper'
describe OmniAuth::FailureEndpoint do
subject { OmniAuth::FailureEndpoint }
context 'raise-out environment' do
before do
@rack_env = ENV['RACK_ENV']
ENV['RACK_ENV'] = 'test'
@default = OmniAuth.config.failure_raise_out_environments
OmniAuth.config.failure_raise_out_en... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | spec/omniauth/strategy_spec.rb | Ruby | mit | 8,068 | master | 41,032 | require 'helper'
def make_env(path = '/auth/test', props = {})
{
'REQUEST_METHOD' => 'POST',
'PATH_INFO' => path,
'rack.session' => {},
'rack.input' => StringIO.new('test=true')
}.merge(props)
end
describe OmniAuth::Strategy do
let(:app) do
lambda { |_env| [404, {}, ['Awesome']] }
end
l... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | spec/omniauth/auth_hash_spec.rb | Ruby | mit | 8,068 | master | 4,357 | require 'helper'
describe OmniAuth::AuthHash do
subject { OmniAuth::AuthHash.new }
it 'converts a supplied info key into an InfoHash object' do
subject.info = {:first_name => 'Awesome'}
expect(subject.info).to be_kind_of(OmniAuth::AuthHash::InfoHash)
expect(subject.info.first_name).to eq('Awesome')
e... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | spec/omniauth/key_store_spec.rb | Ruby | mit | 8,068 | master | 2,049 | require 'helper'
RSpec.describe OmniAuth::KeyStore do
let(:logger) { double('Logger') }
around(:each) do |example|
patched = monkey_patch_logger
example.run
remove_logger(patched)
end
context 'on Hashie < 3.5.0' do
let(:version) { '3.4.0' }
it 'does not log anything to the console' do
... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | spec/omniauth/form_spec.rb | Ruby | mit | 8,068 | master | 2,095 | require 'helper'
describe OmniAuth::Form do
describe '.build' do
it 'yields the instance when called with a block and argument' do
OmniAuth::Form.build { |f| expect(f).to be_kind_of(OmniAuth::Form) }
end
it 'evaluates in the instance when called with a block and no argument' do
f = OmniAuth:... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | spec/omniauth/builder_spec.rb | Ruby | mit | 8,068 | master | 4,018 | require 'helper'
describe OmniAuth::Builder do
describe '#provider' do
it 'translates a symbol to a constant' do
expect(OmniAuth::Strategies).to receive(:const_get).with('MyStrategy', false).and_return(Class.new)
OmniAuth::Builder.new(nil) do
provider :my_strategy
end
end
it 'a... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | spec/omniauth/strategies/developer_spec.rb | Ruby | mit | 8,068 | master | 2,133 | require 'helper'
describe OmniAuth::Strategies::Developer do
let(:app) do
Rack::Builder.new do |b|
b.use Rack::Session::Cookie, :secret => 'abc123'
b.use OmniAuth::Strategies::Developer
b.run lambda { |_env| [200, {}, ['Not Found']] }
end.to_app
end
context 'request phase' do
befor... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth.rb | Ruby | mit | 8,068 | master | 5,272 | # TODO: Fixed in https://github.com/rack/rack/pull/1610 for Rack 3
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
require 'delegate'
end
require 'rack'
require 'singleton'
require 'logger'
module OmniAuth
class Error < StandardError; end
module Strategies
autoload :Developer, 'omniauth/strategies/develo... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/auth_hash.rb | Ruby | mit | 8,068 | master | 1,309 | require 'omniauth/key_store'
module OmniAuth
# The AuthHash is a normalized schema returned by all OmniAuth
# strategies. It maps as much user information as the provider
# is able to provide into the InfoHash (stored as the `'info'`
# key).
class AuthHash < OmniAuth::KeyStore
def self.subkey_class
... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/form.rb | Ruby | mit | 8,068 | master | 2,615 | module OmniAuth
class Form
DEFAULT_CSS = File.read(File.expand_path('../form.css', __FILE__))
attr_accessor :options
def initialize(options = {})
options[:title] ||= 'Authentication Info Required'
options[:header_info] ||= ''
options[:method] ||= 'post'
self.options = options
... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/builder.rb | Ruby | mit | 8,068 | master | 1,266 | module OmniAuth
class Builder < ::Rack::Builder
def on_failure(&block)
OmniAuth.config.on_failure = block
end
def before_options_phase(&block)
OmniAuth.config.before_options_phase = block
end
def before_request_phase(&block)
OmniAuth.config.before_request_phase = block
end
... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/strategy.rb | Ruby | mit | 8,068 | master | 18,426 | require 'omniauth/key_store'
module OmniAuth
class NoSessionError < StandardError; end
# The Strategy is the base unit of OmniAuth's ability to
# wrangle multiple providers. Each strategy provided by
# OmniAuth includes this mixin to gain the default functionality
# necessary to be compatible with the OmniAu... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/authenticity_token_protection.rb | Ruby | mit | 8,068 | master | 640 | require 'rack-protection'
module OmniAuth
class AuthenticityError < StandardError; end
class AuthenticityTokenProtection < Rack::Protection::AuthenticityToken
def initialize(options = {})
@options = default_options.merge(options)
end
def self.call(env)
new.call!(env)
end
def call!... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/failure_endpoint.rb | Ruby | mit | 8,068 | master | 1,567 | module OmniAuth
# This simple Rack endpoint that serves as the default
# 'failure' mechanism for OmniAuth. If a strategy fails for
# any reason this endpoint will be invoked. The default behavior
# is to redirect to `/auth/failure` except in the case of
# a development `RACK_ENV`, in which case an exception w... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/key_store.rb | Ruby | mit | 8,068 | master | 608 | require 'hashie/mash'
module OmniAuth
# Generic helper hash that allows method access on deeply nested keys.
class KeyStore < ::Hashie::Mash
# Disables warnings on Hashie 3.5.0+ for overwritten keys
def self.override_logging
require 'hashie/version'
return unless Gem::Version.new(Hashie::VERSIO... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/test.rb | Ruby | mit | 8,068 | master | 278 | module OmniAuth
# Support for testing OmniAuth strategies.
module Test
autoload :PhonySession, 'omniauth/test/phony_session'
autoload :StrategyMacros, 'omniauth/test/strategy_macros'
autoload :StrategyTestCase, 'omniauth/test/strategy_test_case'
end
end |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/strategies/developer.rb | Ruby | mit | 8,068 | master | 1,715 | module OmniAuth
module Strategies
# The Developer strategy is a very simple strategy that can be used as a
# placeholder in your application until a different authentication strategy
# is swapped in. It has zero security and should *never* be used in a
# production setting.
#
# ## Usage
#
... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/test/phony_session.rb | Ruby | mit | 8,068 | master | 268 | module OmniAuth
module Test
class PhonySession
def initialize(app)
@app = app
end
def call(env)
@session ||= (env['rack.session'] || {})
env['rack.session'] = @session
@app.call(env)
end
end
end
end |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/test/strategy_macros.rb | Ruby | mit | 8,068 | master | 794 | module OmniAuth
module Test
module StrategyMacros
def sets_an_auth_hash
it 'sets an auth hash' do
expect(last_request.env['omniauth.auth']).to be_kind_of(Hash)
end
end
def sets_provider_to(provider)
it "sets the provider to #{provider}" do
expect((las... |
github | omniauth/omniauth | https://github.com/omniauth/omniauth | lib/omniauth/test/strategy_test_case.rb | Ruby | mit | 8,068 | master | 1,153 | require 'rack'
require 'omniauth/test'
module OmniAuth
module Test
# Support for testing OmniAuth strategies.
#
# @example Usage
# class MyStrategyTest < Test::Unit::TestCase
# include OmniAuth::Test::StrategyTestCase
# def strategy
# # return the parameters to a Rack::Bui... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | rails_admin.gemspec | Ruby | mit | 7,954 | master | 1,759 | # frozen_string_literal: true
require_relative 'lib/rails_admin/version'
Gem::Specification.new do |spec|
# If you add a dependency, please maintain alphabetical order
spec.add_dependency 'activemodel-serializers-xml', '>= 1.0'
spec.add_dependency 'csv'
spec.add_dependency 'kaminari', '>= 0.14', '< 2.0'
spe... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | Rakefile | Ruby | mit | 7,954 | master | 961 | # frozen_string_literal: true
# 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.
Dir['lib/tasks/*.rake'].each { |rake| load rake }
require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_ta... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | Gemfile | Ruby | mit | 7,954 | master | 1,441 | # frozen_string_literal: true
source 'https://rubygems.org'
gem 'appraisal', '>= 2.0'
gem 'devise', '~> 4.7'
gem 'net-smtp', require: false
gem 'rails'
gem 'sassc-rails', '~> 2.1'
gem 'turbo-rails'
gem 'vite_rails', require: false
gem 'webpacker', require: false
gem 'webrick'
group :development, :test do
gem 'pry'... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | Appraisals | Ruby | mit | 7,954 | master | 4,763 | # frozen_string_literal: true
appraise 'rails-6.0' do
gem 'rails', '~> 6.0.0'
gem 'concurrent-ruby', '1.3.4' # Workaround for https://github.com/rails/rails/issues/54260
gem 'psych', '~> 3.3'
gem 'turbo-rails', '< 2.0.8'
group :test do
gem 'cancancan', ['~> 3.0', '< 3.6']
gem 'pundit', '~> 2.1.0'
... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | app/helpers/rails_admin/application_helper.rb | Ruby | mit | 7,954 | master | 10,747 | # frozen_string_literal: true
module RailsAdmin
module ApplicationHelper
def authorized?(action_name, abstract_model = nil, object = nil)
object = nil if object.try :new_record?
action(action_name, abstract_model, object).try(:authorized?)
end
def current_action
params[:action].in?(%w[... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | app/helpers/rails_admin/main_helper.rb | Ruby | mit | 7,954 | master | 2,173 | # frozen_string_literal: true
module RailsAdmin
module MainHelper
def rails_admin_form_for(*args, &block)
options = args.extract_options!.reverse_merge(builder: RailsAdmin::FormBuilder)
(options[:html] ||= {})[:novalidate] ||= !RailsAdmin::Config.browser_validations
form_for(*(args << options)... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | app/helpers/rails_admin/form_builder.rb | Ruby | mit | 7,954 | master | 5,404 | # frozen_string_literal: true
require 'nested_form/builder_mixin'
module RailsAdmin
class FormBuilder < ::ActionView::Helpers::FormBuilder
include ::NestedForm::BuilderMixin
include ::RailsAdmin::ApplicationHelper
def generate(options = {})
without_field_error_proc_added_div do
options.re... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | app/controllers/rails_admin/main_controller.rb | Ruby | mit | 7,954 | master | 6,755 | # frozen_string_literal: true
module RailsAdmin
class MainController < RailsAdmin::ApplicationController
include ActionView::Helpers::TextHelper
include RailsAdmin::MainHelper
include RailsAdmin::ApplicationHelper
before_action :check_for_cancel
def bulk_action
get_model
process(par... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | app/controllers/rails_admin/application_controller.rb | Ruby | mit | 7,954 | master | 2,274 | # frozen_string_literal: true
require 'rails_admin/abstract_model'
module RailsAdmin
class ModelNotFound < ::StandardError
end
class ObjectNotFound < ::StandardError
end
class ActionNotAllowed < ::StandardError
end
class ApplicationController < Config.parent_controller.constantize
include RailsAd... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | spec/spec_helper.rb | Ruby | mit | 7,954 | master | 3,583 | # frozen_string_literal: true
# Configure Rails Environment
ENV['RAILS_ENV'] = 'test'
CI_ORM = (ENV['CI_ORM'] || :active_record).to_sym
PK_COLUMN = {active_record: :id, mongoid: :_id}[CI_ORM]
if RUBY_ENGINE == 'jruby'
# Workaround for JRuby CI failure https://github.com/jruby/jruby/issues/6547#issuecomment-77410499... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | spec/policies.rb | Ruby | mit | 7,954 | master | 1,184 | # frozen_string_literal: true
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
def show?
user.roles.include? :admin
end
def destroy?
false
end
def history?
user.roles.include? :admin
end
def show_in_app?
u... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | spec/factories.rb | Ruby | mit | 7,954 | master | 3,029 | # frozen_string_literal: true
FactoryBot.define do
factory :player do
sequence(:name) { |n| "Player #{n}" }
sequence(:number) { |n| n }
sequence(:position) { |n| "Position #{n}" }
end
factory :draft do
date { 1.week.ago }
sequence(:round)
sequence(:pick)
sequence(:overall)
sequen... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | spec/shared_examples/shared_examples_for_field_types.rb | Ruby | mit | 7,954 | master | 2,000 | # frozen_string_literal: true
require 'spec_helper'
RSpec.shared_examples 'a generic field type' do |column_name, field_type|
describe '#html_attributes' do
context 'when the field is required' do
before do
RailsAdmin.config FieldTest do
field column_name, field_type do
requi... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | spec/integration/rails_admin_spec.rb | Ruby | mit | 7,954 | master | 8,117 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe RailsAdmin, type: :request do
subject { page }
before do
RailsAdmin::Config.authenticate_with { warden.authenticate! scope: :user }
RailsAdmin::Config.current_user_method(&:current_user)
login_as User.create(
email: 'username@ex... |
github | railsadminteam/rails_admin | https://github.com/railsadminteam/rails_admin | spec/integration/authorization/cancancan_spec.rb | Ruby | mit | 7,954 | master | 13,616 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'RailsAdmin CanCanCan Authorization', type: :request do
class Ability
include CanCan::Ability
def initialize(user)
can :access, :rails_admin if user.roles.include? :admin
can :read, :dashboard
if user.roles.include? :test_e... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.