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 | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/generators/cancan/ability/templates/ability.rb | Ruby | mit | 5,670 | develop | 1,066 | # frozen_string_literal: true
class Ability
include CanCan::Ability
def initialize(user)
# Define abilities for the user here. For example:
#
# return unless user.present?
# can :read, :all
# return unless user.admin?
# can :manage, :all
#
# The first argument to `can` is t... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/matchers.rb | Ruby | mit | 5,670 | develop | 1,538 | # frozen_string_literal: true
rspec_module = defined?(RSpec::Core) ? 'RSpec' : 'Spec' # RSpec 1 compatability
if rspec_module == 'RSpec'
require 'rspec/core'
require 'rspec/expectations'
else
ActiveSupport::Deprecation.warn('RSpec < 3 will not be supported in the CanCanCan >= 2.0.0')
end
Kernel.const_get(rspec... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/controller_resource_builder.rb | Ruby | mit | 5,670 | develop | 703 | # frozen_string_literal: true
module CanCan
module ControllerResourceBuilder
protected
def build_resource
resource = resource_base.new(resource_params || {})
assign_attributes(resource)
end
def assign_attributes(resource)
resource.send("#{parent_name}=", parent_resource) if @optio... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/controller_resource_sanitizer.rb | Ruby | mit | 5,670 | develop | 834 | # frozen_string_literal: true
module CanCan
module ControllerResourceSanitizer
protected
def sanitize_parameters
case params_method
when Symbol
@controller.send(params_method)
when String
@controller.instance_eval(params_method)
when Proc
params_method.call(@c... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_additions.rb | Ruby | mit | 5,670 | develop | 1,338 | # frozen_string_literal: true
module CanCan
# This module adds the accessible_by class method to a model. It is included in the model adapters.
module ModelAdditions
module ClassMethods
# Returns a scope which fetches only the records that the passed ability
# can perform a given action on. The act... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/rules_compressor.rb | Ruby | mit | 5,670 | develop | 1,279 | # frozen_string_literal: true
require_relative 'conditions_matcher.rb'
module CanCan
class RulesCompressor
attr_reader :initial_rules, :rules_collapsed
def initialize(rules)
@initial_rules = rules
@rules_collapsed = compress(@initial_rules)
end
def compress(array)
array = simplify... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/controller_resource_finder.rb | Ruby | mit | 5,670 | develop | 1,088 | # frozen_string_literal: true
module CanCan
module ControllerResourceFinder
protected
def find_resource
if @options[:singleton] && parent_resource.respond_to?(name)
parent_resource.send(name)
elsif @options[:find_by]
find_resource_using_find_by
else
adapter.find(res... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/ability.rb | Ruby | mit | 5,670 | develop | 10,997 | # frozen_string_literal: true
require_relative 'ability/rules.rb'
require_relative 'ability/actions.rb'
require_relative 'unauthorized_message_resolver.rb'
require_relative 'ability/strong_parameter_support'
module CanCan
# This module is designed to be included into an Ability class. This will
# provide the "can... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/config.rb | Ruby | mit | 5,670 | develop | 3,168 | # frozen_string_literal: true
module CanCan
def self.valid_accessible_by_strategies
strategies = [:left_join]
unless does_not_support_subquery_strategy?
strategies.push(:joined_alias_exists_subquery, :joined_alias_each_rule_as_exists_subquery, :subquery)
end
strategies
end
# You can disa... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/parameter_validators.rb | Ruby | mit | 5,670 | develop | 252 | # frozen_string_literal: true
module CanCan
module ParameterValidators
def valid_attribute_param?(attribute)
attribute.nil? || attribute.is_a?(Symbol) || (attribute.is_a?(Array) && attribute.all? { |a| a.is_a?(Symbol) })
end
end
end |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/conditions_matcher.rb | Ruby | mit | 5,670 | develop | 5,110 | # frozen_string_literal: true
module CanCan
module ConditionsMatcher
# Matches the block or conditions hash
def matches_conditions?(action, subject, attribute = nil, *extra_args)
return call_block_with_all(action, subject, extra_args) if @match_all
return matches_block_conditions(subject, attribu... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/unauthorized_message_resolver.rb | Ruby | mit | 5,670 | develop | 814 | # frozen_string_literal: true
module CanCan
module UnauthorizedMessageResolver
def unauthorized_message(action, subject)
subject = subject.values.last if subject.is_a?(Hash)
keys = unauthorized_message_keys(action, subject)
variables = {}
variables[:action] = I18n.translate("actions.#{act... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/rule.rb | Ruby | mit | 5,670 | develop | 4,322 | # frozen_string_literal: true
require_relative 'conditions_matcher.rb'
require_relative 'class_matcher.rb'
require_relative 'relevant.rb'
module CanCan
# This class is used internally and should only be called through Ability.
# it holds the information about a "can" call made on Ability and provides
# helpful ... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/controller_additions.rb | Ruby | mit | 5,670 | develop | 16,040 | # frozen_string_literal: true
module CanCan
# This module is automatically included into all controllers.
# It also makes the "can?" and "cannot?" methods available to all views.
module ControllerAdditions
module ClassMethods
# Sets up a before filter which loads and authorizes the current resource. Th... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/controller_resource_name_finder.rb | Ruby | mit | 5,670 | develop | 443 | # frozen_string_literal: true
module CanCan
module ControllerResourceNameFinder
protected
def name_from_controller
@params[:controller].split('/').last.singularize
end
def namespaced_name
[namespace, name].join('/').singularize.camelize.safe_constantize || name
end
def name
... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/controller_resource_loader.rb | Ruby | mit | 5,670 | develop | 3,483 | # frozen_string_literal: true
require_relative 'controller_resource_finder.rb'
require_relative 'controller_resource_name_finder.rb'
require_relative 'controller_resource_builder.rb'
require_relative 'controller_resource_sanitizer.rb'
module CanCan
module ControllerResourceLoader
include CanCan::ControllerResour... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/sti_detector.rb | Ruby | mit | 5,670 | develop | 357 | # frozen_string_literal: true
class StiDetector
def self.sti_class?(subject)
return false unless defined?(ActiveRecord::Base)
return false unless subject.respond_to?(:descends_from_active_record?)
return false if subject == :all || subject.descends_from_active_record?
return false unless subject < Ac... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/exceptions.rb | Ruby | mit | 5,670 | develop | 2,517 | # frozen_string_literal: true
module CanCan
# A general CanCan exception
class Error < StandardError; end
# Raised when behavior is not implemented, usually used in an abstract class.
class NotImplemented < Error; end
# Raised when removed code is called, an alternative solution is provided in message.
c... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/relevant.rb | Ruby | mit | 5,670 | develop | 872 | # frozen_string_literal: true
module CanCan
module Relevant
# Matches both the action, subject, and attribute, not necessarily the conditions
def relevant?(action, subject)
subject = subject.values.first if subject.class == Hash
@match_all || (matches_action?(action) && matches_subject?(subject))... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/controller_resource.rb | Ruby | mit | 5,670 | develop | 4,226 | # frozen_string_literal: true
require_relative 'controller_resource_loader.rb'
module CanCan
# Handle the load and authorization controller logic
# so we don't clutter up all controllers with non-interface methods.
# This class is used internally, so you do not need to call methods directly on it.
class Contro... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/class_matcher.rb | Ruby | mit | 5,670 | develop | 938 | require_relative 'sti_detector'
# This class is responsible for matching classes and their subclasses as well as
# upmatching classes to their ancestors.
# This is used to generate sti connections
class SubjectClassMatcher
def self.matches_subject_class?(subjects, subject)
subjects.any? do |sub|
has_subcla... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/active_record_5_adapter.rb | Ruby | mit | 5,670 | develop | 2,206 | # frozen_string_literal: true
module CanCan
module ModelAdapters
class ActiveRecord5Adapter < ActiveRecord4Adapter
AbstractAdapter.inherited(self)
def self.for_class?(model_class)
version_greater_or_equal?('5.0.0') && model_class <= ActiveRecord::Base
end
# rails 5 is capable of... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/active_record_4_adapter.rb | Ruby | mit | 5,670 | develop | 2,173 | # frozen_string_literal: true
module CanCan
module ModelAdapters
class ActiveRecord4Adapter < ActiveRecordAdapter
AbstractAdapter.inherited(self)
class << self
def for_class?(model_class)
version_lower?('5.0.0') && model_class <= ActiveRecord::Base
end
def override... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/conditions_extractor.rb | Ruby | mit | 5,670 | develop | 2,826 | # frozen_string_literal: true
# this class is responsible of converting the hash of conditions
# in "where conditions" to generate the sql query
# it consists of a names_cache that helps calculating the next name given to the association
# it tries to reflect the behavior of ActiveRecord when generating aliases for ta... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/abstract_adapter.rb | Ruby | mit | 5,670 | develop | 2,956 | # frozen_string_literal: true
module CanCan
module ModelAdapters
class AbstractAdapter
attr_reader :model_class
def self.inherited(subclass)
@subclasses ||= []
@subclasses.insert(0, subclass)
end
def self.adapter_class(model_class)
@subclasses.detect { |subclass|... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/sti_normalizer.rb | Ruby | mit | 5,670 | develop | 1,496 | require_relative '../sti_detector'
# this class is responsible for detecting sti classes and creating new rules for the
# relevant subclasses, using the inheritance_column as a merger
module CanCan
module ModelAdapters
class StiNormalizer
class << self
def normalize(rules)
rules_cache = [... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/active_record_adapter.rb | Ruby | mit | 5,670 | develop | 8,937 | # frozen_string_literal: true
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
module CanCan
module ModelAdapters
class ActiveRecordAdapter < AbstractAdapter
def self.version_greater_or_equal?(version)
Gem::Version.new(Ac... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/conditions_normalizer.rb | Ruby | mit | 5,670 | develop | 1,741 | # this class is responsible of normalizing the hash of conditions
# by exploding has_many through associations
# when a condition is defined with an has_many through association this is exploded in all its parts
# TODO: it could identify STI and normalize it
module CanCan
module ModelAdapters
class ConditionsNorm... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/strategies/subquery.rb | Ruby | mit | 5,670 | develop | 463 | module CanCan
module ModelAdapters
class Strategies
class Subquery < Base
def execute!
build_joins_relation_subquery(where_conditions)
end
def build_joins_relation_subquery(where_conditions)
inner = model_class.unscoped do
model_class.left_joins(joins... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/strategies/base.rb | Ruby | mit | 5,670 | develop | 1,085 | module CanCan
module ModelAdapters
class Strategies
class Base
attr_reader :adapter, :relation, :where_conditions
delegate(
:compressed_rules,
:extract_multiple_conditions,
:joins,
:model_class,
:quoted_primary_key,
:quoted_aliased... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/strategies/joined_alias_exists_subquery.rb | Ruby | mit | 5,670 | develop | 916 | # frozen_string_literal: true
module CanCan
module ModelAdapters
class Strategies
class JoinedAliasExistsSubquery < Base
def execute!
model_class
.joins(
"JOIN #{quoted_table_name} AS #{quoted_aliased_table_name} ON " \
"#{quoted_aliased_table_name}... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/model_adapters/strategies/joined_alias_each_rule_as_exists_subquery.rb | Ruby | mit | 5,670 | develop | 3,027 | # frozen_string_literal: false
module CanCan
module ModelAdapters
class Strategies
class JoinedAliasEachRuleAsExistsSubquery < Base
def execute!
model_class
.joins(
"JOIN #{quoted_table_name} AS #{quoted_aliased_table_name} ON " \
"#{quoted_aliased_... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/ability/actions.rb | Ruby | mit | 5,670 | develop | 2,951 | # frozen_string_literal: true
module CanCan
module Ability
module Actions
# Alias one or more actions into another one.
#
# alias_action :update, :destroy, :to => :modify
# can :modify, Comment
#
# Then :modify permission will apply to both :update and :destroy requests.
... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/ability/rules.rb | Ruby | mit | 5,670 | develop | 3,039 | # frozen_string_literal: true
module CanCan
module Ability
module Rules
protected
# Must be protected as an ability can merge with other abilities.
# This means that an ability must expose their rules with another ability.
def rules
@rules ||= []
end
private
d... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | lib/cancan/ability/strong_parameter_support.rb | Ruby | mit | 5,670 | develop | 1,472 | # frozen_string_literal: true
module CanCan
module Ability
module StrongParameterSupport
# Returns an array of attributes suitable for use with strong parameters
#
# Note: reversing the relevant rules is important. Normal order means that 'cannot'
# rules will come before 'can' rules. How... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/matchers.rb | Ruby | mit | 5,670 | develop | 477 | # frozen_string_literal: true
RSpec::Matchers.define :orderlessly_match do |original_string|
match do |given_string|
original_string.split('').sort == given_string.split('').sort
end
failure_message do |given_string|
"expected \"#{given_string}\" to have the same characters as \"#{original_string}\""
... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/spec_helper.rb | Ruby | mit | 5,670 | develop | 1,160 | # frozen_string_literal: true
require 'rubygems'
require 'bundler/setup'
Bundler.require
require 'matchers'
require 'cancan/matchers'
# I8n setting to fix deprecation.
I18n.enforce_available_locales = false if defined?(I18n) && I18n.respond_to?('enforce_available_locales=')
# Add support to load paths
$LOAD_PATH.u... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/changelog_spec.rb | Ruby | mit | 5,670 | develop | 2,760 | # frozen_string_literal: true
# credits to https://github.com/rubocop-hq/rubocop for this CHANGELOG checker
RSpec.describe 'changelog' do
subject(:changelog) do
path = File.join(File.dirname(__FILE__), '..', 'CHANGELOG.md')
File.read(path)
end
it 'has newline at end of file' do
expect(changelog.end_... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/support/sql_helpers.rb | Ruby | mit | 5,670 | develop | 1,530 | # frozen_string_literal: true
module SQLHelpers
def normalized_sql(adapter)
adapter.database_records.to_sql.strip.squeeze(' ')
end
def sqlite?
ENV['DB'] == 'sqlite'
end
def postgres?
ENV['DB'] == 'postgres'
end
def connect_db
# ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveR... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/controller_additions_spec.rb | Ruby | mit | 5,670 | develop | 8,299 | # frozen_string_literal: true
require 'spec_helper'
describe CanCan::ControllerAdditions do
before(:each) do
@controller_class = Class.new
@controller = @controller_class.new
allow(@controller).to receive(:params) { {} }
allow(@controller).to receive(:current_user) { :current_user }
expect(@cont... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/rule_compressor_spec.rb | Ruby | mit | 5,670 | develop | 4,177 | # frozen_string_literal: true
require 'spec_helper'
describe CanCan::RulesCompressor do
before do
class Blog
end
end
def can(action, subject, args = nil)
CanCan::Rule.new(true, action, subject, args, nil)
end
def cannot(action, subject, args = nil)
CanCan::Rule.new(false, action, subject, ... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/rule_spec.rb | Ruby | mit | 5,670 | develop | 2,764 | # frozen_string_literal: true
require 'spec_helper'
require 'ostruct' # for OpenStruct below
# Most of Rule functionality is tested in Ability specs
RSpec.describe CanCan::Rule do
before(:each) do
@conditions = {}
@rule = CanCan::Rule.new(true, :read, Integer, @conditions)
end
it 'returns no associatio... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/ability_spec.rb | Ruby | mit | 5,670 | develop | 31,877 | # frozen_string_literal: true
require 'spec_helper'
describe CanCan::Ability do
before(:each) do
(@ability = double).extend(CanCan::Ability)
connect_db
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
create_table(:named_users) do |t|
t.string :first_name
... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/matchers_spec.rb | Ruby | mit | 5,670 | develop | 1,993 | # frozen_string_literal: true
require 'spec_helper'
describe 'be_able_to' do
subject { double }
context 'check single ability' do
it 'delegates to can?' do
is_expected.to receive(:can?).with(:read, 123) { true }
is_expected.to be_able_to(:read, 123)
end
it 'reports a nice failure message... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/controller_resource_spec.rb | Ruby | mit | 5,670 | develop | 29,290 | # frozen_string_literal: true
require 'spec_helper'
describe CanCan::ControllerResource do
let(:ability) { Ability.new(nil) }
let(:params) { HashWithIndifferentAccess.new(controller: 'models') }
let(:controller_class) { Class.new }
let(:controller) { controller_class.new }
before(:each) do
class Model
... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/exceptions_spec.rb | Ruby | mit | 5,670 | develop | 2,245 | # frozen_string_literal: true
require 'spec_helper'
describe CanCan::AccessDenied do
describe 'with action, subject, and conditions' do
before(:each) do
@exception = CanCan::AccessDenied.new(nil, :some_action, :some_subject, :some_conditions)
end
it 'has action, subject, and conditions accessors'... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/model_adapters/default_adapter_spec.rb | Ruby | mit | 5,670 | develop | 273 | # frozen_string_literal: true
require 'spec_helper'
describe CanCan::ModelAdapters::DefaultAdapter do
it 'is default for generic classes' do
expect(CanCan::ModelAdapters::AbstractAdapter.adapter_class(Object)).to eq(CanCan::ModelAdapters::DefaultAdapter)
end
end |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/model_adapters/active_record_4_adapter_spec.rb | Ruby | mit | 5,670 | develop | 5,682 | # frozen_string_literal: true
require 'spec_helper'
if CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0')
describe CanCan::ModelAdapters::ActiveRecord4Adapter do
# only the `left_join` strategy works in AR4
CanCan.valid_accessible_by_strategies.each do |strategy|
context "with sqlite3 ... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/model_adapters/active_record_5_adapter_spec.rb | Ruby | mit | 5,670 | develop | 5,674 | # frozen_string_literal: true
require 'spec_helper'
if CanCan::ModelAdapters::ActiveRecordAdapter.version_greater_or_equal?('5.0.0')
describe CanCan::ModelAdapters::ActiveRecord5Adapter do
CanCan.valid_accessible_by_strategies.each do |strategy|
context "with sqlite3 and #{strategy} strategy" do
b... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/model_adapters/conditions_extractor_spec.rb | Ruby | mit | 5,670 | develop | 5,066 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe CanCan::ModelAdapters::ConditionsExtractor do
before do
connect_db
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
create_table(:categories) do |t|
t.string :name
t.boolean :visible
t.... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/model_adapters/has_and_belongs_to_many_spec.rb | Ruby | mit | 5,670 | develop | 5,787 | require 'spec_helper'
RSpec.describe CanCan::ModelAdapters::ActiveRecord5Adapter do
let(:ability) { double.extend(CanCan::Ability) }
let(:users_table) { User.table_name }
let(:posts_table) { Post.table_name }
before :all do
connect_db
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.d... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/model_adapters/accessible_by_integration_spec.rb | Ruby | mit | 5,670 | develop | 2,760 | # frozen_string_literal: true
require 'spec_helper'
# integration tests for latest ActiveRecord version.
RSpec.describe CanCan::ModelAdapters::ActiveRecord5Adapter do
let(:ability) { double.extend(CanCan::Ability) }
let(:users_table) { Post.table_name }
let(:posts_table) { Post.table_name }
let(:likes_table) ... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/model_adapters/accessible_by_has_many_through_spec.rb | Ruby | mit | 5,670 | develop | 4,061 | require 'spec_helper'
# integration tests for latest ActiveRecord version.
RSpec.describe CanCan::ModelAdapters::ActiveRecord5Adapter do
let(:ability) { double.extend(CanCan::Ability) }
let(:users_table) { Post.table_name }
let(:posts_table) { Post.table_name }
let(:likes_table) { Like.table_name }
before :e... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/model_adapters/active_record_adapter_spec.rb | Ruby | mit | 5,670 | develop | 57,732 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe CanCan::ModelAdapters::ActiveRecordAdapter do
let(:true_v) do
ActiveRecord::Base.connection.quoted_true
end
let(:false_v) do
ActiveRecord::Base.connection.quoted_false
end
let(:false_condition) { "#{true_v}=#{false_v}" }
before :... |
github | CanCanCommunity/cancancan | https://github.com/CanCanCommunity/cancancan | spec/cancan/model_adapters/conditions_normalizer_spec.rb | Ruby | mit | 5,670 | develop | 3,081 | require 'spec_helper'
RSpec.describe CanCan::ModelAdapters::ConditionsNormalizer do
before do
connect_db
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
create_table(:articles) do |t|
end
create_table(:users) do |t|
t.string :name
end
create_... |
github | danger/danger | https://github.com/danger/danger | danger.gemspec | Ruby | mit | 5,659 | master | 1,534 | # frozen_string_literal: true
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "danger/version"
Gem::Specification.new do |spec|
spec.name = "danger"
spec.version = Danger::VERSION
spec.authors = ["Orta Therox", "Juanito Fatas"]
spec.em... |
github | danger/danger | https://github.com/danger/danger | Guardfile | Ruby | mit | 5,659 | master | 633 | # frozen_string_literal: true
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
# To run, use `guard`.
group :red_green_refactor, halt_on_fail: true do
guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
# Feel free to open issu... |
github | danger/danger | https://github.com/danger/danger | Gemfile | Ruby | mit | 5,659 | master | 552 | # frozen_string_literal: true
source "https://rubygems.org"
gemspec
gem "bundler"
gem "chandler"
gem "danger-gitlab"
gem "danger-junit", "~> 0.5"
gem "faraday-http-cache", "~> 2.5"
gem "fuubar", "~> 2.5"
gem "guard", "~> 2.16"
gem "guard-rspec", "~> 4.7"
gem "guard-rubocop", "~> 1.2"
gem "listen", "3.0.7"
gem "pry",... |
github | danger/danger | https://github.com/danger/danger | Rakefile | Ruby | mit | 5,659 | master | 1,430 | # frozen_string_literal: true
begin
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:specs)
require "rubocop/rake_task"
RuboCop::RakeTask.new
rescue LoadError
puts "Please use `bundle exec` to get all the rake commands"
end
task default: %w(rubocop spec)
desc "Danger'... |
github | danger/danger | https://github.com/danger/danger | Dangerfile | Ruby | mit | 5,659 | master | 2,702 | # frozen_string_literal: true
# Sometimes its a README fix, or something like that - which isn't relevant for
# including in a CHANGELOG for example
has_app_changes = !git.modified_files.grep(/lib/).empty?
has_test_changes = !git.modified_files.grep(/spec/).empty?
is_version_bump = git.modified_files.sort == ["CHANGEL... |
github | danger/danger | https://github.com/danger/danger | danger_plugins/protect_files.rb | Ruby | mit | 5,659 | master | 416 | # frozen_string_literal: true
module Danger
class Files < Plugin
def protect_files(path: nil, message: nil, fail_build: true)
raise "You have to provide a message" if message.to_s.empty?
raise "You have to provide a path" if path.to_s.empty?
broken_rule = git.modified_files.include?(path)
... |
github | danger/danger | https://github.com/danger/danger | lib/danger.rb | Ruby | mit | 5,659 | master | 1,224 | # frozen_string_literal: true
require "danger/version"
require "danger/danger_core/dangerfile"
require "danger/danger_core/environment_manager"
require "danger/commands/runner"
require "danger/plugin_support/plugin"
require "danger/core_ext/string"
require "danger/danger_core/executor"
require "claide"
require "color... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/local_only_git_repo.rb | Ruby | mit | 5,659 | master | 1,189 | # frozen_string_literal: true
require "git"
require "danger/request_sources/local_only"
module Danger
# ### CI Setup
#
# For setting up LocalOnlyGitRepo there is not much needed. Either `--base` and `--head` need to be specified or
# origin/master is expected for base and HEAD for head
#
class LocalOnlyGi... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/appcenter.rb | Ruby | mit | 5,659 | master | 1,647 | # frozen_string_literal: true
# https://docs.microsoft.com/en-us/appcenter/build/custom/variables/
require "uri"
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# Add a script step to your appcenter-post-build.sh:
#
# ```shell
# #!/usr/bin/env bash
# bundle install
# ... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/codemagic.rb | Ruby | mit | 5,659 | master | 1,649 | # frozen_string_literal: true
# https://docs.codemagic.io/building/environment-variables/
module Danger
# ### CI Setup
#
# Add a script step to your workflow:
#
# ```
# - name: Running Danger
# script: |
# bundle install
# bundle exec danger
# ```
#
# ### Token Setup
#
# Add the ... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/circle_api.rb | Ruby | mit | 5,659 | master | 1,695 | # frozen_string_literal: true
require "faraday"
module Danger
class CircleAPI
# Determine if there's a PR attached to this commit,
# and return a bool
def pull_request?(env)
url = pull_request_url(env)
return !url.nil?
end
# Determine if there's a PR attached to this commit,
# a... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/custom_ci_with_github.rb | Ruby | mit | 5,659 | master | 1,573 | # frozen_string_literal: true
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# Custom CI with GitHub
#
# This CI source is for custom, most likely internal, CI systems that are use GitHub as source control.
# An example could be argo-workflows or tekton hosted in your own Ku... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/circle.rb | Ruby | mit | 5,659 | master | 3,961 | # frozen_string_literal: true
# https://circleci.com/docs/environment-variables
require "uri"
require "danger/ci_source/circle_api"
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# For setting up CircleCI, we recommend turning on "Only build pull requests" in "Advanced Settings." ... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/travis.rb | Ruby | mit | 5,659 | master | 2,039 | # frozen_string_literal: true
# http://docs.travis-ci.com/user/osx-ci-environment/
# http://docs.travis-ci.com/user/environment-variables/
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
# You need to edit your `.travis.yml` to include `bundle exec danger`. If you already have
# a `s... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/codeship.rb | Ruby | mit | 5,659 | master | 1,334 | # frozen_string_literal: true
# https://semaphoreci.com/docs/available-environment-variables.html
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# In Codeship, go to your "Project Settings", then add `bundle exec danger` as a test step inside
# one of your pipelines.
#
# ###... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/appveyor.rb | Ruby | mit | 5,659 | master | 1,881 | # frozen_string_literal: true
# https://www.appveyor.com/docs/build-configuration/
module Danger
# ### CI Setup
#
# Install dependencies and add a danger step to your `appveyor.yml`.
#
# ```yaml
# install:
# - cmd: >-
# set PATH=C:\Ruby25-x64\bin;%PATH%
#
# bundle install
# after_test:
... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/concourse.rb | Ruby | mit | 5,659 | master | 1,943 | # frozen_string_literal: true
require "git"
require "danger/request_sources/local_only"
module Danger
# Concourse CI Integration
#
# https://concourse-ci.org/
#
# ### CI Setup
#
# With Concourse, you run the docker images yourself, so you will want to add `yarn danger ci` within one of your build jobs.
... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/bitbucket_pipelines.rb | Ruby | mit | 5,659 | master | 2,196 | # frozen_string_literal: true
module Danger
# ### CI Setup
#
# Install dependencies and add a danger step to your `bitbucket-pipelines.yml`.
#
# ```yaml
# script:
# - bundle exec danger --verbose
# ```
#
# ### Token Setup
#
# For username and password, you need to set.
#
# - `DANGER_B... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/surf.rb | Ruby | mit | 5,659 | master | 1,062 | # frozen_string_literal: true
# http://github.com/surf-build/surf
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# You want to add `bundle exec danger` to your `build.sh` file to run Danger at the
# end of your build.
#
# ### Token Setup
#
# As this is self-hosted, you ... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/local_git_repo.rb | Ruby | mit | 5,659 | master | 3,315 | # frozen_string_literal: true
# For more info see: https://github.com/schacon/ruby-git
require "git"
require "uri"
require "danger/request_sources/github/github"
require "danger/ci_source/support/find_repo_info_from_url"
require "danger/ci_source/support/find_repo_info_from_logs"
require "danger/ci_source/support/n... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/ci_source.rb | Ruby | mit | 5,659 | master | 962 | # frozen_string_literal: true
require "set"
module Danger
# "abstract" CI class
class CI
attr_accessor :repo_slug, :pull_request_id, :repo_url, :supported_request_sources
def self.inherited(child_class)
available_ci_sources.add child_class
super
end
def self.available_ci_sources
... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/bamboo.rb | Ruby | mit | 5,659 | master | 1,450 | # frozen_string_literal: true
require "set"
module Danger
# ### CI Setup
#
# Add a Run Script task that executes `danger` (or `bundle exec danger` if you're using Bundler
# to manage your gems) as your as part of your Bamboo plan.
# The minimum supported version is Bamboo 6.9.
#
# ### Token Setup
#
... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/buddybuild.rb | Ruby | mit | 5,659 | master | 2,299 | # frozen_string_literal: true
module Danger
# ### CI Setup
#
# Read how you can setup Danger on the buddybuild blog:
# https://www.buddybuild.com/blog/using-danger-with-buddybuild/
#
# ### Token Setup
#
# Login to buddybuild and select your app. Go to your *App Settings* and
# in the *Build Settings*... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/buildkite.rb | Ruby | mit | 5,659 | master | 1,827 | # frozen_string_literal: true
# https://buildkite.com/docs/agent/osx
# https://buildkite.com/docs/guides/environment-variables
require "danger/request_sources/github/github"
require "danger/request_sources/gitlab"
module Danger
# ### CI Setup
#
# With BuildKite you run the server yourself, so you will want to r... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/cirrus.rb | Ruby | mit | 5,659 | master | 1,040 | # frozen_string_literal: true
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
# You need to edit your `.cirrus.yml` to include `bundler exec danger`.
#
# Adding this to your `.cirrus.yml` allows Danger to fail your build, both on the Cirrus CI website and within your Pull Request.
... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/xcode_cloud.rb | Ruby | mit | 5,659 | master | 1,360 | # frozen_string_literal: true
module Danger
# ### CI Setup
#
# In order to work with Xcode Cloud and Danger, you will need to add `bundle exec danger` to
# the `ci_scripts/ci_post_xcodebuild.sh` (Xcode Cloud's expected filename for a post-action build script).
# More details and documentation on Xcode Cloud ... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/semaphore.rb | Ruby | mit | 5,659 | master | 1,346 | # frozen_string_literal: true
# https://docs.semaphoreci.com/article/12-environment-variables
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# For Semaphore you will want to go to the settings page of the project. Inside "Build Settings"
# you should add `bundle exec danger` to ... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/azure_pipelines.rb | Ruby | mit | 5,659 | master | 2,426 | # frozen_string_literal: true
# https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables
require "uri"
require "danger/request_sources/github/github"
require "danger/request_sources/vsts"
module Danger
# ### CI Setup
#
# Add a script step:
#
# ```shell
# #!/usr/bin/env bash
# bundle i... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/jenkins.rb | Ruby | mit | 5,659 | master | 5,186 | # frozen_string_literal: true
# https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-JenkinsSetEnvironmentVariables
# https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin
require "danger/request_sources/github/github"
require "danger/request_sources... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/appcircle.rb | Ruby | mit | 5,659 | master | 2,659 | # frozen_string_literal: true
# https://docs.appcircle.io/environment-variables/managing-variables
# https://docs.appcircle.io/build/build-profile-configuration#environment-variables-configuration
require "danger/request_sources/github/github"
require "danger/request_sources/gitlab"
module Danger
# ### CI Setup
#
... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/code_build.rb | Ruby | mit | 5,659 | master | 2,690 | # frozen_string_literal: true
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# In CodeBuild, make sure to correctly forward `CODEBUILD_BUILD_ID`, `CODEBUILD_SOURCE_VERSION`, `CODEBUILD_SOURCE_REPO... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/github_actions.rb | Ruby | mit | 5,659 | master | 1,383 | # frozen_string_literal: true
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# You can use `danger/danger` Action in your `.github/workflows/xxx.yml`.
# And so, you can use GITHUB_TOKEN secret as `DANGER_GITHUB_API_TOKEN` environment variable.
#
# ```yml
# ...
# ste... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/gitlab_ci.rb | Ruby | mit | 5,659 | master | 3,094 | # frozen_string_literal: true
# http://docs.gitlab.com/ce/ci/variables/README.html
require "uri"
require "danger/request_sources/github/github"
require "danger/request_sources/gitlab"
module Danger
# ### CI Setup
#
# Install dependencies and add a danger step to your .gitlab-ci.yml:
#
# ```yml
# before_sc... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/teamcity.rb | Ruby | mit | 5,659 | master | 6,952 | # frozen_string_literal: true
# https://www.jetbrains.com/teamcity/
require "danger/request_sources/github/github"
require "danger/request_sources/gitlab"
module Danger
# ### CI Setup
#
# You need to go to your project settings. Then depending on the type of your build settings, you may need
# to add a new bu... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/xcode_server.rb | Ruby | mit | 5,659 | master | 1,836 | # frozen_string_literal: true
# Following the advice from @czechboy0 https://github.com/danger/danger/issues/171
# https://github.com/czechboy0/Buildasaur
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# If you're bold enough to use Xcode Bots. You will need to use [Buildasaur](ht... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/codefresh.rb | Ruby | mit | 5,659 | master | 1,438 | # frozen_string_literal: true
# https://semaphoreci.com/docs/available-environment-variables.html
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# To set up Danger on Codefresh, create a freestyle step in your Codefresh yaml configuration:
#
# ```yml
# Danger:
# tit... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/screwdriver.rb | Ruby | mit | 5,659 | master | 1,368 | # frozen_string_literal: true
# http://screwdriver.cd
# https://docs.screwdriver.cd/user-guide/environment-variables
require "danger/request_sources/github/github"
module Danger
# ### CI Setup
#
# Install dependencies and add a danger step to your screwdriver.yaml:
#
# ```yml
# jobs:
# danger:
# ... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/drone.rb | Ruby | mit | 5,659 | master | 2,047 | # frozen_string_literal: true
# http://readme.drone.io/usage/variables/
require "danger/request_sources/github/github"
require "danger/request_sources/gitlab"
module Danger
# ### CI Setup
#
# With Drone you run the docker images yourself, so you will want to add `bundle exec danger` at the end of
# your `.dro... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/dotci.rb | Ruby | mit | 5,659 | master | 1,423 | # frozen_string_literal: true
require "danger/request_sources/github/github"
module Danger
# https://groupon.github.io/DotCi
# ### CI Setup
# DotCi is a layer on top of jenkins. So, if you're using DotCi, you're hosting your own environment.
#
# ### Token Setup
#
# #### GitHub
# As you own the machin... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/bitrise.rb | Ruby | mit | 5,659 | master | 2,640 | # frozen_string_literal: true
# http://devcenter.bitrise.io/docs/available-environment-variables
require "danger/request_sources/github/github"
require "danger/request_sources/gitlab"
module Danger
# ### CI Setup
#
# Add a script step to your workflow:
#
# ```yml
# - script@1.1.2:
# inputs:
# -... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/support/find_repo_info_from_url.rb | Ruby | mit | 5,659 | master | 1,076 | # frozen_string_literal: true
require "danger/ci_source/support/repo_info"
module Danger
class FindRepoInfoFromURL
REGEXP = %r{
://[^/]+/
(([^/]+/){1,2}_git/)?
(?<slug>[^/]+(/[^/]+){0,2})
(/(pull|pullrequest|merge_requests|pull-requests)/)
(?<id>\d+)
}x.freeze
# Regex used... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/support/pull_request_finder.rb | Ruby | mit | 5,659 | master | 8,037 | # frozen_string_literal: true
require "danger/ci_source/support/local_pull_request"
require "danger/ci_source/support/remote_pull_request"
require "danger/ci_source/support/no_pull_request"
module Danger
class PullRequestFinder
def initialize(specific_pull_request_id, repo_slug = nil, remote: false, git_logs: "... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/support/find_repo_info_from_logs.rb | Ruby | mit | 5,659 | master | 680 | # frozen_string_literal: true
require "danger/ci_source/support/repo_info"
module Danger
class FindRepoInfoFromLogs
def initialize(github_host, remote_logs)
@github_host = github_host
@remote_logs = remote_logs
end
def call
matched = remote.match(regexp)
if matched
Repo... |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/support/commits.rb | Ruby | mit | 5,659 | master | 283 | # frozen_string_literal: true
module Danger
class Commits
def initialize(base_head)
@base_head = base_head.strip.split(" ")
end
def base
base_head.first
end
def head
base_head.last
end
private
attr_reader :base_head
end
end |
github | danger/danger | https://github.com/danger/danger | lib/danger/ci_source/support/local_pull_request.rb | Ruby | mit | 5,659 | master | 312 | # frozen_string_literal: true
module Danger
class LocalPullRequest
attr_reader :pull_request_id, :sha
def initialize(log_line)
@pull_request_id = log_line.match(/#(?<id>[0-9]+)/)[:id]
@sha = log_line.split(" ").first
end
def valid?
pull_request_id && sha
end
end
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.