repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/missing_archive_number.rb | test/fixtures/missing_archive_number.rb | # name - string
# archived_at - datetime
class MissingArchiveNumber < ActiveRecord::Base
acts_as_archival
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/poly.rb | test/fixtures/poly.rb | # archiveable_id - integer
# archiveable_type - string
# archive_number - string
# archived_at - datetime
class Poly < ActiveRecord::Base
acts_as_archival
belongs_to :archiveable, polymorphic: true
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/missing_archived_at.rb | test/fixtures/missing_archived_at.rb | # name - string
# archive_number - string
class MissingArchivedAt < ActiveRecord::Base
acts_as_archival
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/application_record.rb | test/fixtures/application_record.rb | class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/archival_table_name.rb | test/fixtures/archival_table_name.rb | # name - string
# archive_number - string
# archived_at - datetime
class ArchivalTableName < ActiveRecord::Base
self.table_name = "legacy"
acts_as_archival
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/exploder.rb | test/fixtures/exploder.rb | # archival_id - integer
# archive_number - string
# archived_at - datetime
class Exploder < ActiveRecord::Base
acts_as_archival
belongs_to :archival
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/another_polys_holder.rb | test/fixtures/another_polys_holder.rb | # name - string
# archival_id - integer
# archive_number - string
# archived_at - datetime
class AnotherPolysHolder < ActiveRecord::Base
acts_as_archival
has_many :polys, dependent: :destroy, as: :archiveable
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/test/fixtures/archival_kid.rb | test/fixtures/archival_kid.rb | # archival_id - integer
# archive_number - string
# archived_at - datetime
class ArchivalKid < ActiveRecord::Base
acts_as_archival
belongs_to :archival
has_many :archival_grandkids, dependent: :destroy
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/lib/acts_as_archival.rb | lib/acts_as_archival.rb | require "acts_as_archival/version"
require "expected_behavior/association_operation/base"
require "expected_behavior/association_operation/archive"
require "expected_behavior/association_operation/unarchive"
require "expected_behavior/acts_as_archival"
require "expected_behavior/acts_as_archival_active_record_methods"
# This assumes a fully Rails 5 compatible set of ActiveRecord models
if defined?(ApplicationRecord)
ApplicationRecord.send :include, ExpectedBehavior::ActsAsArchival
ApplicationRecord.send :include, ExpectedBehavior::ActsAsArchivalActiveRecordMethods
else
ActiveRecord::Base.send :include, ExpectedBehavior::ActsAsArchival
ActiveRecord::Base.send :include, ExpectedBehavior::ActsAsArchivalActiveRecordMethods
end
ActiveRecord::Relation.send :include, ExpectedBehavior::ActsAsArchivalActiveRecordMethods::ARRelationMethods
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/lib/acts_as_archival/version.rb | lib/acts_as_archival/version.rb | module ActsAsArchival
VERSION = "2.1.0".freeze
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/lib/expected_behavior/acts_as_archival_active_record_methods.rb | lib/expected_behavior/acts_as_archival_active_record_methods.rb | module ExpectedBehavior
module ActsAsArchivalActiveRecordMethods
def self.included(base)
base.extend ARClassMethods
base.send :include, ARInstanceMethods
end
module ARClassMethods
def archival?
included_modules.include?(ExpectedBehavior::ActsAsArchival::InstanceMethods)
end
end
module ARInstanceMethods
def archival?
self.class.archival?
end
end
module ARRelationMethods
def archive_all!
error_message = "The #{klass} must implement 'act_on_archivals' in order to call `archive_all!`"
raise NotImplementedError.new(error_message) unless archival?
head_archive_number = Digest::MD5.hexdigest("#{klass}#{Time.now.utc.to_i}")
each { |record| record.archive!(head_archive_number) }.tap { reset }
end
def unarchive_all!
error_message = "The #{klass} must implement 'act_on_archivals' in order to call `unarchive_all!`"
raise NotImplementedError.new(error_message) unless archival?
each(&:unarchive!).tap { reset }
end
end
end
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/lib/expected_behavior/acts_as_archival.rb | lib/expected_behavior/acts_as_archival.rb | module ExpectedBehavior
module ActsAsArchival
require "digest/md5"
unless defined?(MissingArchivalColumnError) == "constant" && MissingArchivalColumnError.instance_of?(Class)
MissingArchivalColumnError = Class.new(ActiveRecord::ActiveRecordError)
end
unless defined?(CouldNotArchiveError) == "constant" && CouldNotArchiveError.instance_of?(Class)
CouldNotArchiveError = Class.new(ActiveRecord::ActiveRecordError)
end
unless defined?(CouldNotUnarchiveError) == "constant" && CouldNotUnarchiveError.instance_of?(Class)
CouldNotUnarchiveError = Class.new(ActiveRecord::ActiveRecordError)
end
def self.included(base)
base.extend ActMethods
end
module ActMethods
def acts_as_archival(options = {})
return if included_modules.include?(InstanceMethods)
include InstanceMethods
setup_validations(options)
setup_scopes
setup_callbacks
end
private def setup_validations(options)
before_validation :raise_if_not_archival
validate :readonly_when_archived if options[:readonly_when_archived]
end
private def setup_scopes
scope :archived, -> { where.not(archived_at: nil).where.not(archive_number: nil) }
scope :unarchived, -> { where(archived_at: nil, archive_number: nil) }
scope :archived_from_archive_number, (lambda do |head_archive_number|
where(["archived_at IS NOT NULL AND archive_number = ?", head_archive_number])
end)
end
private def setup_callbacks
callbackable_actions = %w[archive unarchive]
setup_activerecord_callbacks(callbackable_actions)
define_callback_dsl_methods(callbackable_actions)
end
private def setup_activerecord_callbacks(callbackable_actions)
define_callbacks(*[callbackable_actions].flatten)
end
private def define_callback_dsl_methods(callbackable_actions)
callbackable_actions.each do |action|
%w[before after].each do |callbackable_type|
define_callback_dsl_method(callbackable_type, action)
end
end
end
private def define_callback_dsl_method(callbackable_type, action)
# rubocop:disable Security/Eval
# rubocop:disable Style/DocumentDynamicEvalDefinition
eval <<-end_callbacks
unless defined?(#{callbackable_type}_#{action})
def #{callbackable_type}_#{action}(*args, &blk)
set_callback(:#{action}, :#{callbackable_type}, *args, &blk)
end
end
end_callbacks
# rubocop:enable Style/DocumentDynamicEvalDefinition
# rubocop:enable Security/Eval
end
end
module InstanceMethods
def readonly_when_archived
readonly_attributes_changed = archived? && changed? && !archived_at_changed? && !archive_number_changed?
return unless readonly_attributes_changed
errors.add(:base, "Cannot modify an archived record.")
end
def raise_if_not_archival
missing_columns = []
missing_columns << "archive_number" unless respond_to?(:archive_number)
missing_columns << "archived_at" unless respond_to?(:archived_at)
return if missing_columns.blank?
raise MissingArchivalColumnError.new("Add '#{missing_columns.join "', '"}' column(s) to '#{self.class.name}' to make it archival")
end
def archived?
!!(archived_at? && archive_number)
end
def archive!(head_archive_number = nil)
execute_archival_action(:archive) do
unless archived?
head_archive_number ||= Digest::MD5.hexdigest("#{self.class.name}#{id}")
archive_associations(head_archive_number)
self.archived_at = DateTime.now
self.archive_number = head_archive_number
save!
end
end
end
def unarchive!(head_archive_number = nil)
execute_archival_action(:unarchive) do
if archived?
head_archive_number ||= archive_number
self.archived_at = nil
self.archive_number = nil
save!
unarchive_associations(head_archive_number)
end
end
end
def archive_associations(head_archive_number)
AssociationOperation::Archive.new(self, head_archive_number).execute
end
def unarchive_associations(head_archive_number)
AssociationOperation::Unarchive.new(self, head_archive_number).execute
end
private def execute_archival_action(action, &block)
result = false
self.class.transaction do
result = !!run_callbacks(action, &block)
rescue => e
handle_archival_action_exception(e)
end
result
end
private def handle_archival_action_exception(exception)
ActiveRecord::Base.logger.try(:debug, exception.message)
ActiveRecord::Base.logger.try(:debug, exception.backtrace)
raise ActiveRecord::Rollback
end
end
end
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/lib/expected_behavior/association_operation/base.rb | lib/expected_behavior/association_operation/base.rb | module ExpectedBehavior
module ActsAsArchival
module AssociationOperation
class Base
attr_reader :model, :head_archive_number
def initialize(model, head_archive_number)
@model = model
@head_archive_number = head_archive_number
end
def execute
each_archivable_association do |association|
act_on_association(association) if association_conditions_met? association
end
end
protected
def each_archivable_association
model.class.reflect_on_all_associations.each do |association|
yield(association) if archivable_association?(association)
end
end
def archivable_association?(association)
association.macro.to_s =~ /^has/ &&
association.klass.archival? &&
association.options[:through].nil?
end
def association_conditions_met?(_association)
true
end
def act_on_association(association)
key = association.respond_to?(:foreign_key) ? association.foreign_key : association.primary_key_name
scope_conditions = { key => model.id }
# polymorphic associations need a type so we don't accidentally act on multiple associated objects
# that have the same ID
scope_conditions[association.type] = model.class.base_class.name if association.type
scope = association.klass.where(scope_conditions)
act_on_archivals(scope)
end
def act_on_archivals(_scope)
raise NotImplementedError.new("The #{self.class} hasn't implemented 'act_on_archivals(scope)'")
end
end
end
end
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/lib/expected_behavior/association_operation/unarchive.rb | lib/expected_behavior/association_operation/unarchive.rb | module ExpectedBehavior
module ActsAsArchival
module AssociationOperation
class Unarchive < Base
protected
def act_on_archivals(scope)
scope.archived.where(archive_number: head_archive_number).find_each do |related_record|
raise ActiveRecord::Rollback unless related_record.unarchive!(head_archive_number)
end
end
end
end
end
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
expectedbehavior/acts_as_archival | https://github.com/expectedbehavior/acts_as_archival/blob/65a6f284884d49cfbf1276602178fdae5982a09f/lib/expected_behavior/association_operation/archive.rb | lib/expected_behavior/association_operation/archive.rb | module ExpectedBehavior
module ActsAsArchival
module AssociationOperation
class Archive < Base
protected
def act_on_archivals(archivals)
archivals.unarchived.find_each do |related_record|
raise ActiveRecord::Rollback unless related_record.archive!(head_archive_number)
end
end
def association_conditions_met?(association)
association.options[:dependent] == :destroy
end
end
end
end
end
| ruby | MIT | 65a6f284884d49cfbf1276602178fdae5982a09f | 2026-01-04T17:51:12.709644Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/spec/spec_helper.rb | spec/spec_helper.rb | require "rack/builder"
require "rack/json_schema"
require "rack/test"
require "rspec/json_matcher"
RSpec.configure do |config|
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.include RSpec::JsonMatcher
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/spec/rack/spec_spec.rb | spec/rack/spec_spec.rb | require "spec_helper"
describe Rack::JsonSchema do
include Rack::Test::Methods
let(:app) do
local_schema = schema
local_ignore_invalid_content_type = ignore_invalid_content_type
local_ignore_missing_path = ignore_missing_path
local_response_body = response_body
local_response_headers = response_headers
Rack::Builder.app do
use Rack::JsonSchema::ErrorHandler
use Rack::JsonSchema::RequestValidation, ignore_invalid_content_type: local_ignore_invalid_content_type, ignore_missing_path: local_ignore_missing_path, schema: local_schema
use Rack::JsonSchema::ResponseValidation, schema: local_schema
run ->(env) do
[200, local_response_headers, [local_response_body]]
end
end
end
let(:response_headers) do
{ "Content-Type" => "application/json" }
end
let(:response_body) do
if verb == :get
[response_data].to_json
else
response_data.to_json
end
end
let(:response_data) do
{
id: "01234567-89ab-cdef-0123-456789abcdef",
name: "example",
}
end
let(:schema) do
str = File.read(schema_path)
JSON.parse(str)
end
let(:schema_path) do
File.expand_path("../../fixtures/schema.json", __FILE__)
end
let(:ignore_invalid_content_type) do
false
end
let(:ignore_missing_path) do
false
end
let(:response) do
last_response
end
let(:env) do
{}
end
let(:params) do
{}
end
subject do
send(verb, path, params, env)
response.status
end
shared_context "with valid POST request", :with_valid_post_request do
before do
env["CONTENT_TYPE"] = "application/json"
end
let(:verb) do
:post
end
let(:path) do
"/apps"
end
let(:params) do
{ name: "abcd" }.to_json
end
end
describe "RequestValidation" do
let(:verb) do
:get
end
let(:path) do
"/apps"
end
shared_context "with undefined route" do
let(:path) do
"/undefined"
end
end
context "with defined route" do
it { should == 200 }
end
context "with undefined route" do
include_context "with undefined route"
it "returns link_not_found error" do
should == 404
expect(response.body).to be_json_as(
id: "link_not_found",
message: "Could not find the link definition for request path #{path}.",
)
end
end
context "with undefined route and ignore_missing_path option" do
include_context "with undefined route"
let(:ignore_missing_path) do
true
end
it { should == 200 }
end
context "with request body & invalid content type", :with_valid_post_request do
before do
env["CONTENT_TYPE"] = "text/plain"
end
it "returns invalid_content_type error" do
should == 400
expect(response.body).to be_json_as(
id: "invalid_content_type",
message: "Invalid content type",
)
end
end
context "with request body & invalid content type and ignore_invalid_content_type option" do
let(:ignore_invalid_content_type) do
true
end
it "skips content_type check" do
should == 200
end
end
context "with Array request body", :with_valid_post_request do
let(:params) do
[].to_json
end
it { should == 400 }
end
context "with valid request property", :with_valid_post_request do
it { should == 200 }
end
context "with suffixed content type", :with_valid_post_request do
before do
env["CONTENT_TYPE"] = "application/json; charset=utf8"
end
it { should == 200 }
end
context "with invalid request property", :with_valid_post_request do
let(:params) do
{ name: "ab" }.to_json
end
it "returns invalid_parameter error" do
should == 400
expect(response.body).to be_json_as(
id: "invalid_parameter",
message: String,
)
end
end
context "with non-json content type with non-json request body", :with_valid_post_request do
let(:path) do
"/apps/#{app_id}/files"
end
let(:app_id) do
1
end
let(:params) do
{ file: Rack::Test::UploadedFile.new(schema_path, 'text/x-yaml') }
end
before do
env["CONTENT_TYPE"] = "multipart/form-data"
end
it { should == 200 }
end
context "with malformed JSON request body", :with_valid_post_request do
let(:params) do
"malformed"
end
it "returns invalid_parameter error" do
should == 400
expect(response.body).to be_json_as(
id: "invalid_json",
message: "Request body wasn't valid JSON",
)
end
end
end
describe "ResponseValidation" do
let(:verb) do
:get
end
let(:path) do
"/apps"
end
let(:body) do
{
foo: "bar",
}.to_json
end
context "with response content type except for JSON" do
let(:response_headers) do
{ "Content-Type" => "text/plain" }
end
context "when mediaType is specified as text/plain" do
let(:path) do
"/apps/#{response_data[:id]}/text"
end
it { should == 200 }
end
context "when mediaType is not specified" do
it "returns invalid_response_content_type error" do
should == 500
expect(response.body).to be_json_as(
id: "invalid_response_content_type",
message: "Response Content-Type wasn't for JSON",
)
end
end
end
context "without required field" do
before do
response_data.delete(:id)
end
it "returns invalid_response_type error" do
should == 500
expect(response.body).to be_json_as(
id: "invalid_response_type",
message: String,
)
end
end
context "with invalid pattern string field" do
before do
response_data[:id] = "123"
end
it "returns invalid_response_type error" do
should == 500
expect(response.body).to be_json_as(
id: "invalid_response_type",
message: String,
)
end
end
context "with response content type for JSON" do
let(:response_headers) do
{ "Content-Type" => "application/json; charset=utf-8" }
end
it { should == 200 }
end
context "with empty response body without JSON Content-Type" do
let(:response_body) do
""
end
let(:response_headers) do
{}
end
it { should == 200 }
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/spec/rack/spec/mock_spec.rb | spec/rack/spec/mock_spec.rb | require "spec_helper"
describe Rack::JsonSchema::Mock do
include Rack::Test::Methods
let(:app) do
local_schema = schema
Rack::Builder.app do
use Rack::JsonSchema::ErrorHandler
use Rack::JsonSchema::Mock, schema: local_schema
run ->(env) do
[
200,
{},
["dummy"],
]
end
end
end
let(:schema) do
str = File.read(schema_path)
JSON.parse(str)
end
let(:schema_path) do
File.expand_path("../../../fixtures/schema.json", __FILE__)
end
let(:response) do
last_response
end
let(:env) do
{}
end
let(:params) do
{}
end
subject do
send(verb, path, params, env)
response.status
end
describe "#call" do
context "with list API" do
let(:verb) do
:get
end
let(:path) do
"/apps"
end
it "returns Array dummy response" do
should == 200
expect(response.body).to be_json_as(
[
{
id: schema["definitions"]["app"]["definitions"]["id"]["example"],
name: schema["definitions"]["app"]["definitions"]["name"]["example"],
}
]
)
end
end
context "with info API" do
let(:verb) do
:get
end
let(:path) do
"/apps/1"
end
it "returns dummy response" do
should == 200
expect(response.body).to be_json_as(
{
id: schema["definitions"]["app"]["definitions"]["id"]["example"],
name: schema["definitions"]["app"]["definitions"]["name"]["example"],
}
)
end
end
context "with POST API" do
let(:verb) do
:post
end
let(:path) do
"/apps"
end
it "returns dummy response with 201" do
should == 201
end
end
context "without example" do
before do
schema["definitions"]["app"]["definitions"]["id"].delete("example")
end
let(:verb) do
:get
end
let(:path) do
"/apps"
end
it "returns example_not_found error" do
should == 500
expect(response.body).to be_json_as(
id: "example_not_found",
message: "No example found for #/definitions/app/id",
)
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/spec/rack/spec/schema_provider_spec.rb | spec/rack/spec/schema_provider_spec.rb | require "spec_helper"
describe Rack::JsonSchema::SchemaProvider do
include Rack::Test::Methods
let(:app) do
local_schema_url_path = schema_url_path
local_schema = schema
Rack::Builder.app do
use Rack::JsonSchema::SchemaProvider, path: local_schema_url_path, schema: local_schema
run ->(env) do
[
200,
{},
["dummy"],
]
end
end
end
let(:schema) do
str = File.read(schema_path)
JSON.parse(str)
end
let(:schema_path) do
File.expand_path("../../../fixtures/schema.json", __FILE__)
end
let(:schema_url_path) do
nil
end
let(:response) do
last_response
end
let(:env) do
{}
end
let(:params) do
{}
end
subject do
send(verb, path, params, env)
response.status
end
describe "#call" do
let(:verb) do
:get
end
context "without :path option" do
let(:path) do
"/schema"
end
it "returns JSON Schema to request to GET /schema" do
should == 200
expect(response.body).to include("app")
end
end
context "with :path option" do
let(:schema_url_path) do
"/json_schema"
end
let(:path) do
"/json_schema"
end
it "responds to specified path" do
should == 200
expect(response.body).not_to eq("dummy")
end
end
context "without targeted request" do
let(:path) do
"/apps"
end
it "delegates request to inner app" do
should == 200
expect(response.body).to eq("dummy")
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/spec/rack/spec/docs_spec.rb | spec/rack/spec/docs_spec.rb | require "spec_helper"
describe Rack::JsonSchema::Docs do
include Rack::Test::Methods
let(:app) do
local_docs_path = docs_path
local_schema = schema
Rack::Builder.app do
use Rack::JsonSchema::Docs, path: local_docs_path, schema: local_schema
run ->(env) do
[
200,
{},
["dummy"],
]
end
end
end
let(:schema) do
str = File.read(schema_path)
JSON.parse(str)
end
let(:schema_path) do
File.expand_path("../../../fixtures/schema.json", __FILE__)
end
let(:docs_path) do
nil
end
let(:response) do
last_response
end
let(:env) do
{}
end
let(:params) do
{}
end
subject do
send(verb, path, params, env)
response.status
end
describe "#call" do
let(:verb) do
:get
end
context "without :path option" do
let(:path) do
"/docs"
end
it "generates API documentation and returns it to request to GET /docs" do
should == 200
expect(response.body).to include("Example API")
end
end
context "with :path option" do
let(:docs_path) do
"/api_document"
end
let(:path) do
"/api_document"
end
it "responds to specified path" do
should == 200
expect(response.body).not_to eq("dummy")
end
end
context "without targeted request" do
let(:path) do
"/apps"
end
it "delegates request to inner app" do
should == 200
expect(response.body).to eq("dummy")
end
end
context "with /docs.md" do
let(:path) do
"/docs.md"
end
it "also accepts GET /docs.md" do
should == 200
expect(response.body).not_to eq("dummy")
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack-json_schema.rb | lib/rack-json_schema.rb | require "rack/json_schema"
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema.rb | lib/rack/json_schema.rb | require "erubis"
require "jdoc"
require "json"
require "json_schema"
require "rack"
require "rack/json_schema/base_request_handler"
require "rack/json_schema/error"
require "rack/json_schema/docs"
require "rack/json_schema/error_handler"
require "rack/json_schema/mock"
require "rack/json_schema/request_validation"
require "rack/json_schema/response_validation"
require "rack/json_schema/schema"
require "rack/json_schema/schema_provider"
require "rack/json_schema/version"
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema/request_validation.rb | lib/rack/json_schema/request_validation.rb | module Rack
module JsonSchema
class RequestValidation
# Behaves as a rack-middleware
# @param app [Object] Rack application
# @param ignore_invalid_content_type [false, true] Ignore requests with non json content-type
# @param ignore_missing_path [false, true] Ignore requests not defined in schema
# @param schema [Hash] Schema object written in JSON schema format
# @raise [JsonSchema::SchemaError]
def initialize(app, ignore_invalid_content_type: false, ignore_missing_path: false, schema: nil)
@app = app
@ignore_invalid_content_type = ignore_invalid_content_type
@ignore_missing_path = ignore_missing_path
@schema = Schema.new(schema)
end
# @raise [Rack::JsonSchema::RequestValidation::Error] Raises if given request is invalid to JSON Schema
# @param env [Hash] Rack env
def call(env)
Validator.call(
env: env,
ignore_invalid_content_type: @ignore_invalid_content_type,
ignore_missing_path: @ignore_missing_path,
schema: @schema
)
@app.call(env)
end
class Validator < BaseRequestHandler
# Utility wrapper method
def self.call(**args)
new(**args).call
end
# @param env [Hash] Rack env
# @param ignore_invalid_content_type [false, true]
# @param ignore_missing_path [false, true]
# @param schema [JsonSchema::Schema] Schema object
def initialize(env: nil, ignore_invalid_content_type: false, ignore_missing_path: false, schema: nil)
@env = env
@ignore_invalid_content_type = ignore_invalid_content_type
@ignore_missing_path = ignore_missing_path
@schema = schema
end
# Raises an error if any error detected
# @raise [Rack::JsonSchema::RequestValidation::Error]
def call
if has_link_for_current_action?
if has_body? && !has_valid_content_type?
unless ignore_invalid_content_type?
raise InvalidContentType
end
else
case
when content_type_json? && has_body? && !has_valid_json?
raise InvalidJson
when content_type_json? && has_schema? && !has_hash_request_body?
raise InvalidParameter, "Invalid request. Request body must be an Object in JSON."
when content_type_json? && has_schema? && !has_valid_parameter?
raise InvalidParameter, "Invalid request.\n#{schema_validation_error_message}"
end
end
elsif !ignore_missing_path?
raise LinkNotFound, "Could not find the link definition for request path #{path}."
end
end
private
def has_hash_request_body?
parameters_from_body.is_a?(Hash)
end
def has_valid_json?
parsed_body
true
rescue JSON::JSONError
false
end
# @return [true, false] True if request parameters are all valid
def has_valid_parameter?
!!schema_validation_result[0]
end
# @return [true, false] True if any schema is defined for the current action
def has_schema?
!!link.schema
end
# @return [true, false] True if request body is not empty
def has_body?
!body.empty?
end
# @return [true, false] True if no or matched content type given
def has_valid_content_type?
mime_type.nil? || Rack::Mime.match?(link.enc_type, mime_type)
end
# @return [false, true]
def ignore_invalid_content_type?
!!@ignore_invalid_content_type
end
# @return [false, true]
def ignore_missing_path?
!!@ignore_missing_path
end
# @return [true, false] True if the current link supports json format
def content_type_json?
Rack::Mime.match?(link.enc_type, "application/json")
end
# @return [Array] A result of schema validation for the current action
def schema_validation_result
@schema_validation_result ||= link.schema.validate(parameters)
end
# @return [Array] Errors of schema validation
def schema_validation_errors
schema_validation_result[1]
end
# @return [String] Joined error message to the result of schema validation
def schema_validation_error_message
::JsonSchema::SchemaError.aggregate(schema_validation_errors).join("\n")
end
# @return [String, nil] Request MIME Type specified in Content-Type header field
# @example
# mime_type #=> "application/json"
def mime_type
request.content_type.split(";").first if request.content_type
end
# @return [String] request body
def body
return @body if instance_variable_defined?(:@body)
if request.body
@body = request.body.read
request.body.rewind
else
@body = ''
end
@body
end
# @return [Hash] Request parameters decoded from JSON
# @raise [JSON::JSONError]
def parameters
@parameters ||= parameters_from_query.merge(parameters_from_body)
end
# @return [Hash] Request parameters decoded from JSON
# @raise [JSON::JSONError]
def parameters_from_body
if has_body?
parsed_body
else
{}
end
end
# @return [Hash] Request parameters extracted from URI query
def parameters_from_query
request.GET
end
def parsed_body
@parsed_body ||= JSON.parse(body)
end
end
# Base error class for Rack::JsonSchema::RequestValidation
class Error < Error
end
# Error class for case when no link defined for given request
class LinkNotFound < Error
def status
404
end
def id
"link_not_found"
end
end
# Error class for invalid request content type
class InvalidContentType < Error
def initialize
super("Invalid content type")
end
def status
400
end
def id
"invalid_content_type"
end
end
# Error class for invalid JSON
class InvalidJson < Error
def initialize
super("Request body wasn't valid JSON")
end
def status
400
end
def id
"invalid_json"
end
end
# Error class for invalid request parameter
class InvalidParameter < Error
def status
400
end
def id
"invalid_parameter"
end
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema/version.rb | lib/rack/json_schema/version.rb | module Rack
module JsonSchema
VERSION = "1.5.4"
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema/schema_provider.rb | lib/rack/json_schema/schema_provider.rb | module Rack
module JsonSchema
class SchemaProvider
DEFAULT_PATH = "/schema"
# Behaves as a rack-middleware
# @param app [Object] Rack application
# @param path [String, nil] URL path to return JSON Schema (default: /schema)
# @param schema [Hash] Schema object written in JSON schema format
# @raise [JsonSchema::SchemaError]
def initialize(app, path: nil, schema: nil)
@app = app
@path = path
@schema = schema
end
# Returns rendered document for document request
# @return [Array] Rack response
# @param env [Hash] Rack env
def call(env)
if env["REQUEST_METHOD"] == "GET" && env["PATH_INFO"] == path
[
200,
{ "Content-Type" => "application/json" },
[rendered_schema],
]
else
@app.call(env)
end
end
private
# @return [String] Path to return document
def path
@path || DEFAULT_PATH
end
# @return [String] Rendered JSON Schema in JSON format
def rendered_schema
JSON.pretty_generate(@schema)
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema/docs.rb | lib/rack/json_schema/docs.rb | module Rack
module JsonSchema
class Docs
DEFAULT_PATH = "/docs"
# Behaves as a rack-middleware
# @param app [Object] Rack application
# @param path [String, nil] URL path to return document (default: /docs)
# @param schema [Hash] Schema object written in JSON schema format
def initialize(app, path: nil, schema: nil)
@app = app
@path = path
@markdown = Jdoc::Generator.call(schema)
@html = Jdoc::Generator.call(schema, html: true)
end
# Returns rendered document for document request
# @param env [Hash] Rack env
def call(env)
DocumentGenerator.call(
app: @app,
env: env,
html: @html,
markdown: @markdown,
path: path,
)
end
private
# @return [String] Path to return document
def path
@path || DEFAULT_PATH
end
class DocumentGenerator
def self.call(*args, **kwargs)
new(*args, **kwargs).call
end
# @param app [Object] Rack application
# @param env [Hash] Rack env
# @param html [String] HTML rendered docs
# @param markdown [String] Markdown rendered docs
# @param path [String] Route for docs
def initialize(app: nil, env: nil, html: nil, markdown: nil, path: nil)
@app = app
@env = env
@html = html
@markdown = markdown
@path = path
end
# Generates suited response body from given env & document to docs request
# @return [Array] Rack response
def call
if has_docs_request?
if has_markdown_request?
markdown_response
else
html_response
end
else
delegate
end
end
private
# Delegates request to given rack app
def delegate
@app.call(@env)
end
# @return [true, false] True if docs are requested
def has_docs_request?
request_method == "GET" && path_without_extname == @path
end
# @return [true, false] True if raw markdown content are requested
def has_markdown_request?
extname == ".md"
end
# @return [String] Extension name of request path
# @example
# extname #=> ".md"
def extname
::File.extname(path)
end
# @return [String] Request path
def path
@env["PATH_INFO"]
end
# @return [String]
def request_method
@env["REQUEST_METHOD"]
end
# @return [String]
def path_without_extname
path.gsub(/\..+\z/, "")
end
# @return [Array] Rack response of raw markdown text
def markdown_response
[
200,
{ "Content-Type" => "text/plain; charset=utf-8" },
[@markdown],
]
end
# @return [Array] Rack response of human readable HTML document, rendered from given document
def html_response
[
200,
{ "Content-Type" => "text/html; charset=utf-8" },
[@html],
]
end
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema/base_request_handler.rb | lib/rack/json_schema/base_request_handler.rb | module Rack
module JsonSchema
# Base class for providing some utility methods to handle Rack env and JSON Schema
class BaseRequestHandler
# Utility wrapper method
def self.call(*args, **kwargs)
new(*args, **kwargs).call
end
# @param env [Hash] Rack env
# @param schema [JsonSchema::Schema] Schema object
def initialize(env: nil, schema: nil)
@env = env
@schema = schema
end
private
# Treats env as a utility object to easily extract method and path
# @return [Rack::Request]
def request
@request ||= Rack::Request.new(@env)
end
# @return [String] HTTP request method
# @example
# method #=> "GET"
def method
request.request_method
end
# @return [String] Request path
# @example
# path #=> "/recipes"
def path
request.path_info
end
# @return [JsonSchema::Schema::Link, nil] Link for the current action
def link
if instance_variable_defined?(:@link)
@link
else
@link = @schema.link_for(method: method, path: path)
end
end
# @return [true, false] True if link is defined for the current action
def has_link_for_current_action?
!!link
end
# @return [JsonSchema::Schema] Schema for current link, specified by targetSchema or parent schema
def schema_for_current_link
link.target_schema || link.parent
end
# @return [true, false] True if response is intended to be list data
def has_list_data?
link.rel == "instances"
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema/error_handler.rb | lib/rack/json_schema/error_handler.rb | module Rack
module JsonSchema
class ErrorHandler
# Behaves as a rack middleware
# @param app [Object] Rack application
def initialize(app)
@app = app
end
# Behaves as a rack middleware
# @param env [Hash] Rack env
def call(env)
@app.call(env)
rescue Rack::JsonSchema::Error => exception
exception.to_rack_response
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema/response_validation.rb | lib/rack/json_schema/response_validation.rb | module Rack
module JsonSchema
class ResponseValidation
# Behaves as a rack-middleware
# @param app [Object] Rack application
# @param schema [Hash] Schema object written in JSON schema format
# @raise [JsonSchema::SchemaError]
def initialize(app, schema: nil)
@app = app
@schema = Schema.new(schema)
end
# @raise [Rack::JsonSchema::ResponseValidation::Error]
# @param env [Hash] Rack env
def call(env)
@app.call(env).tap do |response|
Validator.call(env: env, response: response, schema: @schema)
end
end
class Validator < BaseRequestHandler
# @param env [Hash] Rack env
# @param response [Array] Rack response
# @param schema [JsonSchema::Schema] Schema object
def initialize(env: nil, response: nil, schema: nil)
@env = env
@response = response
@schema = schema
end
# Raises an error if any error detected, skipping validation for non-defined link
# @raise [Rack::JsonSchema::ResponseValidation::InvalidResponse]
def call
if !has_redirection_or_error_status? && has_link_for_current_action? && has_link_of_media_type_json?
case
when has_body? && !has_json_content_type?
raise InvalidResponseContentType
when !valid?
raise InvalidResponseType, validator.errors
end
end
end
# @return [true, false] True if any bytes are included in response body
def has_body?
!body.size.zero?
end
# @return [true, false] True if Link mediaType is for JSON
def has_link_of_media_type_json?
mime_type_json?(link.media_type)
end
# @return [true, false] True if response Content-Type is for JSON
def has_json_content_type?
mime_type_json?(mime_type)
end
# @return [true, false] True if given data is valid to the JSON schema
def valid?
!has_body? || (has_list_data? && data.empty?) || validator.validate(example_item)
end
# @return [Hash] Choose an item from response data, to be validated
def example_item
if has_list_data?
data.first
else
data
end
end
# @return [Array, Hash] Response body data, decoded from JSON
def data
JSON.parse(body)
end
# @return [JsonSchema::Validator]
# @note The result is memoized for returning errors in invalid case
def validator
@validator ||= ::JsonSchema::Validator.new(schema_for_current_link)
end
# @return [Hash] Response headers
def headers
@response[1]
end
# @return [String] Response body
def body
result = ""
@response[2].each {|str| result << str }
result
end
# @return [Fixnum] Response status code
def response_status
@response[0]
end
# Skips validation if status code is equal to or larger than 300
# @return [true, false]
def has_redirection_or_error_status?
response_status >= 300
end
# @return [String, nil] Response MIME Type specified in Content-Type header field
# @example
# mime_type #=> "application/json"
def mime_type
headers["Content-Type"].split(";").first if headers["Content-Type"]
end
# @return [true, false] return true if mime type is for JSON
# @example
# "application/json" #=> true
# "application/calendar+json" #=> true
# "application/vnd.myapp.custom-json" #=> false
def mime_type_json?(value)
%r<\Aapplication/(?:.*\+)?json> === value
end
end
# Base error class for Rack::JsonSchema::ResponseValidation
class Error < Error
end
class InvalidResponseType < Error
def initialize(errors)
super ::JsonSchema::SchemaError.aggregate(errors).join(" ")
end
def id
"invalid_response_type"
end
def status
500
end
end
class InvalidResponseContentType < Error
def initialize
super("Response Content-Type wasn't for JSON")
end
def id
"invalid_response_content_type"
end
def status
500
end
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema/mock.rb | lib/rack/json_schema/mock.rb | module Rack
module JsonSchema
class Mock
# Behaves as a rack-middleware
# @param app [Object] Rack application
# @param schema [Hash] Schema object written in JSON schema format
# @raise [JsonSchema::SchemaError]
def initialize(app, schema: nil)
@app = app
@schema = Schema.new(schema)
end
# @param env [Hash] Rack env
def call(env)
RequestHandler.call(app: @app, env: env, schema: @schema)
end
class RequestHandler < BaseRequestHandler
# @param app [Object] Rack application
def initialize(app: nil, **args)
@app = app
super(**args)
end
# Returns dummy response if JSON schema is defined for the current link
# @return [Array] Rack response
def call
if has_link_for_current_action?
dummy_response
else
@app.call(@env)
end
end
private
def dummy_response
[dummy_status, dummy_headers, [dummy_body]]
end
def dummy_status
method == "POST" ? 201 : 200
end
def dummy_headers
{ "Content-Type" => "application/json; charset=utf-8" }
end
def dummy_body
document = ResponseGenerator.call(schema_for_current_link)
document = [document] if has_list_data?
JSON.pretty_generate(document) + "\n"
end
end
class ResponseGenerator
# Generates example response Hash from given schema
# @return [Hash]
# @example
# Rack::JsonSchema::Mock::ResponseGenerator(schema) #=> { "id" => 1, "name" => "example" }
def self.call(schema)
schema.properties.inject({}) do |result, (key, value)|
result.merge(
key => case
when !value.properties.empty?
call(value)
when !value.data["example"].nil?
value.data["example"]
when value.type.include?("null")
nil
when value.type.include?("array")
[call(value.items)]
else
raise ExampleNotFound, "No example found for #{schema.pointer}/#{key}"
end
)
end
end
end
class Error < Error
end
class ExampleNotFound < Error
def id
"example_not_found"
end
def status
500
end
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema/schema.rb | lib/rack/json_schema/schema.rb | module Rack
module JsonSchema
# Utility wrapper class for JsonSchema::Schema
class Schema
# Recursively extracts all links in given JSON schema
# @param json_schema [JsonSchema::Schema]
# @return [Array] An array of JsonSchema::Schema::Link
def self.extract_links(json_schema)
links = json_schema.links.select {|link| link.method && link.href }
links + json_schema.properties.map {|key, schema| extract_links(schema) }.flatten
end
# @param schema [Hash]
# @raise [JsonSchema::SchemaError]
# @example
# hash = JSON.parse("schema.json")
# schema = Rack::JsonSchema::Schema.new(hash)
def initialize(schema)
@json_schema = ::JsonSchema.parse!(schema).tap(&:expand_references!)
end
# @param method [String] Uppercase HTTP method name (e.g. GET, POST)
# @param path [String] Path string, which may include URI template
# @return [JsonSchema::Scheam::Link, nil] Link defined for the given method and path
# @example
# schema.has_link_for?(method: "GET", path: "/recipes/{+id}") #=> nil
def link_for(method: nil, path: nil)
links_indexed_by_method[method].find do |link|
%r<^#{link.href.gsub(/(?:\{.*?\})|(?::\w+)/, "[^/]+")}$> === path
end
end
# @return [Array] All links defined in given JSON schema
# @example
# schema.links #=> [#<JsonSchema::Schema::Link>]
def links
@links ||= self.class.extract_links(@json_schema)
end
private
# @return [Hash] A key-value pair of HTTP method and an Array of links
# @note This Hash always returns an Array for any key
# @example
# schema.links_indexed_by_method #=> { "GET" => [#<JsonSchema::Schema::Link>] }
def links_indexed_by_method
@links_indexed_by_method ||= links.inject(Hash.new {|hash, key| hash[key] = [] }) do |result, link|
result[link.method.to_s.upcase] << link
result
end
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
r7kamura/rack-json_schema | https://github.com/r7kamura/rack-json_schema/blob/f2dee02dd401b55bb2a216279201f77bc30a358e/lib/rack/json_schema/error.rb | lib/rack/json_schema/error.rb | module Rack
module JsonSchema
class Error < StandardError
# @return [Array] Rack response
def to_rack_response
[status, headers, [body]]
end
private
# @note Override this
def status
500
end
# @note Override this
def id
"internal_server_error"
end
def headers
{ "Content-Type" => "application/json; charset=utf-8" }
end
def body
JSON.pretty_generate(id: id, message: message) + "\n"
end
end
end
end
| ruby | MIT | f2dee02dd401b55bb2a216279201f77bc30a358e | 2026-01-04T17:51:21.313181Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/app/helpers/flipper_helper.rb | app/helpers/flipper_helper.rb | # frozen_string_literal: true
module FlipperHelper
def should_add_tour(flipper_key, flipper_activation)
return true if !flipper_defined?
case process_activation_option(flipper_activation)
when "enabled"
return (flipper_key && Flipper.enabled?(flipper_key.to_sym)) || flipper_key.nil?
when "disabled"
return (flipper_key && !Flipper.enabled?(flipper_key.to_sym)) || flipper_key.nil?
else
return false
end
end
private
def flipper_defined?
Object.const_defined?("Flipper")
end
def process_activation_option(flipper_activation)
return "disabled" if flipper_activation == "disabled"
"enabled"
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/app/helpers/abraham_helper.rb | app/helpers/abraham_helper.rb | # frozen_string_literal: true
module AbrahamHelper
include FlipperHelper
def abraham_tour
# Do we have tours for this controller/action in the user's locale?
tours = Rails.configuration.abraham.tours["#{controller_path}.#{action_name}.#{I18n.locale}"]
# Otherwise, default to the default locale
tours ||= Rails.configuration.abraham.tours["#{controller_path}.#{action_name}.#{I18n.default_locale}"]
if tours
# Have any automatic tours been completed already?
completed = AbrahamHistory.where(
creator_id: current_user.id,
controller_name: controller_path,
action_name: action_name
)
tour_keys_completed = completed.map(&:tour_name)
tour_keys = tours.keys
tour_html = ''
tour_keys.each do |key|
flipper_key = tours[key]["flipper_key"]
flipper_activation = tours[key]["flipper_activation"]
if should_add_tour(flipper_key, flipper_activation)
tour_html += render(partial: "application/abraham",
locals: { tour_name: key,
tour_completed: tour_keys_completed.include?(key),
trigger: tours[key]["trigger"],
steps: tours[key]["steps"] })
end
end
tour_html.html_safe
end
end
def abraham_cookie_prefix
"abraham-#{fetch_application_name.to_s.underscore}-#{current_user.id}-#{controller_path}-#{action_name}"
end
def fetch_application_name
if Module.method_defined?(:module_parent)
Rails.application.class.module_parent
else
Rails.application.class.parent
end
end
def abraham_domain
request.host
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/app/controllers/abraham_histories_controller.rb | app/controllers/abraham_histories_controller.rb | # frozen_string_literal: true
class AbrahamHistoriesController < ApplicationController
def create
@abraham_history = AbrahamHistory.new(abraham_history_params)
@abraham_history.creator_id = current_user.id
respond_to do |format|
if @abraham_history.save
format.json { render json: @abraham_history, status: :created }
else
format.json { render json: @abraham_history.errors, status: :unprocessable_entity }
end
end
end
private
def abraham_history_params
params.require(:abraham_history).permit(:controller_name, :action_name, :tour_name)
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/app/models/application_record.rb | app/models/application_record.rb | # frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/app/models/abraham_history.rb | app/models/abraham_history.rb | # frozen_string_literal: true
class AbrahamHistory < ActiveRecord::Base
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/application_system_test_case.rb | test/application_system_test_case.rb | require "test_helper"
Capybara.server = :webrick
Capybara.register_driver(:headless_chrome) do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w[headless disable-gpu] }
)
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: capabilities
)
end
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/install_generator_test.rb | test/install_generator_test.rb | # frozen_string_literal: true
require "test_helper"
require "rails/generators"
require "generators/abraham/install_generator"
class InstallGeneratorTest < Rails::Generators::TestCase
tests Abraham::Generators::InstallGenerator
destination File.expand_path("../tmp", __dir__)
setup :prepare_destination
test "should generate a migration" do
begin
run_generator
assert_migration "db/migrate/create_abraham_histories"
ensure
FileUtils.rm_rf destination_root
end
end
test "should skip the migration when told to do so" do
begin
run_generator ["--skip-migration"]
assert_no_migration "db/migrate/create_abraham_histories"
ensure
FileUtils.rm_rf destination_root
end
end
test "should generate an initializer" do
begin
run_generator
assert_file "config/initializers/abraham.rb"
assert_file "config/abraham.yml"
ensure
FileUtils.rm_rf destination_root
end
end
test "should skip the initializer when told to do so" do
begin
run_generator ["--skip-initializer"]
assert_no_file "config/initializers/abraham.rb"
ensure
FileUtils.rm_rf destination_root
end
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/test_helper.rb | test/test_helper.rb | # frozen_string_literal: true
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"
require File.expand_path('../dummy/config/environment.rb', __FILE__)
ActiveRecord::Migrator.migrations_paths = [File.expand_path('../dummy/db/migrate', __FILE__)]
require 'rails/test_help'
require 'mocha/minitest'
# Filter out Minitest backtrace while allowing backtrace from other libraries
# to be shown.
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/abraham_test.rb | test/abraham_test.rb | # frozen_string_literal: true
require "test_helper"
class Abraham::Test < ActiveSupport::TestCase
test "truth" do
assert_kind_of Module, Abraham
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/models/abraham_history_test.rb | test/models/abraham_history_test.rb | # frozen_string_literal: true
require "test_helper"
class AbrahamHistoryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/app/jobs/application_job.rb | test/dummy/app/jobs/application_job.rb | # frozen_string_literal: true
class ApplicationJob < ActiveJob::Base
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/app/helpers/dashboard_helper.rb | test/dummy/app/helpers/dashboard_helper.rb | # frozen_string_literal: true
module DashboardHelper
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/app/helpers/application_helper.rb | test/dummy/app/helpers/application_helper.rb | # frozen_string_literal: true
module ApplicationHelper
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/app/controllers/dashboard_controller.rb | test/dummy/app/controllers/dashboard_controller.rb | # frozen_string_literal: true
class DashboardController < ApplicationController
def home; end
def other; end
def placement; end
def missing; end
def buttons; end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/app/controllers/application_controller.rb | test/dummy/app/controllers/application_controller.rb | # frozen_string_literal: true
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
helper_method :current_user
def current_user
OpenStruct.new(id: Random.rand(1..99_999))
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/app/controllers/foobar/dashboard_controller.rb | test/dummy/app/controllers/foobar/dashboard_controller.rb | # frozen_string_literal: true
class Foobar::DashboardController < ApplicationController
def home; end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/app/models/application_record.rb | test/dummy/app/models/application_record.rb | # frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/app/mailers/application_mailer.rb | test/dummy/app/mailers/application_mailer.rb | # frozen_string_literal: true
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/app/channels/application_cable/channel.rb | test/dummy/app/channels/application_cable/channel.rb | # frozen_string_literal: true
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/app/channels/application_cable/connection.rb | test/dummy/app/channels/application_cable/connection.rb | # frozen_string_literal: true
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/db/schema.rb | test/dummy/db/schema.rb | # 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.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2016_11_18_143752) do
create_table "abraham_histories", force: :cascade do |t|
t.string "controller_name"
t.string "action_name"
t.string "tour_name"
t.integer "creator_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["created_at"], name: "index_abraham_histories_on_created_at"
t.index ["creator_id"], name: "index_abraham_histories_on_creator_id"
t.index ["updated_at"], name: "index_abraham_histories_on_updated_at"
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/db/migrate/20161118143752_create_abraham_histories.rb | test/dummy/db/migrate/20161118143752_create_abraham_histories.rb | # frozen_string_literal: true
class CreateAbrahamHistories < ActiveRecord::Migration[5.0]
def change
create_table :abraham_histories do |t|
t.string :controller_name
t.string :action_name
t.string :tour_name
t.references :creator, null: false, index: true
t.timestamps index: true
end
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/test/system/tours_test.rb | test/dummy/test/system/tours_test.rb | require "application_system_test_case"
class ToursTest < ApplicationSystemTestCase
setup do
@user_id = Random.rand(1..99999)
@cookie_name = "abraham-dummy-#{@user_id}-dashboard-home-intro"
ApplicationController.any_instance.stubs(:current_user).returns(OpenStruct.new(id: @user_id))
end
test "see and complete a tour" do
visit dashboard_home_url
# Tour Step 1
assert_selector ".shepherd-element", visible: true
assert_selector ".shepherd-text", text: "ENGLISH This first HOME step is centered & 'text-only'"
assert_selector ".shepherd-button", text: "Later"
assert_selector ".shepherd-button", text: "Continue"
find(".shepherd-button", text: "Continue").click
# Now try to manually trigger another tour
find('#show_manual').click
# Even though we triggered another tour, it should not appear since one is already active
assert_selector ".shepherd-element", count: 1, visible: true
# Tour Step 2
assert_selector ".shepherd-header", text: "ENGLISH This step has a \"title\""
assert_selector ".shepherd-text", text: "ENGLISH This intermediate step has \"some text\""
assert_selector ".shepherd-button", text: "Exit"
assert_selector ".shepherd-button", text: "Next"
find(".shepherd-button", text: "Next").click
# Tour Step 3 (should be skipped)
refute_selector ".shepherd-header", text: "ENGLISH A missing step"
# Tour Step 4
assert_selector ".shepherd-header", text: "ENGLISH The final step"
assert_selector ".shepherd-text", text: "ENGLISH Some text here too, and it's attached to the right"
assert_selector ".shepherd-arrow", visible: true
assert_selector ".shepherd-button", text: "Done"
find(".shepherd-button", text: "Done").click
# Tour should no longer be visible
refute_selector ".shepherd-element"
# Tour should not reappear on reload
visit dashboard_home_url
refute_selector ".shepherd-element"
# Now start a manual tour
find('#show_manual').click
assert_selector ".shepherd-element", visible: true
assert_selector ".shepherd-text", text: "You triggered the manual tour"
assert_selector ".shepherd-button", text: "Done"
find(".shepherd-button", text: "Done").click
# Even though we finished the manual tour, we can start it again right away
find('#show_manual').click
assert_selector ".shepherd-element", visible: true
end
test "mark a tour for Later and it will not come back in this session" do
visit dashboard_home_url
assert_selector ".shepherd-element", visible: true
# Dismiss tour
find(".shepherd-button", text: "Later").click
# Tour should no longer be visible
refute_selector ".shepherd-element"
# Tour should not reappear on reload
visit dashboard_home_url
refute_selector ".shepherd-element"
# Clear the cookie (simulate browser restart)
execute_script("Cookies.remove('#{@cookie_name}', { domain: '127.0.0.1' });")
# Tour should reappear
visit dashboard_home_url
assert_selector ".shepherd-element", visible: true
end
test "navigate with turbolinks between pages with tours" do
visit dashboard_home_url
assert_selector ".shepherd-element", visible: true
# Navigate to other page
find("a").click
assert_selector ".shepherd-element", visible: true
end
test "tour with missing first step attachTo does not appear" do
visit dashboard_missing_url
# No tour should be visible, since the first step is invalid
refute_selector ".shepherd-element"
end
test "page with two incomplete tours shows them on consecutive visits" do
# First tour should appear at first visit
visit dashboard_other_url
assert_selector ".shepherd-element", visible: true
assert_selector ".shepherd-header", text: "TOUR ONE step one ENGLISH"
find(".shepherd-button", text: "Done").click
# Second tour should appear at second visit
visit dashboard_other_url
assert_selector ".shepherd-element", visible: true
assert_selector ".shepherd-header", text: "TOUR TWO step one ENGLISH"
find(".shepherd-button", text: "Done").click
# Now no tours should appear since they're both done
visit dashboard_other_url
refute_selector ".shepherd-element"
end
test "tour with custom buttons" do
visit dashboard_buttons_url
assert_selector ".shepherd-element", visible: true
assert_selector ".shepherd-button", text: "Show this to me later"
assert_selector ".shepherd-button", text: "Finish now"
# Confirm that the custom buttons' specified actions work
### Click cancel
find(".shepherd-button", text: "Show this to me later").click
### Revisit
visit dashboard_buttons_url
### Tour doesn't appear
refute_selector ".shepherd-element"
### Clear the cookie
execute_script("Cookies.remove('abraham-dummy-#{@user_id}-dashboard-buttons-button_tour', { domain: '127.0.0.1' });")
### Revisit
visit dashboard_buttons_url
### Tour should reappear and let us click the other button
find(".shepherd-button", text: "Finish now").click
### Revisit
visit dashboard_buttons_url
### Tour doesn't appear (now because it's completed)
refute_selector ".shepherd-element"
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/test/helpers/flipper_helper_test.rb | test/dummy/test/helpers/flipper_helper_test.rb | # frozen_string_literal: true
require "test_helper"
class FlipperHelperTest < ActionView::TestCase
test "Add tour whenever all options nil" do
assert should_add_tour(nil, nil)
end
test "Add tour whenever Flipper is disabled " do
# Flipper is not enabled, so tour should be added regardless of options
assert should_add_tour("foo", "enabled")
assert should_add_tour("foo", "disabled")
end
test "Respect Flipper results if Flipper enabled" do
mockFlipper = Object.new
mockFlipper.stubs(:enabled?).returns(true)
Kernel.const_set('Flipper', mockFlipper)
assert_equal Flipper, mockFlipper
assert should_add_tour("foo", "enabled")
refute should_add_tour("foo", "disabled")
mockFlipper.stubs(:enabled?).returns(false)
refute should_add_tour("foo", "enabled")
assert should_add_tour("foo", "disabled")
Kernel.send(:remove_const, :Flipper)
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/test/controllers/abraham_histories_controller_test.rb | test/dummy/test/controllers/abraham_histories_controller_test.rb | # frozen_string_literal: true
require "test_helper"
class AbrahamHistoriesControllerTest < ActionDispatch::IntegrationTest
test "should create AbrahamHistory" do
assert_difference ["AbrahamHistory.count"] do
post abraham_histories_url, as: :json, params: { abraham_history: { action_name: "foo", controller_name: "bar", tour_name: "baz" } }
end
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/test/controllers/dashboard_controller_test.rb | test/dummy/test/controllers/dashboard_controller_test.rb | # frozen_string_literal: true
require "test_helper"
class DashboardControllerTest < ActionDispatch::IntegrationTest
setup do
I18n.locale = :en
end
teardown do
I18n.locale = :en
end
test "uses configured shepherd configuration" do
# No options
Rails.configuration.abraham.tour_options = nil
get dashboard_home_url
assert_response :success
assert_select "body script" do |element|
# No options passed into Tour()
assert element.text.include? "new Shepherd.Tour()"
end
# Custom options
Rails.configuration.abraham.tour_options = '{ defaultStepOptions: { classes: "my-custom-class" } }'
get dashboard_home_url
assert_select "body script" do |element|
# Config-specified options passed into Tour()
assert element.text.include? 'new Shepherd.Tour({ defaultStepOptions: { classes: "my-custom-class" } })'
end
end
test "home should have home tour code" do
get dashboard_home_url
assert_response :success
assert_select "body script" do |element|
# it's the home tour
assert element.text.include? "ENGLISH This first HOME step is centered & 'text-only'"
# it has four steps
assert element.text.include? "step-1"
assert element.text.include? "step-2"
assert element.text.include? "step-3"
assert element.text.include? "step-4"
# Generates a showOn option
assert element.text.include? "showOn:"
# it will post the right completion information
assert element.text.include? "controller_name: 'dashboard'"
assert element.text.include? "action_name: 'home'"
assert element.text.include? "tour_name: 'intro'"
end
end
test "should show tour for locale" do
I18n.locale = :es
get dashboard_home_url
assert_response :success
assert_select 'body script' do |element|
# it's the spanish home tour
assert element.text.include? 'SPANISH This first HOME step is centered text-only'
end
end
test "should show custom buttons for locale" do
get dashboard_buttons_url
assert_response :success
assert_select 'body script' do |element|
assert element.text.include? 'Show this to me later'
assert element.text.include? 'Finish now'
end
I18n.locale = :es
get dashboard_buttons_url
assert_response :success
assert_select 'body script' do |element|
assert element.text.include? 'Mas tarde'
assert element.text.include? 'Ahora'
end
end
test "other should have other tour code" do
get dashboard_other_url
assert_response :success
assert_select "body script" do |element|
# it's the home tour
assert element.text.include? "TOUR ONE step one ENGLISH"
# it has only one steps
assert element.text.include? "step-1"
# it will post the right completion information
assert element.text.include? "controller_name: 'dashboard'"
assert element.text.include? "action_name: 'other'"
assert element.text.include? "tour_name: 'tour_one'"
end
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/test/controllers/foobar/dashboard_controller_test.rb | test/dummy/test/controllers/foobar/dashboard_controller_test.rb | # frozen_string_literal: true
require "test_helper"
class Foobar::DashboardControllerTest < ActionDispatch::IntegrationTest
test "home should have home tour code" do
get foobar_dashboard_home_url
assert_response :success
assert_select "body script" do |element|
# it's the Foobar module home tour
assert element.text.include? "This tour should appear for the Foobar::DashboardController only"
end
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/application.rb | test/dummy/config/application.rb | # frozen_string_literal: true
require_relative "boot"
require "rails/all"
Bundler.require(*Rails.groups)
require "abraham"
module Dummy
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# For Rails 5.2 - 6.0, we need to set this configuration
if (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1) || (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR < 1)
config.active_record.sqlite3.represent_boolean_as_integer = true
end
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/environment.rb | test/dummy/config/environment.rb | # frozen_string_literal: true
# Load the Rails application.
require_relative "application"
# Initialize the Rails application.
Rails.application.initialize!
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/puma.rb | test/dummy/config/puma.rb | # frozen_string_literal: true
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum, this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
#
port ENV.fetch("PORT") { 3000 }
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory. If you use this option
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
# preload_app!
# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted this block will be run, if you are using `preload_app!`
# option you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, Ruby
# cannot share connections between processes.
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/routes.rb | test/dummy/config/routes.rb | # frozen_string_literal: true
Rails.application.routes.draw do
get "dashboard/home"
get "dashboard/other"
get "dashboard/placement"
get "dashboard/missing"
get "dashboard/buttons"
namespace :foobar do
get "dashboard/home"
end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/spring.rb | test/dummy/config/spring.rb | # frozen_string_literal: true
%w[
.ruby-version
.rbenv-vars
tmp/restart.txt
tmp/caching-dev.txt
].each { |path| Spring.watch(path) }
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/boot.rb | test/dummy/config/boot.rb | # frozen_string_literal: true
# Set up gems listed in the Gemfile.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/filter_parameter_logging.rb | test/dummy/config/initializers/filter_parameter_logging.rb | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/application_controller_renderer.rb | test/dummy/config/initializers/application_controller_renderer.rb | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# ApplicationController.renderer.defaults.merge!(
# http_host: 'example.org',
# https: false
# )
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/session_store.rb | test/dummy/config/initializers/session_store.rb | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: "_dummy_session"
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/abraham.rb | test/dummy/config/initializers/abraham.rb | # frozen_string_literal: true
Rails.application.configure do
tours = {}
tours_root = Pathname.new(Rails.root.join("config/tours"))
if Rails.root.join("config/tours").exist?
Dir.glob(Rails.root.join("config/tours/**/*.yml")).each do |yml|
relative_filename = Pathname.new(yml).relative_path_from(tours_root)
# `controller_path` is either "controller_name" or "module_name/controller_name"
controller_path, filename = relative_filename.split
file_parts = filename.to_s.split(".")
action = file_parts[0]
locale = file_parts[1]
t = YAML.load_file(yml)
tours["#{controller_path}.#{action}.#{locale}"] = t
end
end
abraham_config = Rails.application.config_for :abraham
config.abraham = ActiveSupport::OrderedOptions.new
config.abraham.tour_options = abraham_config[:tour_options]
config.abraham.tours = tours
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/new_framework_defaults.rb | test/dummy/config/initializers/new_framework_defaults.rb | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
#
# This file contains migration options to ease your Rails 5.0 upgrade.
#
# Read the Rails 5.0 release notes for more info on each option.
# Enable per-form CSRF tokens. Previous versions had false.
Rails.application.config.action_controller.per_form_csrf_tokens = true
# Enable origin-checking CSRF mitigation. Previous versions had false.
Rails.application.config.action_controller.forgery_protection_origin_check = true
# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`.
# Previous versions had false.
ActiveSupport.to_time_preserves_timezone = true
# Require `belongs_to` associations by default. Previous versions had false.
Rails.application.config.active_record.belongs_to_required_by_default = true
# Configure SSL options to enable HSTS with subdomains. Previous versions had false.
Rails.application.config.ssl_options = { hsts: { subdomains: true } }
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/wrap_parameters.rb | test/dummy/config/initializers/wrap_parameters.rb | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end
# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
# self.include_root_in_json = true
# end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/inflections.rb | test/dummy/config/initializers/inflections.rb | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/cookies_serializer.rb | test/dummy/config/initializers/cookies_serializer.rb | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Specify a serializer for the signed and encrypted cookie jars.
# Valid options are :json, :marshal, and :hybrid.
Rails.application.config.action_dispatch.cookies_serializer = :marshal | ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/assets.rb | test/dummy/config/initializers/assets.rb | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0"
# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('vendor', 'assets', 'javascripts')
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/backtrace_silencers.rb | test/dummy/config/initializers/backtrace_silencers.rb | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/initializers/mime_types.rb | test/dummy/config/initializers/mime_types.rb | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/environments/test.rb | test/dummy/config/environments/test.rb | # frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# 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 there!
config.cache_classes = true
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=3600"
}
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
config.action_mailer.perform_caching = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/environments/development.rb | test/dummy/config/environments/development.rb | # frozen_string_literal: true
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 on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join("tmp/caching-dev.txt").exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=172800"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/test/dummy/config/environments/production.rb | test/dummy/config/environments/production.rb | # frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [:request_id]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "dummy_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/lib/abraham.rb | lib/abraham.rb | # frozen_string_literal: true
require "abraham/engine"
module Abraham
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/lib/generators/abraham/install_generator.rb | lib/generators/abraham/install_generator.rb | # frozen_string_literal: true
require "rails/generators"
require "rails/generators/active_record"
module Abraham
module Generators
class InstallGenerator < ActiveRecord::Generators::Base
argument :name, type: :string, default: "random_name"
class_option :'skip-migration', type: :boolean, desc: "Don't generate a migration for the histories table"
class_option :'skip-initializer', type: :boolean, desc: "Don't generate an initializer"
class_option :'skip-config', type: :boolean, desc: "Don't generate a config file"
source_root File.expand_path(File.join(File.dirname(__FILE__), "templates"))
# Copies the migration template to db/migrate.
def copy_files
return if options["skip-migration"]
migration_template "migration.rb", "db/migrate/create_abraham_histories.rb"
end
def create_initializer
return if options["skip-initializer"]
copy_file "initializer.rb", "config/initializers/abraham.rb"
end
def create_config
return if options["skip-config"]
copy_file "abraham.yml", "config/abraham.yml"
end
end
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/lib/generators/abraham/templates/initializer.rb | lib/generators/abraham/templates/initializer.rb | # frozen_string_literal: true
Rails.application.configure do
tours = {}
tours_root = Pathname.new(Rails.root.join("config/tours"))
if Rails.root.join("config/tours").exist?
Dir.glob(Rails.root.join("config/tours/**/*.yml")).each do |yml|
relative_filename = Pathname.new(yml).relative_path_from(tours_root)
# `controller_path` is either "controller_name" or "module_name/controller_name"
controller_path, filename = relative_filename.split
file_parts = filename.to_s.split(".")
action = file_parts[0]
locale = file_parts[1]
t = YAML.load_file(yml)
tours["#{controller_path}.#{action}.#{locale}"] = t
end
end
abraham_config = Rails.application.config_for :abraham
config.abraham = ActiveSupport::OrderedOptions.new
config.abraham.tour_options = abraham_config[:tour_options]
config.abraham.tours = tours
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/lib/generators/abraham/templates/migration.rb | lib/generators/abraham/templates/migration.rb | # frozen_string_literal: true
class CreateAbrahamHistories < ActiveRecord::Migration[5.0]
def change
create_table :abraham_histories do |t|
t.string :controller_name
t.string :action_name
t.string :tour_name
t.references :creator, null: false, index: true
t.timestamps index: true
end
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/lib/abraham/version.rb | lib/abraham/version.rb | # frozen_string_literal: true
module Abraham
VERSION = "2.6.1"
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/lib/abraham/engine.rb | lib/abraham/engine.rb | # frozen_string_literal: true
require "rubygems"
module Abraham
class Engine < ::Rails::Engine
end
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
actmd/abraham | https://github.com/actmd/abraham/blob/881f4553119315243c636c9de97359e56a53d9ec/config/routes.rb | config/routes.rb | # frozen_string_literal: true
Rails.application.routes.draw do
resources :abraham_histories, only: :create
end
| ruby | MIT | 881f4553119315243c636c9de97359e56a53d9ec | 2026-01-04T17:51:22.478424Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/metadata.rb | metadata.rb | name "td-agent"
maintainer "Treasure Data, Inc."
maintainer_email "k@treasure-data.com"
license "Apache 2.0"
description "Installs/Configures td-agent"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "3.2.1"
recipe "td-agent", "td-agent configuration"
chef_version ">= 12" if respond_to?(:chef_version)
issues_url "https://github.com/treasure-data/chef-td-agent/issues" if respond_to?(:issues_url)
source_url "https://github.com/treasure-data/chef-td-agent" if respond_to?(:source_url)
%w{redhat centos debian ubuntu}.each do |os|
supports os
end
depends 'apt'
depends 'yum'
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/integration/1x-chef12/bash/spec/spec_helper.rb | test/integration/1x-chef12/bash/spec/spec_helper.rb | require "serverspec"
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/integration/1x-chef12/bash/spec/localhost/td-agent_spec.rb | test/integration/1x-chef12/bash/spec/localhost/td-agent_spec.rb | require 'serverspec'
set :backend, :exec
describe package('td-agent') do
it { should be_installed }
end
describe service('td-agent') do
it { should be_running }
end
describe file('/etc/td-agent') do
it { should be_a_directory }
end
describe file('/etc/td-agent/td-agent.conf') do
it { should be_a_file }
it { should be_mode 644 }
end
describe file('/etc/td-agent/conf.d') do
it { should be_a_directory }
it { should be_mode 755 }
end
describe package('fluent-plugin-time_parser') do
it { should_not be_installed.by('gem') }
end
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/integration/1x-chef12/bash/spec/localhost/lwrp_spec.rb | test/integration/1x-chef12/bash/spec/localhost/lwrp_spec.rb | require 'serverspec'
set :backend, :exec
describe package('td-agent') do
it { should be_installed }
end
describe service('td-agent') do
it { should be_running }
end
describe file('/etc/td-agent') do
it { should be_a_directory }
end
describe file('/etc/td-agent/td-agent.conf') do
it { should be_a_file }
it { should be_mode 644 }
end
describe file('/etc/td-agent/conf.d') do
it { should be_a_directory }
it { should be_mode 755 }
end
describe file('/etc/td-agent/conf.d/test_in_tail.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain "<source>\n type tail\n tag syslog\n format syslog\n path /var/log/syslog\n</source>"}
end
describe file('/etc/td-agent/conf.d/test_in_tail_nginx.conf') do
it { should be_a_file }
it { should be_mode 644 }
its(:content) { should match %r|^\s*type\s+tail$| }
its(:content) { should match %r|^\s*tag\s+webserver\.nginx$| }
its(:content) { should match %r|^\s*path\s+/tmp/access\.log$| }
its(:content) { should match %r|^\s*pos_file\s+/tmp/.access\.log\.pos$| }
# its(:content) { should match %r|^\s*exclude_path\s+\["/tmp/access\.log\.\*\.gz",\s+"/tmp/access\.log\.\*\.bz2"\]$| }
end
describe file('/etc/td-agent/conf.d/test_gelf_match.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain "<match webserver.*>\n type copy\n <store>\ntype gelf\nhost 127.0.0.1\nport 12201\nflush_interval 5s\n</store>\n<store>\ntype stdout\n</store>\n</match>" }
end
describe file('/etc/td-agent/conf.d/test_filter.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain %|<filter webserver.*>\n type record_transformer\n <record>\host_param "#{Socket.gethostname}"\n</record>\n</filter>| }
end
describe file('/etc/td-agent/plugin/gelf.rb') do
it { should be_a_file }
it { should be_mode 644 }
end
describe command('td-agent --dry-run') do
its(:exit_status) { should eq 0 }
end
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/integration/2x-chef13/bash/spec/spec_helper.rb | test/integration/2x-chef13/bash/spec/spec_helper.rb | require "serverspec"
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/integration/2x-chef13/bash/spec/localhost/td-agent_spec.rb | test/integration/2x-chef13/bash/spec/localhost/td-agent_spec.rb | require 'serverspec'
set :backend, :exec
describe package('td-agent') do
it { should be_installed }
end
describe service('td-agent') do
it { should be_running }
end
describe file('/etc/td-agent') do
it { should be_a_directory }
end
describe file('/etc/td-agent/td-agent.conf') do
it { should be_a_file }
it { should be_mode 644 }
end
describe file('/etc/td-agent/conf.d') do
it { should be_a_directory }
it { should be_mode 755 }
end
describe package('fluent-plugin-time_parser') do
it { should_not be_installed.by('gem') }
end
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/integration/2x-chef13/bash/spec/localhost/lwrp_spec.rb | test/integration/2x-chef13/bash/spec/localhost/lwrp_spec.rb | require 'serverspec'
set :backend, :exec
describe package('td-agent') do
it { should be_installed }
end
describe service('td-agent') do
it { should be_running }
end
describe file('/etc/td-agent') do
it { should be_a_directory }
end
describe file('/etc/td-agent/td-agent.conf') do
it { should be_a_file }
it { should be_mode 644 }
end
describe file('/etc/td-agent/conf.d') do
it { should be_a_directory }
it { should be_mode 755 }
end
describe file('/etc/td-agent/conf.d/test_in_tail.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain "<source>\n type tail\n tag syslog\n format syslog\n path /var/log/syslog\n</source>"}
end
describe file('/etc/td-agent/conf.d/test_in_tail_nginx.conf') do
it { should be_a_file }
it { should be_mode 644 }
its(:content) { should match %r|^\s*type\s+tail$| }
its(:content) { should match %r|^\s*tag\s+webserver\.nginx$| }
its(:content) { should match %r|^\s*path\s+/tmp/access\.log$| }
its(:content) { should match %r|^\s*pos_file\s+/tmp/.access\.log\.pos$| }
# its(:content) { should match %r|^\s*exclude_path\s+\["/tmp/access\.log\.\*\.gz",\s+"/tmp/access\.log\.\*\.bz2"\]$| }
end
describe file('/etc/td-agent/conf.d/test_gelf_match.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain "<match webserver.*>\n type copy\n <store>\ntype gelf\nhost 127.0.0.1\nport 12201\nflush_interval 5s\n</store>\n<store>\ntype stdout\n</store>\n</match>" }
end
describe file('/etc/td-agent/conf.d/test_filter.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain %|<filter webserver.*>\n type record_transformer\n <record>\host_param "#{Socket.gethostname}"\n</record>\n</filter>| }
end
describe file('/etc/td-agent/plugin/gelf.rb') do
it { should be_a_file }
it { should be_mode 644 }
end
describe command('td-agent --dry-run') do
its(:exit_status) { should eq 0 }
end
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/integration/2x-chef12/bash/spec/spec_helper.rb | test/integration/2x-chef12/bash/spec/spec_helper.rb | require "serverspec"
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/integration/2x-chef12/bash/spec/localhost/td-agent_spec.rb | test/integration/2x-chef12/bash/spec/localhost/td-agent_spec.rb | require 'serverspec'
set :backend, :exec
describe package('td-agent') do
it { should be_installed }
end
describe service('td-agent') do
it { should be_running }
end
describe file('/etc/td-agent') do
it { should be_a_directory }
end
describe file('/etc/td-agent/td-agent.conf') do
it { should be_a_file }
it { should be_mode 644 }
end
describe file('/etc/td-agent/conf.d') do
it { should be_a_directory }
it { should be_mode 755 }
end
describe package('fluent-plugin-time_parser') do
it { should_not be_installed.by('gem') }
end
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/integration/2x-chef12/bash/spec/localhost/lwrp_spec.rb | test/integration/2x-chef12/bash/spec/localhost/lwrp_spec.rb | require 'serverspec'
set :backend, :exec
describe package('td-agent') do
it { should be_installed }
end
describe service('td-agent') do
it { should be_running }
end
describe file('/etc/td-agent') do
it { should be_a_directory }
end
describe file('/etc/td-agent/td-agent.conf') do
it { should be_a_file }
it { should be_mode 644 }
end
describe file('/etc/td-agent/conf.d') do
it { should be_a_directory }
it { should be_mode 755 }
end
describe file('/etc/td-agent/conf.d/test_in_tail.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain "<source>\n type tail\n tag syslog\n format syslog\n path /var/log/syslog\n</source>"}
end
describe file('/etc/td-agent/conf.d/test_in_tail_nginx.conf') do
it { should be_a_file }
it { should be_mode 644 }
its(:content) { should match %r|^\s*type\s+tail$| }
its(:content) { should match %r|^\s*tag\s+webserver\.nginx$| }
its(:content) { should match %r|^\s*path\s+/tmp/access\.log$| }
its(:content) { should match %r|^\s*pos_file\s+/tmp/.access\.log\.pos$| }
# its(:content) { should match %r|^\s*exclude_path\s+\["/tmp/access\.log\.\*\.gz",\s+"/tmp/access\.log\.\*\.bz2"\]$| }
end
describe file('/etc/td-agent/conf.d/test_gelf_match.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain "<match webserver.*>\n type copy\n <store>\ntype gelf\nhost 127.0.0.1\nport 12201\nflush_interval 5s\n</store>\n<store>\ntype stdout\n</store>\n</match>" }
end
describe file('/etc/td-agent/conf.d/test_filter.conf') do
it { should be_a_file }
it { should be_mode 644 }
it { should contain %|<filter webserver.*>\n type record_transformer\n <record>\host_param "#{Socket.gethostname}"\n</record>\n</filter>| }
end
describe file('/etc/td-agent/plugin/gelf.rb') do
it { should be_a_file }
it { should be_mode 644 }
end
describe command('td-agent --dry-run') do
its(:exit_status) { should eq 0 }
end
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/fixtures/td-agent-spec/metadata.rb | test/fixtures/td-agent-spec/metadata.rb | name 'td-agent-spec'
maintainer 'Jack Naglieri'
maintainer_email 'jacknagzdev@gmail.com'
license 'Apache 2.0'
description 'Unit test fixture cookbook to verify custom resources within td-agent cookbook'
long_description 'Unit test fixture cookbook to verify custom resources within td-agent cookbook'
version '0.1.0'
depends 'td-agent' | ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/fixtures/td-agent-spec/recipes/source.rb | test/fixtures/td-agent-spec/recipes/source.rb | include_recipe 'td-agent::default'
td_agent_source '01_input' do
action :create
type 'forward'
tag 'test'
parameters(port: 22222, bind: '0.0.0.0')
end
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/fixtures/td-agent-spec/recipes/filter.rb | test/fixtures/td-agent-spec/recipes/filter.rb | include_recipe 'td-agent::default'
td_agent_filter '01_filter' do
action :create
type 'record_transformer'
tag 'test'
parameters(
record: {
hostname: '"#{Socket.gethostname}"',
tag: '${tag}'
}
)
end
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
treasure-data/chef-td-agent | https://github.com/treasure-data/chef-td-agent/blob/fdb75ce53550c43bdcc0878f849c6ee3c8886283/test/fixtures/td-agent-spec/recipes/match.rb | test/fixtures/td-agent-spec/recipes/match.rb | include_recipe 'td-agent::default'
td_agent_match '01_out_file' do
action :create
type 'file'
tag 'my.data'
parameters(
path: '/var/log/fluent/myapp',
compress: 'gzip',
buffer: {
timekey: '1d',
timekey_use_utc: true,
timekey_wait: '10m'
}
)
end
| ruby | Apache-2.0 | fdb75ce53550c43bdcc0878f849c6ee3c8886283 | 2026-01-04T17:51:25.360527Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.