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 |
|---|---|---|---|---|---|---|---|---|
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/spec/rubicure/concerns/gengou_spec.rb | spec/rubicure/concerns/gengou_spec.rb | describe Rubicure::Concerns::Gengou do
using Rubicure::Concerns::Gengou
describe "Date#heisei?" do
subject { date(str).heisei? }
using RSpec::Parameterized::TableSyntax
where(:str, :expected) do
"1989-01-07" | false
"1989-01-08" | true
"2019-04-30" | true
"2019-05-01" | false
end
with_them do
it { should eq expected }
end
end
describe "Date#reiwa?" do
subject { date(str).reiwa? }
using RSpec::Parameterized::TableSyntax
where(:str, :expected) do
"1989-01-07" | false
"1989-01-08" | false
"2019-04-30" | false
"2019-05-01" | true
end
with_them do
it { should eq expected }
end
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/examples/common.rb | examples/common.rb | require "readline"
def run(code)
Readline.readline
code.each_line do |line|
line = line.strip
next if line.empty?
puts "> #{line}"
sleep 5
eval(line) # rubocop:disable Security/Eval
puts ""
sleep 5
end
Readline.readline
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/examples/maho_girls.rb | examples/maho_girls.rb | require "rubicure"
require_relative "common"
code = <<-RUBY
puts Precure.maho_girls.title
@mirai = Cure.miracle
puts @mirai.name
@mirai.cure_up_rapapa! :diamond
puts @mirai.name
@mirai.attack!
@mirai.humanize!
puts @mirai.name
@mirai.cure_up_rapapa! :ruby
puts @mirai.name
@mirai.attack!
RUBY
run code
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/examples/tropical_rouge.rb | examples/tropical_rouge.rb | require "rubicure"
require_relative "common"
code = <<~RUBY
@manatsu = Cure.summer
puts @manatsu.name
@manatsu.precure_tropical_change!
puts @manatsu.name
@manatsu.humanize!
puts @manatsu.name
@manatsu.precure_tropical_change!
puts @manatsu.name
RUBY
run code
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/examples/all.rb | examples/all.rb | # FIXME: NameError: uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger when activesupport < 7.1
require "logger"
require "rubicure"
Precure.each_with_series do |series|
puts <<~MESSAGE
====================
title: #{series.title}
broadcast: #{series.started_date} - #{series.try(:ended_date)}
girls: #{series.girls.count}
MESSAGE
series.girls.each do |girl|
puts <<~MESSAGE
------------------------
human_name: #{girl.human_name}
human_full_name: #{girl.human_full_name}
precure_name: #{girl.precure_name}
cast_name: #{girl.cast_name}
color: #{girl.color}
extra_names: #{girl[:extra_names]}
state_names: #{girl.state_names}
attack_messages: #{girl.attack_messages}
transform_message:
#{girl.transform_message}
MESSAGE
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/ubicure.rb | lib/ubicure.rb | require "rubicure"
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure.rb | lib/rubicure.rb | require "active_support"
require "active_support/core_ext/array/wrap"
require "active_support/core_ext/hash/keys"
require "active_support/core_ext/object/blank"
begin
# workaround for activesupport 7.0.0
# c.f. https://github.com/rails/rails/issues/43851
require "active_support/isolated_execution_state"
rescue LoadError # rubocop:disable Lint/SuppressedException
end
require "active_support/core_ext/time/calculations"
require "yaml"
require "hashie"
require "date"
require "json"
require "rubicure/version"
require "rubicure/concerns/util"
require "rubicure/concerns/gengou"
require "rubicure/series"
require "rubicure/girl"
require "rubicure/core"
require "rubicure/movie"
require "rubicure/cure"
require "rubicure/errors"
require "rubicure/cure_cosmo"
require "rubicure/cure_peace"
require "rubicure/cure_passion"
require "rubicure/cure_beat"
require "rubicure/cure_scarlet"
require "rubicure/cure_finale"
module Precure
def self.method_missing(name, *args, &block)
Rubicure::Core.instance.send(name, *args, &block)
end
def self.respond_to_missing?(name, include_private)
Rubicure::Core.instance.respond_to_missing?(name, include_private)
end
end
module Shiny
# @return [Rubicure::Girl] Shiny luminous
def self.luminous
Rubicure::Girl.find(:luminous)
end
end
module Milky
# @return [Rubicure::Girl] Milky rose
def self.rose
Rubicure::Girl.find(:rose)
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/core.rb | lib/rubicure/core.rb | module Rubicure
require "singleton"
# generic methods
class Core
include Singleton
include Enumerable
include Rubicure::Concerns::Util
Rubicure::Series.names.each do |series_name|
define_method series_name do
Rubicure::Series.find(series_name)
end
end
def method_missing(name, *args)
unmarked_precure = Rubicure::Series.find(:unmarked)
if unmarked_precure.respond_to?(name)
unmarked_precure.send(name, *args)
else
super
end
end
def respond_to_missing?(name, _include_private)
unmarked_precure = Rubicure::Series.find(:unmarked)
unmarked_precure.respond_to?(name)
end
# rubocop:disable Layout/LineLength
# get current precure series
# @return [Rubicure::Series] current precure
#
# @raise [NotOnAirError] not onair!
#
# @example
# Precure.now
# #=> {:series_name=>"go_princess", :title=>"Go!プリンセスプリキュア", :started_date=>Sun, 01 Feb 2015, :girls=>["cure_flora", "cure_mermaid", "cure_twinkle", "cure_scarlet"]}
def now
current_time = Time.now
each_with_series do |series|
return series if series.on_air?(current_time)
end
raise NotOnAirError, "Not on air precure!"
end
# rubocop:enable Layout/LineLength
alias_method :current, :now
# Get precure all stars
#
# @param [Time,Date,String,Symbol] arg Time, Date or date like String (ex. "2013-12-16")
#
# @return [Array<Rubicure::Girl>]
#
# @example precure all stars
# Precure.all_stars.count
# Precure.all_stars.map(&:precure_name)
# # returns current precure count and names
#
# Precure.all_stars.include?(Cure.echo)
# #=> false
#
# Precure.all_stars("2013-10-26").count
# #=> 33
#
# Precure.all_stars(:dx).count
# #=> 14
#
# Precure.all_stars(:dx2).count
# #=> 17
#
# Precure.all_stars(:dx3).count
# #=> 21
#
# Precure.all_stars(:new_stage).count
# #=> 29
# Precure.all_stars(:new_stage).include?(Cure.echo)
# #=> true
#
# Precure.all_stars(:new_stage2).count
# #=> 32
#
# Precure.all_stars(:new_stage3).count
# #=> 37
# Precure.all_stars(:new_stage3).include?(Cure.echo)
# #=> true
#
# Precure.all_stars(:spring_carnival).count
# #=> 40
#
# Precure.all_stars(:sing_together_miracle_magic).count
# #=> 44
# Precure.all_stars(:sing_together_miracle_magic).include?(Cure.echo)
# #=> true
#
# Precure.all_stars(:memories).count
# #=> 55
#
# Precure.all_stars(:f).count
# #=> 78
# Precure.all_stars(:f).include?(Cure.echo)
# #=> false
def all_stars(arg = Time.current)
extra_girls = []
# args is Time or Date
date = to_date(arg)
if date
last_all_stars_date = Rubicure::Movie.find(:stmm).started_date
if date > last_all_stars_date
date = last_all_stars_date
end
else
# args is movie name
movie = Rubicure::Movie.find(arg.to_sym)
date = movie.started_date
if movie.has_key?(:extra_girls)
extra_girls = movie.extra_girls.map {|girl_name| Rubicure::Girl.find(girl_name.to_sym) }
end
end
all_girls(date) - [Cure.echo] + extra_girls
end
# Get all precures
#
# @param [Time,Date] arg Time, Date or date like String (ex. "2013-12-16")
#
# @return [Array<Rubicure::Girl>] all precures
#
# @example
# Precure.all_girls.count
# Precure.all_girls.map(&:precure_name)
# # returns current precure count and names
#
# Precure.all_girls("2013-10-26").count
# #=> 33
#
# Precure.all_girls.include?(Cure.echo)
# #=> true
def all_girls(arg = Time.current)
date = to_date(arg)
unless @all_girls
@all_girls = []
Rubicure::Girl.names.each do |girl_name|
@all_girls << Rubicure::Girl.find(girl_name)
end
@all_girls.uniq!(&:human_name)
end
@all_girls.select {|girl| girl.created_date && girl.created_date <= date }
end
alias_method :all, :all_girls
alias_method :all_members, :all_girls
# Get precure dream stars
#
# @return [Array<Rubicure::Girl>] precure dream stars
#
# @example
# Precure.dream_stars.count
# #=> 12
#
# Precure.dream_stars.map(&:precure_name)
# #=> ["キュアフローラ", "キュアマーメイド", "キュアトゥインクル", "キュアスカーレット", "キュアミラクル", "キュアマジカル", "キュアフェリーチェ", "キュアホイップ", "キュアカスタード", "キュアジェラート", "キュアマカロン", "キュアショコラ"]
def dream_stars
return @dream_stars if @dream_stars
girls = Precure.go_princess.girls + Precure.maho_girls.girls + Precure.a_la_mode.girls
dream_stars_date = Rubicure::Movie.find(:dream_stars).started_date
@dream_stars = girls.select {|girl| girl.created_date && girl.created_date <= dream_stars_date }
@dream_stars
end
# Get precure super stars
#
# @return [Array<Rubicure::Girl>] precure super stars
#
# @example
# Precure.super_stars.count
# #=> 12
#
# Precure.super_stars.map(&:precure_name)
# #=> ["キュアミラクル", "キュアマジカル", "キュアフェリーチェ", "キュアホイップ", "キュアカスタード", "キュアジェラート", "キュアマカロン", "キュアショコラ", "キュアパルフェ", "キュアエール", "キュアアンジュ", "キュアエトワール"]
def super_stars
return @super_stars if @super_stars
girls = Precure.maho_girls.girls + Precure.a_la_mode.girls + Precure.hugtto.girls
super_stars_date = Rubicure::Movie.find(:super_stars).started_date
@super_stars = girls.select {|girl| girl.created_date && girl.created_date <= super_stars_date }
@super_stars
end
alias_method :superstars, :super_stars
# rubocop:disable Layout/LineLength
# Get precure miracle universe
#
# @return [Array<Rubicure::Girl>] precure miracle universe
#
# @example
# Precure.miracle_universe.count
# #=> 15
#
# Precure.miracle_universe.map(&:precure_name)
# #=> ["キュアホイップ", "キュアカスタード", "キュアジェラート", "キュアマカロン", "キュアショコラ", "キュアパルフェ", "キュアエール", "キュアアンジュ", "キュアエトワール", "キュアマシェリ", "キュアアムール", "キュアスター", "キュアミルキー", "キュアソレイユ", "キュアセレーネ"]
def miracle_universe
return @miracle_universe if @miracle_universe
girls = Precure.a_la_mode.girls + Precure.hugtto.girls + Precure.star_twinkle.girls
miracle_universe_date = Rubicure::Movie.find(:miracle_universe).started_date
@miracle_universe = girls.select {|girl| girl.created_date && girl.created_date <= miracle_universe_date }
@miracle_universe
end
# Get precure miracle leap
#
# @return [Array<Rubicure::Girl>] precure miracle leap
#
# @example
# Precure.miracle_leap.count
# #=> 13
#
# Precure.miracle_leap.map(&:precure_name)
# #=> ["キュアエール", "キュアアンジュ", "キュアエトワール", "キュアマシェリ", "キュアアムール", "キュアスター", "キュアミルキー", "キュアソレイユ", "キュアセレーネ", "キュアグレース", "キュアフォンテーヌ", "キュアスパークル"]
def miracle_leap
return @miracle_leap if @miracle_leap
girls = Precure.hugtto.girls + Precure.star_twinkle.girls + Precure.healingood.girls
miracle_leap_date = Rubicure::Movie.find(:miracle_leap).started_date
@miracle_leap = girls.select {|girl| girl.created_date && girl.created_date <= miracle_leap_date }
@miracle_leap.reject! {|girl| girl == Cure.earth }
@miracle_leap
end
# rubocop:enable Layout/LineLength
# iterate with :unmarked, :max_heart, ...
#
# @yield series
# @yieldparam series [Rubicure::Series]
#
# @return [Array<Symbol>] ex. :unmarked, :max_heart, ...
def each_with_series
Rubicure::Series.uniq_names.each do |series_name|
series = Rubicure::Series.find(series_name)
yield series
end
end
alias_method :each, :each_with_series
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/cure.rb | lib/rubicure/cure.rb | module Cure
Rubicure::Girl.names.each do |girl_name|
define_singleton_method girl_name do
Rubicure::Girl.find(girl_name)
end
end
def self.define_turnover_methods(target, original_human_name, another_human_name)
target.instance_variable_set(:@__original_human_name, original_human_name)
target.instance_variable_set(:@__another_human_name, another_human_name)
def target.!
humanize!
@another_human_name ||= @__another_human_name
self[:human_name], @another_human_name = @another_human_name, self[:human_name]
self
end
def target.rollback
self[:human_name] = @__original_human_name
@another_human_name = @__another_human_name
self
end
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/version.rb | lib/rubicure/version.rb | module Rubicure
VERSION = "4.1.5".freeze
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/errors.rb | lib/rubicure/errors.rb | module Rubicure
class NotOnAirError < StandardError; end
class RequireTransformError < StandardError; end
class UnknownMovieError < StandardError; end
class UnknownSeriesError < StandardError; end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/cure_scarlet.rb | lib/rubicure/cure_scarlet.rb | [Cure.scarlet, Cure.cure_scarlet].each do |scarlet|
Cure.define_turnover_methods(scarlet, "紅城トワ", "トワイライト")
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/cure_cosmo.rb | lib/rubicure/cure_cosmo.rb | module Cure
module CosmoExt
def transform!(style = nil)
return super unless style == :rainbow_perfume
humanize!
self[:human_name] = %w[マオ ブルーキャット バケニャーン].sample
print_by_line "レインボーパフュームいくニャン!"
self
end
def rollback
self[:human_name] = "ユニ"
self
end
end
end
[Cure.cosmo, Cure.cure_cosmo].each do |cosmo|
cosmo.singleton_class.prepend(Cure::CosmoExt)
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/movie.rb | lib/rubicure/movie.rb | module Rubicure
# Precure All Stars Movie
#
# this is record of "config/movies.yml"
class Movie < Hash
include Hashie::Extensions::MethodAccess
class << self
include Rubicure::Concerns::Util
# @return [Array<Symbol>]
def names
config.keys
end
# @return [Array<Symbol>]
def uniq_names
uniq_names = []
config.each do |name, series|
uniq_names << name unless uniq_names.any? {|uniq_name| config[uniq_name][:title] == series[:title] }
end
uniq_names
end
# @return [Hash] content of config/movies.yml
def config
unless @config
config_file = "#{File.dirname(__FILE__)}/../../config/movies.yml"
@config = load_yaml_file(config_file).deep_symbolize_keys
end
@config
end
# @return [Hash] content of config/movies.yml
def reload_config!
@cache = {}
@config = nil
config
end
# @param [Symbol] series_name
def valid?(series_name)
names.include?(series_name)
end
# @param movie_name [Symbol]
# @return [Rubicure::Movie]
# @raise arg is invalid
def find(movie_name)
raise UnknownMovieError, "unknown movie: #{movie_name}" unless valid?(movie_name)
@cache ||= {}
unless @cache[movie_name]
movie_config = config[movie_name] || {}
movie_config.compact!
@cache[movie_name] = Rubicure::Movie[movie_config]
end
@cache[movie_name]
end
end
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/cure_peace.rb | lib/rubicure/cure_peace.rb | [Cure.peace, Cure.cure_peace].each do |peace|
class << peace
# rubocop:disable Performance/CollectionLiteralInLoop
HANDS =
(["グー"] * 13) +
(["チョキ"] * 14) +
(["パー"] * 15) +
["グッチョッパー"]
# rubocop:enable Performance/CollectionLiteralInLoop
MESSAGE = <<~JANKEN.freeze
ピカピカピカリン
ジャンケンポン!
(%s)
JANKEN
def pikarin_janken
print_by_line(MESSAGE % HANDS.sample)
end
alias_method :janken, :pikarin_janken
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/cure_finale.rb | lib/rubicure/cure_finale.rb | [Cure.finale, Cure.cure_finale].each do |finale|
Cure.define_turnover_methods(finale, "菓彩あまね", "ジェントルー")
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/cure_passion.rb | lib/rubicure/cure_passion.rb | [Cure.passion, Cure.cure_passion].each do |passion|
Cure.define_turnover_methods(passion, "東せつな", "イース")
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/series.rb | lib/rubicure/series.rb | module Rubicure
# Precure TV series (ex. Smile Precure, Dokidoki Orecure)
# this is record of "config/series.yml"
class Series < Hash
include Hashie::Extensions::MethodAccess
include Rubicure::Concerns::Util
include Enumerable
using Rubicure::Concerns::Gengou
@cache = {}
@config = nil
# @param [Rubicure::Series,Rubicure::Girl] other
#
# @return [Boolean] other is same Rubicure::Series or Rubicure::Series include Rubicure::Girl
def ===(other)
case other
when self.class
self == other
when Rubicure::Girl
girls.include? other
else
false
end
end
# Whether series is on air
#
# @param [Time,Date,String] arg Time, Date or date like String (ex. "2013-12-16")
#
# @return [Boolean]
def on_air?(arg)
date = to_date(arg)
return false unless respond_to?(:started_date)
if respond_to?(:ended_date)
# ended title
(started_date..ended_date).cover?(date)
else
# on air title
started_date <= date
end
end
# @return [Array<Rubicure::Girl>]
def girls
unless @girls
@girls = []
if has_key?(:girls)
fetch(:girls).each do |girl_name|
@girls << Rubicure::Girl.find(girl_name.to_sym)
end
end
end
@girls
end
alias_method :members, :girls
alias_method :each_without_girls, :each
def each(&block)
girls.each(&block)
end
# @return [String] json string
def to_json(*_args)
original_hash = {}
each_without_girls do |k, v|
original_hash[k] = v
end
original_hash.to_json
end
# Whether Heisei precure
def heisei?
started_date.heisei? || ended_date.heisei?
end
# Whether Reiwa precure
def reiwa?
# TODO: Remove after StarTwinkle Precure is finished
return true unless has_key?(:ended_date)
started_date.reiwa? || ended_date.reiwa?
end
class << self
include Rubicure::Concerns::Util
# @return [Array<Symbol>]
def names
config.keys
end
# @return [Array<Symbol>]
def uniq_names
uniq_names = []
config.each do |name, series|
uniq_names << name unless uniq_names.any? {|uniq_name| config[uniq_name][:title] == series[:title] }
end
uniq_names
end
# @return [Hash] content of config/series.yml
def config
unless @config
config_file = "#{File.dirname(__FILE__)}/../../config/series.yml"
@config = load_yaml_file(config_file).deep_symbolize_keys
end
@config
end
# @return [Hash] content of config/precure.yml
def reload_config!
@cache = {}
@config = nil
config
end
# @param [Symbol] series_name
def valid?(series_name)
names.include?(series_name)
end
# @param series_name [Symbol]
# @return [Rubicure::Series]
# @raise arg is not precure
def find(series_name)
raise UnknownSeriesError, "unknown series: #{series_name}" unless valid?(series_name)
@cache ||= {}
unless @cache[series_name]
series_config = config[series_name] || {}
series_config.compact!
@cache[series_name] = Rubicure::Series[series_config]
end
@cache[series_name]
end
end
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/girl.rb | lib/rubicure/girl.rb | module Rubicure
require "sengiri_yaml"
# Precure girl (ex. Cure Peace, Cure Rosetta, Cure Honey)
#
# this is record of "config/girls/*.yml"
class Girl < Hash # rubocop:disable Metrics/ClassLength
include Hashie::Extensions::MethodAccess
using Rubicure::Concerns::Gengou
ATTRIBUTES = [
:girl_name,
:human_name,
:human_full_name,
:precure_name,
:cast_name,
:color,
:created_date,
:birthday,
:transform_message,
:extra_names,
:attack_messages,
:transform_calls,
:random_transform_words,
].freeze
# @return [Integer]
def current_state
@current_state ||= 0
end
# @return [Array<String>]
def state_names
state_names = [human_name, precure_name]
state_names += Array.wrap(extra_names) if respond_to?(:extra_names)
state_names
end
# @return [Boolean]
def ==(other)
other.is_a?(self.class) && self.human_name == other.human_name
end
# @return [String] name of current form
def name
state_names[current_state]
end
alias_method :to_s, :name
# human -> precure ( -> extra forms ) -> human ...
#
# @param style [Symbol]
#
# @return [Rubicure::Girl] self
#
# @example
# yayoi = Cure.peace
#
# yayoi.name
# #=> "黄瀬やよい"
#
# yayoi.transform!
#
# # (レディ?)
# # プリキュア・スマイルチャージ!
# # (ゴー!ゴー!レッツ・ゴー!ピース!!)
# # ピカピカピカリンジャンケンポン! キュアピース!
# # 5つの光が導く未来!
# # 輝け!スマイルプリキュア!
#
# yayoi.name
# #=> "キュアピース"
def transform!(style = nil)
if style
raise "Unknown style: #{style}" unless has_transform_style?(style)
@current_transform_style = style
end
state = inc_current_state
message =
if random_transform_words && !random_transform_words.empty?
random_transform_word = random_transform_words.sample
transform_message.gsub("${random_transform_word}", random_transform_word)
else
transform_message
end
print_by_line message if state == 1
self
end
# Rollback to human
#
# @example
# yayoi = Cure.peace
# yayoi.transform!
# yayoi.name
# #=> "キュアピース"
#
# yayoi.humanize!
# yayoi.name
# #=> "黄瀬やよい"
def humanize!
@current_state = 0
@current_transform_style = nil
self
end
# Attack to enemy
#
# @raise [RequireTransformError] current form is human
#
# @example
# yayoi = Cure.peace
# yayoi.transform!
#
# yayoi.attack!
#
# # プリキュア!ピースサンダー!!
def attack!
raise RequireTransformError, "require transform" if current_attack_message.blank?
print_by_line current_attack_message
current_attack_message
end
# Whether `date` is her birthday
#
# @param date [Date]
#
# @return [Boolean]
#
# @example
# Cure.twinkle.birthday?(Date.parse("2015-9-12"))
# #=> true
def birthday?(date = Date.today)
return false unless have_birthday?
# NOTE: birthday is "mm/dd"
month, day = birthday.split("/")
birthday_date = Date.new(date.year, month.to_i, day.to_i)
birthday_date == date
end
# Whether she has birthday
#
# @return [Boolean]
#
# @example
# Cure.peace.have_birthday?
# #=> false
#
# Cure.twinkle.has_birthday?
# #=> true
def have_birthday? # rubocop:disable Naming/PredicateName
has_key?(:birthday)
end
alias_method :has_birthday?, :have_birthday?
# returns `human_full_name` or `human_name`
#
# @return [String]
def full_name
human_full_name.presence || human_name
end
# Whether Heisei precure
def heisei?
created_date.heisei?
end
# Whether Reiwa precure
def reiwa?
created_date.reiwa?
end
ATTRIBUTES.each do |attribute|
define_method attribute do
if @current_transform_style
dig(:transform_styles, @current_transform_style, attribute) || self[attribute]
else
self[attribute]
end
end
end
class << self
attr_writer :sleep_sec
# @param girl_name [Symbol]
# @return [Rubicure::Girl]
def find(girl_name)
raise "unknown girl: #{girl_name}" unless valid?(girl_name)
@cache ||= {}
unless @cache[girl_name]
girl_config = config[girl_name] || {}
@cache[girl_name] = Rubicure::Girl[girl_config]
end
@cache[girl_name]
end
# @return [Array<Symbol>]
def names
config.keys
end
# @return [Array<Symbol>]
def uniq_names
config.each_with_object([]) do |(name, girl), uniq_names|
uniq_names << name unless uniq_names.any? {|uniq_name| config[uniq_name][:precure_name] == girl[:precure_name] }
end
end
# @return [Hash] content of config/girls/*.yml
def config
unless @config
@config = SengiriYaml.load_dir("#{File.dirname(__FILE__)}/../../config/girls", permitted_classes: [Date], aliases: true).deep_symbolize_keys
end
@config
end
# @return [Hash] content of config/precure.yml
def reload_config!
@cache = {}
@config = nil
@colors = nil
config
end
# @param [Symbol] girl_name
def valid?(girl_name)
names.include?(girl_name)
end
def sleep_sec
@sleep_sec ||= 1
end
# return defined colors
# @return [Array<Symbol>]
def colors
unless @colors
@colors = config.values.each_with_object([]) {|girl, colors| colors << girl[:color].to_sym }.uniq.sort
end
@colors
end
end
colors.each do |color|
define_method :"#{color}?" do
self.color.to_sym == color
end
end
private
def has_transform_style?(style)
return false unless has_key?(:transform_styles)
transform_styles.keys.map(&:to_sym).include?(style.to_sym)
end
def inc_current_state
@current_state = current_state + 1
@current_state = 0 unless @current_state < state_names.length
@current_state
end
def current_attack_message
attack_messages[current_state - 1] if current_state > 0
end
def print_by_line(message)
index = 0
message.each_line do |line|
sleep(self.class.sleep_sec) if index > 0
puts line
index += 1
end
end
def method_missing(method_name, *args)
return super unless respond_to_missing?(method_name, false)
transform!(*args)
end
def respond_to_missing?(method_name, _include_private)
# call Hashie::Extensions::MethodAccess#method_missing
return false if has_key?(method_name)
return false unless has_key?(:transform_calls)
shortened_name = method_name.to_s.
sub(/\Aprecure_|_precure\z/, "").delete_suffix("!")
transform_calls.include?(shortened_name)
end
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/cure_beat.rb | lib/rubicure/cure_beat.rb | [Cure.beat, Cure.cure_beat].each do |beat|
Cure.define_turnover_methods(beat, "黒川エレン", "セイレーン")
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/concerns/gengou.rb | lib/rubicure/concerns/gengou.rb | module Rubicure
module Concerns
module Gengou
refine Date do
# Whether current date is Heisei
def heisei?
Date.new(1989, 1, 8) <= self && self <= Date.new(2019, 4, 30)
end
# Whether current date is Reiwa
def reiwa?
Date.new(2019, 5, 1) <= self
end
end
end
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
sue445/rubicure | https://github.com/sue445/rubicure/blob/07d85d753c2572af29d9a630eb8f0af8ab9e2c3e/lib/rubicure/concerns/util.rb | lib/rubicure/concerns/util.rb | module Rubicure
module Concerns
# utility methods
module Util
# @param arg [Date,Time,String]
#
# @return [Date] arg is String, Date or Time
# @return [nil] arg is other
def to_date(arg)
case arg
when Date
arg
when Time
arg.to_date
when String
begin
Date.parse(arg)
rescue
nil
end
else
nil
end
end
module_function
# @param yaml_file [String]
# @return [Hash]
def load_yaml_file(yaml_file)
YAML.safe_load(File.read(yaml_file), permitted_classes: [Date], aliases: true)
end
end
end
end
| ruby | MIT | 07d85d753c2572af29d9a630eb8f0af8ab9e2c3e | 2026-01-04T17:44:56.245530Z | false |
ConsultingMD/graphql-preload | https://github.com/ConsultingMD/graphql-preload/blob/aedeb86e05525f8b9b2549e07ab0fa975225aa79/test/test_helper.rb | test/test_helper.rb | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'graphql/preload'
require 'minitest/autorun'
| ruby | MIT | aedeb86e05525f8b9b2549e07ab0fa975225aa79 | 2026-01-04T17:44:59.117977Z | false |
ConsultingMD/graphql-preload | https://github.com/ConsultingMD/graphql-preload/blob/aedeb86e05525f8b9b2549e07ab0fa975225aa79/test/graphql/preload_test.rb | test/graphql/preload_test.rb | require 'test_helper'
module GraphQL
class PreloadTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::GraphQL::Preload::VERSION
end
end
end
| ruby | MIT | aedeb86e05525f8b9b2549e07ab0fa975225aa79 | 2026-01-04T17:44:59.117977Z | false |
ConsultingMD/graphql-preload | https://github.com/ConsultingMD/graphql-preload/blob/aedeb86e05525f8b9b2549e07ab0fa975225aa79/lib/graphql/preload.rb | lib/graphql/preload.rb | require 'graphql'
require 'graphql/batch'
require 'promise.rb'
GraphQL::Field.accepts_definitions(
preload: ->(type, *args) do
type.metadata[:preload] ||= []
type.metadata[:preload].concat(args)
end,
preload_scope: ->(type, arg) { type.metadata[:preload_scope] = arg }
)
GraphQL::Schema.accepts_definitions(
enable_preloading: ->(schema) do
schema.instrument(:field, GraphQL::Preload::Instrument.new)
end
)
module GraphQL
# Provides a GraphQL::Field definition to preload ActiveRecord::Associations
module Preload
autoload :Instrument, 'graphql/preload/instrument'
autoload :Loader, 'graphql/preload/loader'
autoload :VERSION, 'graphql/preload/version'
module SchemaMethods
def enable_preloading
instrument(:field, GraphQL::Preload::Instrument.new)
end
end
module FieldMetadata
def initialize(*args, preload: nil, preload_scope: nil, **kwargs, &block)
if preload
@preload ||= []
@preload.concat Array.wrap preload
end
if preload_scope
@preload_scope = preload_scope
end
super(*args, **kwargs, &block)
end
def to_graphql
field_defn = super
field_defn.metadata[:preload] = @preload
field_defn.metadata[:preload_scope] = @preload_scope
field_defn
end
end
end
Schema.extend Preload::SchemaMethods
Schema::Field.prepend Preload::FieldMetadata
end
| ruby | MIT | aedeb86e05525f8b9b2549e07ab0fa975225aa79 | 2026-01-04T17:44:59.117977Z | false |
ConsultingMD/graphql-preload | https://github.com/ConsultingMD/graphql-preload/blob/aedeb86e05525f8b9b2549e07ab0fa975225aa79/lib/graphql/preload/version.rb | lib/graphql/preload/version.rb | module GraphQL
module Preload
VERSION = '2.1.0'.freeze
end
end
| ruby | MIT | aedeb86e05525f8b9b2549e07ab0fa975225aa79 | 2026-01-04T17:44:59.117977Z | false |
ConsultingMD/graphql-preload | https://github.com/ConsultingMD/graphql-preload/blob/aedeb86e05525f8b9b2549e07ab0fa975225aa79/lib/graphql/preload/loader.rb | lib/graphql/preload/loader.rb | module GraphQL
module Preload
# Preloads ActiveRecord::Associations when called from the Preload::Instrument
class Loader < GraphQL::Batch::Loader
attr_accessor :scope
attr_reader :association, :model
def cache_key(record)
record.object_id
end
def initialize(model, association, _scope_sql)
@association = association
@model = model
validate_association
end
def load(record)
unless record.is_a?(model)
raise TypeError, "Loader for #{model} can't load associations for #{record.class} objects"
end
return Promise.resolve(record) if association_loaded?(record)
super
end
def perform(records)
preload_association(records)
records.each { |record| fulfill(record, record) }
end
private def association_loaded?(record)
record.association(association).loaded?
end
private def preload_association(records)
ActiveRecord::Associations::Preloader.new.preload(records, association, preload_scope)
end
private def preload_scope
return nil unless scope
reflection = model.reflect_on_association(association)
raise ArgumentError, 'Cannot specify preload_scope for polymorphic associations' if reflection.polymorphic?
scope if scope.try(:klass) == reflection.klass
end
private def validate_association
unless association.is_a?(Symbol)
raise ArgumentError, 'Association must be a Symbol object'
end
unless model < ActiveRecord::Base
raise ArgumentError, 'Model must be an ActiveRecord::Base descendant'
end
return if model.reflect_on_association(association)
raise TypeError, "Association :#{association} does not exist on #{model}"
end
end
end
end
| ruby | MIT | aedeb86e05525f8b9b2549e07ab0fa975225aa79 | 2026-01-04T17:44:59.117977Z | false |
ConsultingMD/graphql-preload | https://github.com/ConsultingMD/graphql-preload/blob/aedeb86e05525f8b9b2549e07ab0fa975225aa79/lib/graphql/preload/instrument.rb | lib/graphql/preload/instrument.rb | module GraphQL
module Preload
# Provides an instrument for the GraphQL::Field :preload definition
class Instrument
def instrument(_type, field)
metadata = merged_metadata(field)
return field if metadata.fetch(:preload, nil).nil?
old_resolver = field.resolve_proc
new_resolver = ->(obj, args, ctx) do
return old_resolver.call(obj, args, ctx) unless obj
if metadata[:preload_scope]
scope = metadata[:preload_scope].call(args, ctx)
end
is_graphql_object = obj.is_a?(GraphQL::Schema::Object)
respond_to_object = obj.respond_to?(:object)
record = is_graphql_object && respond_to_object ? obj.object : obj
preload(record, metadata[:preload], scope).then do
old_resolver.call(obj, args, ctx)
end
end
field.redefine do
resolve(new_resolver)
end
end
private def preload(record, associations, scope)
if associations.is_a?(String)
raise TypeError, "Expected #{associations} to be a Symbol, not a String"
elsif associations.is_a?(Symbol)
return preload_single_association(record, associations, scope)
end
promises = []
Array.wrap(associations).each do |association|
case association
when Symbol
promises << preload_single_association(record, association, scope)
when Array
association.each do |sub_association|
promises << preload(record, sub_association, scope)
end
when Hash
association.each do |sub_association, nested_association|
promises << preload_single_association(record, sub_association, scope).then do
associated_records = record.public_send(sub_association)
case associated_records
when ActiveRecord::Base
preload(associated_records, nested_association, scope)
else
Promise.all(
Array.wrap(associated_records).map do |associated_record|
preload(associated_record, nested_association, scope)
end
)
end
end
end
end
end
Promise.all(promises)
end
private def preload_single_association(record, association, scope)
# We would like to pass the `scope` (which is an `ActiveRecord::Relation`),
# directly into `Loader.for`. However, because the scope is
# created for each parent record, they are different objects and
# return different loaders, breaking batching.
# Therefore, we pass in `scope.to_sql`, which is the same for all the
# scopes and set the `scope` using an accessor. The actual scope
# object used will be the last one, which shouldn't make any difference,
# because even though they are different objects, they are all
# functionally equivalent.
loader = GraphQL::Preload::Loader.for(record.class, association, scope.try(:to_sql))
loader.scope = scope
loader.load(record)
end
private def merged_metadata(field)
type_class = field.metadata.fetch(:type_class, nil)
if type_class.nil? || !type_class.respond_to?(:to_graphql)
field.metadata
else
field.metadata.merge(type_class.to_graphql.metadata)
end
end
end
end
end
| ruby | MIT | aedeb86e05525f8b9b2549e07ab0fa975225aa79 | 2026-01-04T17:44:59.117977Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/jobs/github_job.rb | app/jobs/github_job.rb | class GithubJob < ActiveJob::Base
queue_as :default
def perform(method, *args)
GithubService.send(method, *args)
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/services/github_service.rb | app/services/github_service.rb | class GithubRateLimitError < RuntimeError; end
class GithubService
class << self
def create_or_update_user(access_token)
client = Octokit::Client.new access_token: access_token
return nil if client.rate_limit.remaining < 10
# Retrieve or update the user
user = User.find_or_create_by(username: client.user[:login])
user.update(access_token: access_token, name: client.user[:name], avatar_url: client.user[:avatar_url])
user
end
def load_repositories(access_token)
# Find user
user = User.find_by_access_token(access_token)
# Create client with token
client = Octokit::Client.new access_token: access_token, auto_paginate: true
return nil if client.rate_limit.remaining < 10
old_repos = user.repositories.pluck(:github_id)
old_orgs = user.organizations.pluck(:name)
current_repos, current_orgs = add_repos(client.repos, user)
# Add repos and remove user from any repos/orgs they no longer have access to
remove_outdated(user, old_repos - current_repos)
remove_outdated_orgs(user, old_orgs - current_orgs)
end
# rubocop:disable ParameterLists
def submit_issue(repo_id, sub_name, email, email_public, title, details)
# Find repo
repo = Repository.find(repo_id)
# Determine title
issue_title = repo.allow_issue_title && !title.empty? ? title : 'Git Reports Issue'
# Create client and check rate limit
client = Octokit::Client.new access_token: repo.access_token
raise GithubRateLimitError if client.rate_limit.remaining < 10
# Create the issue
issue = create_issue(client, repo, issue_title, repo.construct_body(sub_name, email, email_public, details))
# Send notification email
if repo.notification_emails.present?
if repo.include_submitter_email
NotificationMailer.issue_submitted_email(repo.id, issue.number, submitter_name: sub_name, submitter_email: email).deliver_later
else
NotificationMailer.issue_submitted_email(repo.id, issue.number).deliver_later
end
end
issue
end
# rubocop:enable ParameterLists
private
def add_repos(repos, user)
found_repo_ids = []
found_org_names = []
repos.select(&:has_issues).each do |api_repo|
repo_attrs = {
name: api_repo[:name],
owner: api_repo[:owner][:login]
}
if api_repo[:owner][:type] == 'Organization'
org_name = api_repo[:owner][:login]
repo_attrs[:organization] = add_org(org_name, user)
found_org_names << org_name unless found_org_names.include?(org_name)
end
if (repo = Repository.find_by_github_id(api_repo.id))
# Update any information and ensure user is added
repo.update(repo_attrs)
repo.add_user!(user)
found_repo_ids << api_repo.id.to_s
# Else create it
else
repo_attrs.merge!(
github_id: api_repo[:id],
is_active: false,
users: [user]
)
Repository.create(repo_attrs)
end
end
[found_repo_ids, found_org_names]
end
def create_issue(client, repo, title, body)
name = repo.holder_name + '/' + repo.name
issue_name = repo.issue_name.present? ? repo.issue_name : title
labels = { labels: repo.labels.present? ? repo.labels : '' }
client.create_issue(name, issue_name, body, labels)
end
def add_org(org_name, user)
org = Organization.find_or_create_by(name: org_name)
# Make sure it's added to the user
org.add_user!(user)
org
end
def remove_outdated(user, old_ids)
old_ids.each do |github_id|
repo = Repository.find_by_github_id(github_id)
# Delete user from repository
repo.users.delete(user)
# If the repo has no users left, disable it
repo.update(is_active: false) if repo.users.count.zero?
end
end
def remove_outdated_orgs(user, old_names)
user.organizations.delete(Organization.where(name: old_names))
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/helpers/authentications_helper.rb | app/helpers/authentications_helper.rb | module AuthenticationsHelper
def signed_in?
!session[:user_id].nil?
end
def current_user
signed_in? ? User.find(session[:user_id]) : nil
end
def ensure_signed_in!
redirect_to login_path unless signed_in?
end
def ensure_own_repository!
id = params[:id] || params[:repository_id]
if !signed_in?
redirect_to root_path
elsif !Repository.find_by(id: id)
render 'not_found'
elsif !Repository.find(id).users.include?(current_user)
redirect_to profile_path
end
end
def ensure_repository_active!
holder = User.find_by_username(params[:username]) || Organization.find_by_name(params[:username])
if holder.nil?
render 'repositories/not_found'
else
repo = holder.repositories.find_by_name(params[:repositoryname])
render 'repositories/not_found' if repo.nil? || !repo.is_active
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/helpers/layout_helper.rb | app/helpers/layout_helper.rb | module LayoutHelper
TITLE = 'Git Reports'.freeze
DESCRIPTION = 'Git Reports is a free service that lets you set up a stable URL for anonymous users to submit bugs and other Issues to your GitHub repositories.'.freeze
KEYWORDS = 'GitHub, git, issue, report, bug'.freeze
def default_meta
{
description: DESCRIPTION,
keywords: KEYWORDS,
title: TITLE,
icon: '/favicon.ico',
viewport: 'width=device-width, initial-scale=1.0',
og: {
title: TITLE,
url: request.url,
site_name: TITLE,
description: DESCRIPTION,
image: 'https://gitreports.com/images/alarm.png',
type: 'website'
}
}
end
def bootstrap_class_for(flash_type)
case flash_type.to_sym
when :success
'alert-success'
when :error
'alert-danger'
when :notice
'alert-info'
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/helpers/markdown_helper.rb | app/helpers/markdown_helper.rb | module MarkdownHelper
def markdown(content)
@@markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, space_after_headers: true)
@@markdown.render(content)
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/controllers/issues_controller.rb | app/controllers/issues_controller.rb | class IssuesController < ApplicationController
before_action :ensure_repository_active!
def new
@repository = current_resource
# Set each param passed in the URL.
%w[name email email_public issue_title details].each do |p|
instance_variable_set("@#{p}", params[p.intern])
end
# If not specifically overridden to something, keep the email
# public box checked by default.
@email_public = '1' if @email_public.nil?
end
def create
repo = current_resource
# Check the captcha
if pass_captcha?
# Submit issue
GithubJob.perform_later('submit_issue', repo.id, params[:name], params[:email], params[:email_public] == '1', params[:issue_title], params[:details])
# Redirect
redirect_to submitted_path(repo.holder_name, repo.name)
# If invalid, display as such
else
# Redirect
redirect_to repository_public_path(prefill_params.merge(email_public: params[:email_public] || '0')), flash: { error: 'Incorrect CAPTCHA; please retry!' }
end
end
def created
@repository = current_resource
end
private
def prefill_params
params.permit(:username, :repositoryname, :name, :email, :issue_title, :details)
end
def current_resource
holder = User.find_by_username(params[:username]) || Organization.find_by_name(params[:username])
@current_resource ||= holder.repositories.find_by_name(params[:repositoryname])
end
def pass_captcha?
simple_captcha_valid? && (!Rails.env.test? || session[:override_captcha])
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/controllers/authentications_controller.rb | app/controllers/authentications_controller.rb | class AuthenticationsController < ApplicationController
before_action :check_state!, only: [:callback]
def login
redirect_to root_path, flash: { success: 'Already logged in!' } if signed_in?
redirect_to auth_url
end
def callback
delete_state!
# Retrieve access token
error_redirect! unless (access_token = token_request!(params[:code]))
# Create user
rate_limit_redirect! unless (user = GithubService.create_or_update_user(access_token))
# Log in the user
log_in!(user)
# Add repositories
session[:job_id] = GithubJob.perform_later('load_repositories', access_token).provider_job_id
profile_redirect!
end
def logout
log_out!
redirect_to root_path, flash: { notice: 'Logged out!' }
end
def login_rate_limited; end
private
def auth_url
"https://github.com/login/oauth/authorize?client_id=#{ENV['GITHUB_CLIENT_ID']}&" \
"#{{ redirect_uri: ENV['GITHUB_CALLBACK_URL'] }.to_query}&#{{ scope: 'repo' }.to_query}&state=#{state}"
end
def check_state!
redirect_to root_path, flash: { error: 'An error occurred; please try again' } unless params[:state] == state
end
def delete_state!
session.delete(:state)
end
def log_in!(user)
session[:user_id] = user.id
end
def log_out!
session.delete(:user_id)
end
def error_redirect!
redirect_to root_path, flash: { error: 'An error occurred; please try again' }
end
def rate_limit_redirect!
redirect_to login_rate_limited_path
end
def profile_redirect!
redirect_to profile_path(refresh: true), flash: { success: 'Logged in!' }
end
def state
session[:state] ||= SecureRandom.hex
end
def token_request!(code)
# Initialize HTTP library
url = URI.parse('https://github.com')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
# Create the new request
request = Net::HTTP::Post.new('/login/oauth/access_token')
# Add params to request
request.set_form_data(client_id: ENV['GITHUB_CLIENT_ID'], client_secret: ENV['GITHUB_CLIENT_SECRET'], code: code)
# Accept JSON
request['accept'] = 'application/json'
# Make request and return parsed result
response = http.request(request)
response ? JSON.parse(response.body)['access_token'] : nil
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/controllers/repositories_controller.rb | app/controllers/repositories_controller.rb | class RepositoriesController < ApplicationController
before_action :ensure_signed_in!, only: [:index]
before_action :ensure_own_repository!, except: %i[index load_status]
def index
@current_user = current_user
end
def show
@repository = Repository.find(params[:id])
end
def edit
@repository = Repository.find(params[:id])
end
def update
@repository = Repository.find(params[:id])
if @repository.update(repository_params)
redirect_to repository_path(@repository)
else
render 'edit'
end
end
def load_status
render plain: Sidekiq::Status.complete?(session[:job_id])
end
private
def repository_params
params[:repository].permit(:display_name, :issue_name, :prompt, :followup, :labels, :allow_issue_title, :include_submitter_email, :is_active).merge(
notification_emails: parse_emails(params[:repository][:notification_emails]),
allow_issue_title: (params[:repository][:allow_issue_title] == 'yes'),
include_submitter_email: (params[:repository][:include_submitter_email] == 'yes')
)
end
def parse_emails(emails)
valid_emails = []
unless emails.nil?
emails.split(/,|\n/).each do |full_email|
next if full_email.blank?
email = if full_email.index(/\<.+\>/)
full_email.match(/\<.*\>/)[0].gsub(/[\<\>]/, '').strip
else
full_email.strip
end
email = email.delete('<').delete('>')
valid_emails << email if ValidateEmail.valid?(email)
end
end
valid_emails.join(', ')
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/controllers/errors_controller.rb | app/controllers/errors_controller.rb | class ErrorsController < ApplicationController
def error_404
render(status: 404)
end
def error_422
render(status: 422)
end
def error_500
render(status: 500)
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/controllers/application_controller.rb | app/controllers/application_controller.rb | class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include AuthenticationsHelper
include MarkdownHelper
include SimpleCaptcha::ControllerHelpers
around_action :catch_halt
before_action :ensure_production_host
before_action :set_locale
def render(*args)
super
throw :halt
end
def redirect_to(*args)
super
throw :halt
end
protected
def catch_halt
catch :halt do
yield
end
end
private
def ensure_production_host
# Ensure hostname is gitreports.com -- not www or the heroku URL.
return unless %w[gitreports.herokuapp.com www.gitreports.com].include?(request.host)
redirect_to "https://gitreports.com#{request.fullpath}"
end
def set_locale
I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales) || :en
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/models/repository.rb | app/models/repository.rb | class Repository < ApplicationRecord
has_and_belongs_to_many :users, -> { order 'username ASC' }
belongs_to :organization
scope :user_owned, -> { where(organization: nil) }
scope :with_user, ->(user) { joins(:users).where('users.id = ?', user) }
validate :custom_field_length
include HasUniqueUsers
def access_token
users.first.access_token
end
def holder_name
if owner
owner
elsif organization
organization.name
else
users.first.username
end
end
def holder_path
"https://github.com/#{holder_name}"
end
def construct_body(sub_name, email, email_public, details)
body = ''
body += "Submitter: #{sub_name}\r\n" unless sub_name.blank?
body += "Email: #{email}\r\n" if email_public == 'on' && email.present?
body += details unless details.blank?
body
end
def display_or_name
return display_name if display_name.present?
name
end
def github_issues_path
"#{holder_path}/#{name}/issues"
end
def github_issue_path(issue)
"#{github_issues_path}/#{issue}"
end
private
def custom_field_length
%w[display_name issue_name prompt followup].each do |field|
errors[field] << 'must be at least 5 characters' unless send(field).blank? || send(field).length >= 5
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/models/application_record.rb | app/models/application_record.rb | class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/models/organization.rb | app/models/organization.rb | class Organization < ApplicationRecord
has_and_belongs_to_many :users, -> { order 'username ASC' }
has_many :repositories
include HasUniqueUsers
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/models/user.rb | app/models/user.rb | class User < ApplicationRecord
has_and_belongs_to_many :repositories, -> { order 'name ASC' }, uniq: true
has_and_belongs_to_many :organizations, -> { order 'name ASC' }, uniq: true
def github_path
"https://github.com/#{username}"
end
def avatar_url
if self[:avatar_url].blank?
"https://github.com/identicons/#{username}.png"
else
self[:avatar_url]
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/models/concerns/has_unique_users.rb | app/models/concerns/has_unique_users.rb | module HasUniqueUsers
extend ActiveSupport::Concern
included do
def add_user!(user)
return if users.include?(user)
users << user
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/app/mailers/notification_mailer.rb | app/mailers/notification_mailer.rb | class NotificationMailer < ActionMailer::Base
default from: 'no-reply@gitreports.com'
def issue_submitted_email(repo_id, issue_id, submitter_info = {})
@repository = Repository.find(repo_id)
@issue_id = issue_id
@subject = "New Issue Submitted to #{@repository.name}"
if submitter_info[:submitter_name].present? && submitter_info[:submitter_email].present?
@subject = "#{@subject} by #{submitter_info[:submitter_name]}: #{submitter_info[:submitter_email]}"
end
mail to: @repository.notification_emails, subject: @subject
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/seeds.rb | db/seeds.rb | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/schema.rb | 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: 20170731231431) do
create_table "organizations", force: :cascade do |t|
t.string "name", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "organizations_users", force: :cascade do |t|
t.integer "organization_id"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "repositories", force: :cascade do |t|
t.string "github_id", limit: 255
t.string "name", limit: 255
t.string "display_name", limit: 255
t.string "issue_name", limit: 255
t.text "prompt"
t.text "followup"
t.string "labels", limit: 255
t.boolean "is_active"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "organization_id"
t.string "owner", limit: 255
t.string "notification_emails", limit: 255
t.boolean "allow_issue_title", default: false
t.boolean "include_submitter_email", default: false
end
create_table "repositories_users", force: :cascade do |t|
t.integer "repository_id"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "simple_captcha_data", force: :cascade do |t|
t.string "key", limit: 40
t.string "value", limit: 6
t.datetime "created_at"
t.datetime "updated_at"
t.index ["key"], name: "idx_key"
end
create_table "users", force: :cascade do |t|
t.string "username", limit: 255
t.string "name", limit: 255
t.string "avatar_url", limit: 255
t.string "access_token", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "is_admin", default: false
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20131214192504_remove_extraneous_user_columns.rb | db/migrate/20131214192504_remove_extraneous_user_columns.rb | class RemoveExtraneousUserColumns < ActiveRecord::Migration[4.2]
def change
remove_column :organizations, :user_id
remove_column :repositories, :user_id
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20131127214430_create_users.rb | db/migrate/20131127214430_create_users.rb | class CreateUsers < ActiveRecord::Migration[4.2]
def change
create_table :users do |t|
t.string :username
t.string :name
t.string :gravatar_id
t.string :access_token
t.timestamps
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20131201025805_create_organizations.rb | db/migrate/20131201025805_create_organizations.rb | class CreateOrganizations < ActiveRecord::Migration[4.2]
def change
create_table :organizations do |t|
t.belongs_to :user
t.string :name
t.timestamps
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20141130172103_change_gravatar_id_to_avatar.rb | db/migrate/20141130172103_change_gravatar_id_to_avatar.rb | class ChangeGravatarIdToAvatar < ActiveRecord::Migration[4.2]
def up
User.where.not(gravatar_id: '').each do |user|
user.update!(gravatar_id: "https://gravatar.com/avatar/#{user.gravatar_id}?s=96")
end
rename_column :users, :gravatar_id, :avatar_url
end
def down
User.update_all(avatar_url: '')
rename_column :users, :avatar_url, :gravatar_id
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20150705225028_add_issue_title_to_repositories.rb | db/migrate/20150705225028_add_issue_title_to_repositories.rb | class AddIssueTitleToRepositories < ActiveRecord::Migration[4.2]
def change
add_column :repositories, :allow_issue_title, :boolean, default: false
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20141130233032_add_notification_emails_to_repositories.rb | db/migrate/20141130233032_add_notification_emails_to_repositories.rb | class AddNotificationEmailsToRepositories < ActiveRecord::Migration[4.2]
def change
add_column :repositories, :notification_emails, :string
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20150506175412_add_is_admin_to_users.rb | db/migrate/20150506175412_add_is_admin_to_users.rb | class AddIsAdminToUsers < ActiveRecord::Migration[4.2]
def change
add_column :users, :is_admin, :boolean, default: false
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20131127220659_create_repositories.rb | db/migrate/20131127220659_create_repositories.rb | class CreateRepositories < ActiveRecord::Migration[4.2]
def change
create_table :repositories do |t|
t.belongs_to :user
t.string :github_id
t.string :name
t.string :display_name
t.string :issue_name
t.text :prompt
t.text :followup
t.string :labels
t.boolean :is_active
t.timestamps
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20140329105826_create_simple_captcha_data.rb | db/migrate/20140329105826_create_simple_captcha_data.rb | class CreateSimpleCaptchaData < ActiveRecord::Migration[4.2]
def self.up
create_table :simple_captcha_data do |t|
t.string :key, limit: 40
t.string :value, limit: 6
t.timestamps
end
add_index :simple_captcha_data, :key, name: 'idx_key'
end
def self.down
drop_table :simple_captcha_data
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20170730214412_cleanup_duplicate_users.rb | db/migrate/20170730214412_cleanup_duplicate_users.rb | class CleanupDuplicateUsers < ActiveRecord::Migration[5.1]
def up
User.order(id: :asc).pluck(:id).each do |id|
user = User.find_by(id: id)
next if user.nil? # skip if user has already been de-duped
dupes = User.where(username: user.username).where.not(id: id)
next if dupes.none? # skip if there are no dupes
# Ensure user is added to each org/repo that a dupe has,
# then destroy the dupe.
dupes.each do |dupe|
dupe.repositories.each do |repo|
repo.add_user!(user)
end
dupe.organizations.each do |org|
org.add_user!(user)
end
dupe.destroy
end
end
end
def down; end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20131214181227_create_repositories_users.rb | db/migrate/20131214181227_create_repositories_users.rb | class CreateRepositoriesUsers < ActiveRecord::Migration[4.2]
def change
create_table :repositories_users do |t|
t.belongs_to :repository
t.belongs_to :user
t.timestamps
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20170731231431_add_include_submitter_email_to_repositories.rb | db/migrate/20170731231431_add_include_submitter_email_to_repositories.rb | class AddIncludeSubmitterEmailToRepositories < ActiveRecord::Migration[5.1]
def change
add_column :repositories, :include_submitter_email, :boolean, default: false
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20141022145432_add_owner_to_repositories.rb | db/migrate/20141022145432_add_owner_to_repositories.rb | class AddOwnerToRepositories < ActiveRecord::Migration[4.2]
def change
add_column :repositories, :owner, :string
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20131201034024_create_organizations_users.rb | db/migrate/20131201034024_create_organizations_users.rb | class CreateOrganizationsUsers < ActiveRecord::Migration[4.2]
def change
create_table :organizations_users do |t|
t.belongs_to :organization
t.belongs_to :user
t.timestamps
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/db/migrate/20131201025921_add_organization_to_repository.rb | db/migrate/20131201025921_add_organization_to_repository.rb | class AddOrganizationToRepository < ActiveRecord::Migration[4.2]
def change
change_table :repositories do |t|
t.belongs_to :organization
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/spec_helper.rb | spec/spec_helper.rb | require 'simplecov'
SimpleCov.start 'rails' do
add_group 'Services', '/services/'
end
ENV['RAILS_ENV'] = 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'
require 'capybara/poltergeist'
require 'webmock/rspec'
require 'rack_session_access/capybara'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
# Include ActiveJob helper methods
config.include ActiveJob::TestHelper
# Include FactoryGirl helper methods
config.include FactoryGirl::Syntax::Methods
# Include SessionHelper methods
config.include Features::SessionHelpers, type: :feature
config.include Controllers::SessionHelpers, type: :controller
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
# Set up Capybara
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app)
end
Capybara.configure do |capy|
capy.javascript_driver = :poltergeist
capy.server_port = 5000
end
config.before(:suite) do
WebMock.disable_net_connect!(allow_localhost: true)
DatabaseCleaner.clean_with :truncation
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
# Stub GitHub requests
config.before(:each) do
stub_request(:any, /github.com/).to_rack(FakeGitHub)
end
# Ensure ActiveJob is empty
config.after(:each) do
clear_enqueued_jobs
end
# Start webpack server if needed.
config.add_setting :webpack_dev_server_pid
config.when_first_matching_example_defined(:needs_assets) do
# Start webpack-dev-server unless in CI or it is already running
next if ENV['CI'] == 'true' || system('lsof -i:3808', out: '/dev/null')
config.webpack_dev_server_pid = fork do
puts 'Child process starting webpack-dev-server...'
exec 'TARGET=development webpack-dev-server --config config/webpack.babel.js --quiet'
end
end
config.after(:suite) do
next unless config.webpack_dev_server_pid
puts 'Killing webpack-dev-server'
Process.kill('HUP', config.webpack_dev_server_pid)
begin
Timeout.timeout(2) do
Process.wait(config.webpack_dev_server_pid, 0)
end
rescue Timeout::Error
Process.kill(9, config.webpack_dev_server_pid)
ensure
config.webpack_dev_server_pid = nil
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/jobs/github_job_spec.rb | spec/jobs/github_job_spec.rb | describe GithubJob do
subject { GithubJob.new.perform(method, *args) }
let(:method) { 'load_repositories' }
let(:args) { ['123'] }
it 'calls provided method with provided args' do
expect(GithubService).to receive('load_repositories').with('123')
subject
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/services/github_service_spec.rb | spec/services/github_service_spec.rb | describe GithubService do
describe '#create_or_update_user' do
subject { GithubService.create_or_update_user(access_token) }
end
describe '#load_repositories' do
subject { GithubService.load_repositories('access') }
context 'first user login' do
let!(:user) { GithubService.create_or_update_user('access') }
before { subject }
it('adds user to org') do
expect(user.organizations.first.name).to eq('CoolOrg')
end
end
context 'org repos exist' do
let!(:user) { create :user, access_token: 'access' }
let!(:org) { create :organization, name: 'neatorg' }
let!(:org_repo) { create :repository, name: 'OldOrgCode', organization: org, users: [user] }
let!(:existing_org_repo) { create :repository, name: 'NeatOrgStuff', github_id: 5_705_826, organization: org, users: [user] }
before do
GithubService.create_or_update_user('access')
subject
end
it 'removes outdated org repository' do
expect(user.repositories.find_by_name('OldOrgCode')).to eq(nil)
end
it 'updates org repository with new information' do
expect(user.repositories.find_by_name('NeatOrgCode')).not_to eq(nil)
end
end
context 'user repos exist' do
let!(:org) { create :organization }
let!(:user) { create :user, access_token: 'access', organizations: [org] }
let!(:repository) { create :user_repository, name: 'OldCode', users: [user] }
let!(:existing_repo) { create :user_repository, name: 'NeatCode', github_id: 5_705_827, users: [user] }
let!(:unlinked_repo) { create :user_repository, name: 'PrettyProject', github_id: 19_548_054 }
let!(:unlinked_org_repo) { create :repository, name: 'NeatOrgProject', github_id: 19_548_055 }
before { subject }
it 'adds existing repository to user' do
expect(user.repositories.find_by_name('PrettyProject')).not_to eq(nil)
end
it 'adds existing org repository to user' do
expect(user.repositories.find_by_name('NeatOrgProject')).not_to eq(nil)
end
it 'updates user repository with new name' do
expect(user.repositories.find_by_name('CoolCode')).not_to eq(nil)
end
it 'deletes outdated user repository' do
expect(user.repositories.find_by_name('OldCode')).to eq(nil)
end
end
context 'user repo exists but is not owned by the user' do
let!(:org) { create :organization }
let!(:user) { create :user, access_token: 'access', organizations: [org] }
let!(:repository) { create :user_repository, name: 'NeatOrgProject', github_id: 19_548_055, users: [user], owner: [org.name] }
before { subject }
it 'leaves user on the repository' do
expect(user.repositories.find_by_name('NeatOrgProject')).not_to eq(nil)
end
end
context 'user is removed from a repo with another user on it' do
let!(:user) { create :user, access_token: 'access' }
let!(:another_user) { create :user }
let!(:repository) { create :user_repository, name: 'SharedCode', users: [user, another_user] }
before { subject }
it 'removes the user from the repository' do
expect(user.repositories.find_by_name('SharedCode')).to eq(nil)
end
it 'leaves the repository and other user intact' do
expect(another_user.repositories.find_by_name('SharedCode')).not_to eq(nil)
end
end
context 'user is removed from an org with another user in it' do
let!(:org) { create :organization, name: 'NeatOrg' }
let!(:user) { create :user, access_token: 'access', organizations: [org] }
let!(:another_user) { create :user, organizations: [org] }
let!(:repository) { create :user_repository, name: 'SharedOrgCode', organization: org, users: [user, another_user] }
before { subject }
it 'removes the user from the org' do
expect(user.organizations.find_by_name('NeatOrg')).to eq(nil)
end
it 'leaves the other user in the org' do
expect(another_user.organizations.find_by_name('NeatOrg')).not_to eq(nil)
end
it 'removes the user from the org repository' do
expect(user.repositories.find_by_name('SharedOrgCode')).to eq(nil)
end
it 'leaves the org repository intact' do
expect(org.repositories.find_by_name('SharedOrgCode')).not_to eq(nil)
end
it 'leaves the other user on the org repository' do
expect(repository.users.find(another_user.id)).not_to eq(nil)
end
end
end
describe '#submit_issue' do
let!(:user) { create :user }
subject { GithubService.submit_issue(repository.id, 'Bob', 'bob@email.com', false, nil, "I'm having a problem with this.") }
context 'repository has configured notification mails' do
let!(:repository) { create :repository, users: [user], notification_emails: 'joe@email.com' }
it 'creates the issue and sends notification' do
issue = subject
expect(issue['body']).to eq("I'm having a problem with this.")
# Should have queued notification mail
expect(enqueued_jobs.size).to eq(1)
expect(enqueued_jobs.first[:job]).to eq(ActionMailer::DeliveryJob)
expect(enqueued_jobs.first[:args]).to eq(['NotificationMailer', 'issue_submitted_email', 'deliver_now', 1, 1347])
end
end
context 'repository has configured notification mails and includes submitters emails in said notifications' do
let!(:repository) { create :repository, users: [user], notification_emails: 'joe@email.com', include_submitter_email: true }
it 'creates the issue and sends notification' do
issue = subject
expect(issue['body']).to eq("I'm having a problem with this.")
# Should have queued notification mail
expect(enqueued_jobs.size).to eq(1)
expect(enqueued_jobs.first[:job]).to eq(ActionMailer::DeliveryJob)
expect(enqueued_jobs.first[:args]).to eq(['NotificationMailer', 'issue_submitted_email', 'deliver_now', 1, 1347,
'submitter_name' => 'Bob', 'submitter_email' => 'bob@email.com', '_aj_symbol_keys' => %w[submitter_name submitter_email]])
end
end
context 'repository has not configured notification mails' do
let!(:repository) { create :repository, users: [user] }
it 'creates the issue and sends no notification' do
issue = subject
expect(issue['body']).to eq("I'm having a problem with this.")
# Should have queued notification mail
expect(enqueued_jobs.size).to eq(0)
end
end
context 'custom title submitted' do
subject { GithubService.submit_issue(repository.id, 'Bob', 'bob@email.com', false, 'Custom Title', "I'm having a problem with this.") }
context 'repository has enabled custom issue title' do
let!(:repository) { create :repository, users: [user], allow_issue_title: true }
it 'uses custom title' do
issue = subject
expect(issue['title']).to eq('Custom Title')
end
end
context 'repository has not enabled custom issue title' do
let!(:repository) { create :repository, users: [user] }
it 'ignores custom title' do
issue = subject
expect(issue['title']).to eq('Git Reports Issue')
end
end
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/support/feature_session_helpers.rb | spec/support/feature_session_helpers.rb | module Features
module SessionHelpers
def log_in(user = create!(:user))
page.set_rack_session(user_id: user.id)
end
def override_captcha(value)
page.set_rack_session(override_captcha: value)
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/support/controller_session_helpers.rb | spec/support/controller_session_helpers.rb | module Controllers
module SessionHelpers
def log_in(user = create!(:user))
session[:user_id] = user.id
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/support/fake_github.rb | spec/support/fake_github.rb | require 'sinatra/base'
require 'json'
class FakeGitHub < Sinatra::Base
post '/login/oauth/access_token' do
if rate_limit_expired
json_response 200, access_token: 'rate_limit_expired'
elsif access_fail
json_response 500, access_token: nil
else
json_response 200, access_token: 'access'
end
end
get '/user' do
json_response 200, 'user.json'
end
get '/user/repos' do
json_response 200, 'repos.json'
end
get '/user/orgs' do
json_response 200, 'organization.json'
end
get '/rate_limit' do
headers = {}
headers['X-RateLimit-Limit'] = '5000'
if rate_limit_expired
headers['X-RateLimit-Remaining'] = '0'
headers['X-RateLimit-Reset'] = '1500000000'
json_response 200, 'rate_limit_exp.json', headers
else
headers['X-RateLimit-Remaining'] = '4999'
headers['X-RateLimit-Reset'] = '1372700873'
json_response 200, 'rate_limit.json', headers
end
end
post '/repos/:username/:repository/issues' do
body = JSON.parse(request.body.string)
overrides = body['title'] == 'Custom Title' ? { 'Git Reports Issue' => 'Custom Title' } : {}
json_response 201, 'issue.json', nil, overrides
end
private
def access_fail
params[:code] == 'access_fail'
end
def rate_limit_expired
request.env['HTTP_AUTHORIZATION'] == 'token rate_limit_expired' || params[:code] == 'rate_limit_expired'
end
def json_response(response_code, content, headers = nil, overrides = {})
content_type :json
status response_code
headers&.each do |k, v|
response[k] = v
end
if content.is_a? Hash
content.to_json
else
response_json = File.open(File.expand_path('../../', __FILE__) + '/fixtures/' + content, 'rb').read
# Replace any overrides in the JSON.
overrides.each { |k, v| response_json.gsub!(k, v) }
response_json
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/factories/users.rb | spec/factories/users.rb | FactoryGirl.define do
factory :user do
username { Faker::Internet.user_name nil, %w[_] }
name { Faker::Name.name }
avatar_url { "https://github.com/identicons/#{username}.png" }
access_token { Faker::Bitcoin.address }
repositories { [] }
organizations { [] }
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/factories/organizations.rb | spec/factories/organizations.rb | FactoryGirl.define do
factory :organization do
name { Faker::Lorem.word }
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/factories/repositories.rb | spec/factories/repositories.rb | FactoryGirl.define do
factory :repository do
github_id { Faker::Bitcoin.address }
name { Faker::Lorem.characters(10) }
is_active true
display_name ''
prompt ''
followup ''
owner { Faker::Internet.user_name }
organization
users { [] }
allow_issue_title false
factory :user_repository do
organization nil
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/controllers/errors_controller_spec.rb | spec/controllers/errors_controller_spec.rb | describe ErrorsController do
describe '#error_404' do
subject { get :error_404 }
it 'returns 404 response' do
expect(subject).to have_http_status(:not_found)
expect(subject).to render_template(:error_404)
end
end
describe '#error_422' do
subject { get :error_422 }
it 'returns 422 response' do
expect(subject).to have_http_status(:unprocessable_entity)
expect(subject).to render_template(:error_422)
end
end
describe '#error_500' do
subject { get :error_500 }
it 'returns 500 response' do
expect(subject).to have_http_status(:internal_server_error)
expect(subject).to render_template(:error_500)
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/controllers/repositories_controller_spec.rb | spec/controllers/repositories_controller_spec.rb | describe RepositoriesController do
let!(:organization) { create :organization }
let!(:user) { create :user }
let!(:org_user) { create :user, organizations: [organization] }
let!(:another_user) { create :user }
describe '#load_status' do
subject { get :load_status }
context 'job ID does not exist' do
it 'returns false' do
expect(subject.body).to eq('false')
end
end
context 'job ID is set' do
before { session[:job_id] = 1 }
it 'checks job status' do
expect(subject.body).to eq('false')
end
end
end
describe '#show' do
let!(:repository) { create :user_repository, users: [user] }
let!(:org_repository) { create :repository, organization: organization, users: [org_user] }
context 'repository owner logged in' do
before { log_in user }
subject { get :show, params: { id: repository } }
it 'shows the repository' do
expect(subject).to render_template(:show)
end
end
context 'org user logged in' do
before { log_in org_user }
subject { get :show, params: { id: org_repository } }
it 'shows the repository' do
expect(subject).to render_template(:show)
end
end
context 'another user logged in' do
before { log_in another_user }
subject { get :show, params: { id: repository } }
it 'does not show the repository' do
expect(subject).to redirect_to(profile_path)
end
end
context 'repo does not exist' do
before { log_in another_user }
subject { get :show, params: { id: 0 } }
it 'renders 404' do
expect(subject).to render_template('not_found')
end
end
end
describe '#edit' do
let!(:repository) { create :user_repository, users: [user] }
let!(:org_repository) { create :repository, organization: organization, users: [org_user] }
context 'repository owner logged in' do
before { log_in user }
subject { get :edit, params: { id: repository } }
it 'shows the repository' do
expect(subject).to render_template(:edit)
end
end
context 'org user logged in' do
before { log_in org_user }
subject { get :edit, params: { id: org_repository } }
it 'shows the repository' do
expect(subject).to render_template(:edit)
end
end
context 'another user logged in' do
before { log_in another_user }
subject { get :edit, params: { id: repository } }
it 'does not show the repository' do
expect(subject).to redirect_to(profile_path)
end
end
context 'repo does not exist' do
before { log_in another_user }
subject { get :edit, params: { id: 0 } }
it 'renders 404' do
expect(subject).to render_template('not_found')
end
end
end
describe '#update' do
let!(:repository) { create :user_repository, is_active: false, users: [user] }
let!(:org_repository) { create :repository, is_active: false, organization: organization, users: [org_user] }
context 'repository owner logged in' do
before { log_in user }
subject { patch :update, params: { id: repository, repository: { is_active: true } } }
it 'activates the repository' do
expect(subject).to redirect_to(repository_path(repository))
end
end
context 'org user logged in' do
before { log_in org_user }
subject { patch :update, params: { id: org_repository, repository: { is_active: true } } }
it 'activates the repository' do
expect(subject).to redirect_to(repository_path(org_repository))
end
end
context 'another user logged in' do
before { log_in another_user }
subject { patch :update, params: { id: repository, repository: { is_active: true } } }
it 'does not allow activation' do
expect(subject).to redirect_to(profile_path)
end
end
context 'repo does not exist' do
before { log_in another_user }
subject { patch :update, params: { id: 0, repository: { is_active: true } } }
it 'renders 404' do
expect(subject).to render_template('not_found')
end
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/controllers/authentications_controller_spec.rb | spec/controllers/authentications_controller_spec.rb | describe AuthenticationsController do
describe '#login' do
let!(:user) { create :user }
subject { get :login }
context 'user is not logged in' do
it 'redirects to login url' do
expect(subject).to redirect_to(%r{\Ahttps://github.com/login/oauth/authorize})
end
end
context 'user is already logged in' do
before { log_in(user) }
it 'redirects home' do
expect(subject).to redirect_to(root_path)
end
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/models/repository_spec.rb | spec/models/repository_spec.rb | describe Repository do
it_behaves_like 'has unique users'
describe '#holder_name' do
context 'owner field is set' do
subject { create :repository, owner: 'greptest' }
it 'returns owner field' do
expect(subject.holder_name).to eq('greptest')
end
end
context 'repository is in an organization' do
let!(:organization) { create :organization, name: 'CoolOrg' }
subject { create :repository, owner: nil, organization: organization }
it 'returns organization name' do
expect(subject.holder_name).to eq('CoolOrg')
end
end
context 'repository is a user repository' do
let!(:user) { create :user, username: 'joeschmoe' }
subject { create :user_repository, owner: nil, users: [user] }
it 'returns user\'s username' do
expect(subject.holder_name).to eq('joeschmoe')
end
end
end
describe '#github_issue_path' do
context 'owner field is set' do
subject { create :repository, name: 'greprepo', owner: 'greptest' }
it 'returns url with owner login' do
expect(subject.github_issue_path(1)).to eq('https://github.com/greptest/greprepo/issues/1')
end
end
context 'repository is in an organization' do
let!(:organization) { create :organization, name: 'CoolOrg' }
subject { create :repository, name: 'CoolRepo', owner: nil, organization: organization }
it 'returns url with organization name' do
expect(subject.github_issue_path(1)).to eq('https://github.com/CoolOrg/CoolRepo/issues/1')
end
end
context 'repository is a user repository' do
let!(:user) { create :user, username: 'joeschmoe' }
subject { create :user_repository, name: 'joerepo', owner: nil, users: [user] }
it 'returns url with user\'s username' do
expect(subject.github_issue_path(1)).to eq('https://github.com/joeschmoe/joerepo/issues/1')
end
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/models/organization_spec.rb | spec/models/organization_spec.rb | describe Organization do
it_behaves_like 'has unique users'
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/models/user_spec.rb | spec/models/user_spec.rb | describe User do
describe '#avatar_url' do
context 'avatar url is blank' do
subject { create :user, username: 'joeschmoe', avatar_url: nil }
it 'returns identicon url' do
expect(subject.avatar_url).to eq('https://github.com/identicons/joeschmoe.png')
end
end
context 'avatar url is populated' do
subject { create :user, username: 'joeschmoe', avatar_url: 'https://github.com/some_other_url/joeschmoe.png' }
it 'returns avatar url' do
expect(subject.avatar_url).to eq('https://github.com/some_other_url/joeschmoe.png')
end
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/models/concerns/has_unique_users_spec.rb | spec/models/concerns/has_unique_users_spec.rb | shared_examples_for 'has unique users' do
let(:model) { described_class }
let(:user) { create :user }
let(:repository) { create :repository, users: users }
subject { repository.add_user! user }
context 'users include user' do
let(:users) { [user] }
it 'does not add duplicate' do
expect { subject }.not_to change { repository.users.count }.from(1)
end
end
context 'users do not include user' do
let(:users) { [] }
it 'adds user' do
expect { subject }.to change { repository.users.count }.from(0).to(1)
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/features/authentications_feature_spec.rb | spec/features/authentications_feature_spec.rb | feature 'Authentication', :needs_assets do
describe 'login and get repositories from API' do
let!(:state) { SecureRandom.hex }
before do
page.set_rack_session(state: state)
end
context 'state is incorrect' do
scenario 'does not log in' do
visit "/github_callback?state=wrongstate&code=#{SecureRandom.hex}"
expect(page).to have_content('An error occurred; please try again')
end
end
context 'rate limit is expired' do
scenario 'shows rate limited page' do
visit "/github_callback?state=#{state}&code=rate_limit_expired"
expect(page).to have_content('Git Reports is currently experiencing heavy traffic.')
end
end
context 'access token request fails' do
scenario 'shows error message' do
visit "/github_callback?state=#{state}&code=access_fail"
expect(page).to have_content('An error occurred; please try again')
end
end
context 'first user login' do
scenario 'logs in the user' do
visit "/github_callback?state=#{state}&code=#{SecureRandom.hex}"
expect(page).to have_content('Logged in!')
# Should have queued repository update
expect(enqueued_jobs.size).to eq(1)
end
end
end
describe 'logout' do
let!(:user) { create :user, name: 'Joe Schmoe' }
context 'user is logged in' do
before { log_in user }
scenario 'logs out the user' do
visit logout_path
expect(page).to have_content('Login')
expect(page).not_to have_content('Joe Schmoe')
end
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/features/repositories_feature_spec.rb | spec/features/repositories_feature_spec.rb | feature 'Repository', :needs_assets do
let!(:organization) { create :organization }
let!(:user) { create :user, username: 'greptest' }
let!(:org_user) { create :user, organizations: [organization] }
let!(:another_user) { create :user }
let!(:repository) { create :user_repository, name: 'CoolCode', owner: user.username, users: [user] }
let!(:org_repository) { create :repository, name: 'CoolOrg', organization: organization, users: [org_user] }
let!(:inactive_repository) { create :repository, name: 'CoolInactive', is_active: false, users: [user] }
describe 'edit repository' do
context 'repository owner logged in' do
before do
log_in user
visit profile_path
end
context 'invalid fields' do
scenario 'shows errors' do
click_on 'CoolCode'
click_on 'Edit'
fill_in 'Display name', with: 'Shrt'
click_on 'Update'
expect(page).to have_content('Display name must be at least 5 characters')
fill_in 'Display name', with: 'The Coolest'
fill_in 'Issue name', with: 'Shrt'
click_on 'Update'
expect(page).to have_content('Issue name must be at least 5 characters')
fill_in 'Issue name', with: 'Big problems!'
fill_in 'Prompt', with: 'Shrt'
click_on 'Update'
expect(page).to have_content('Prompt must be at least 5 characters')
fill_in 'Prompt', with: 'Tell us what is wrong'
fill_in 'Followup', with: 'Shrt'
click_on 'Update'
expect(page).to have_content('Followup must be at least 5 characters')
end
end
context 'valid fields' do
scenario 'edits the repository' do
click_on 'CoolCode'
click_on 'Edit'
fill_in 'Display name', with: 'The Coolest'
fill_in 'Issue name', with: 'Big problems!'
fill_in 'Prompt', with: 'Tell us what is wrong'
fill_in 'Followup', with: 'Thanks!'
fill_in 'Labels', with: 'problem'
fill_in 'Notification emails', with: 'valid@email.com, invalid@email, Joe Smith <joe@email.com>'
click_on 'Update'
expect(page).to have_content('The Coolest')
expect(page).to have_content('Big problems!')
expect(page).to have_content('Tell us what is wrong')
expect(page).to have_content('Thanks!')
expect(page).to have_content('problem')
expect(page).to have_content('valid@email.com')
expect(page).not_to have_content('invalid@email')
expect(page).not_to have_content('Joe Smith')
expect(page).to have_content('joe@email.com')
end
end
end
context 'org user logged in' do
before do
log_in org_user
visit profile_path
end
scenario 'edits the repository' do
click_on 'CoolOrg'
click_on 'Edit'
fill_in 'Display name', with: 'The Coolest'
fill_in 'Issue name', with: 'Big problems!'
fill_in 'Prompt', with: 'Tell us what is wrong'
fill_in 'Followup', with: 'Thanks!'
fill_in 'Labels', with: 'problem'
fill_in 'Notification emails', with: 'valid@email.com, invalid@email'
choose 'repository_allow_issue_title_yes'
click_on 'Update'
expect(page).to have_content('The Coolest')
expect(page).to have_content('Big problems!')
expect(page).to have_content('Tell us what is wrong')
expect(page).to have_content('Thanks!')
expect(page).to have_content('problem')
expect(page).to have_content('valid@email.com')
expect(page).not_to have_content('invalid@email')
expect(page).to have_content('Yes: Users are permitted to set the issue title on GitHub.')
end
end
context 'another user logged in' do
before { log_in another_user }
scenario 'does not permit editing' do
visit edit_repository_path(repository)
expect(page).not_to have_content('Update Repository')
end
end
context 'nobody logged in' do
scenario 'does not permit editing' do
visit edit_repository_path(repository)
expect(page).not_to have_content('Update Repository')
end
end
end
describe 'activates and deactivates repository' do
context 'repository owner logged in' do
before do
log_in user
visit profile_path
end
scenario 'deactivates and reactivates the repository' do
click_on 'CoolCode'
expect(page).to have_content('Status: Active')
click_on 'Deactivate'
expect(page).to have_content('Status: Inactive')
click_on 'Activate'
expect(page).to have_content('Status: Active')
end
end
context 'org user logged in' do
before do
log_in org_user
visit profile_path
end
scenario 'edits the repository' do
click_on 'CoolOrg'
expect(page).to have_content('Status: Active')
click_on 'Deactivate'
expect(page).to have_content('Status: Inactive')
click_on 'Activate'
expect(page).to have_content('Status: Active')
end
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/features/issues_feature_spec.rb | spec/features/issues_feature_spec.rb | feature 'Issue', :needs_assets do
let!(:organization) { create :organization }
let!(:user) { create :user, username: 'greptest' }
let!(:org_user) { create :user, organizations: [organization] }
let!(:another_user) { create :user }
let!(:repository) { create :user_repository, name: 'CoolCode', owner: user.username, users: [user] }
let!(:org_repository) { create :repository, name: 'CoolOrg', organization: organization, users: [org_user] }
let!(:inactive_repository) { create :repository, name: 'CoolInactive', is_active: false, users: [user] }
describe 'show repository' do
context 'holder does not exist' do
scenario 'shows 404' do
visit repository_public_path('joe_schmoe', inactive_repository.name)
expect(page).to have_content(I18n.t('repositories.not_found.message'))
end
end
context 'repository is activated' do
scenario 'shows the repository issue page' do
visit repository_public_path(user.username, repository.name)
expect(page).to have_content(repository.name)
end
end
context 'repository is not activated' do
scenario 'shows 404' do
visit repository_public_path(user.username, inactive_repository.name)
expect(page).to have_content(I18n.t('repositories.not_found.message'))
end
end
context 'URL params are passed' do
scenario 'prefills the issue form' do
visit repository_public_path(user.username, repository.name, name: 'Important Issue', email: 'some@email.com', details: 'Big details')
expect(find_field('name').value).to eq('Important Issue')
expect(find_field('email').value).to eq('some@email.com')
expect(find_field('details').value).to eq('Big details')
end
end
context 'locale is passed in headers' do
before { Capybara.current_session.driver.header('Accept-Language', 'pl') }
after { Capybara.current_session.driver.header('Accept-Language', 'pl') }
scenario 'uses requested language' do
visit repository_public_path(user.username, repository.name)
expect(page).to have_content('Zgłoszenie')
end
end
end
describe 'submit issue' do
context 'custom display name, prompt, and followup are set' do
before { override_captcha true }
let!(:repository) { create :user_repository, owner: user.username, users: [user], display_name: 'Cool Code', prompt: 'Enter your bug please', followup: 'Thanks a lot!' }
scenario 'shows custom display name, prompt, and followup' do
visit repository_public_path(repository.holder_name, repository.name)
expect(page).to have_content('Cool Code')
expect(page).not_to have_content(repository.name)
expect(page).to have_content('Enter your bug please')
expect(page).not_to have_content('Please enter your bug report or feature request')
fill_in 'name', with: 'Joe Schmoe'
fill_in 'email', with: 'joe.schmoe@gmail.com'
fill_in 'details', with: 'Your code is broken!'
fill_in 'captcha', with: 'asdfgh'
click_on I18n.t('submit_form.label.submit')
expect(page).to have_content('Thanks a lot!')
expect(page).not_to have_content('Thanks for submitting your report!')
end
end
context 'no custom display, prompt, followup' do
scenario 'shows default display name and prompt' do
visit repository_public_path(repository.holder_name, repository.name)
expect(page).to have_content(repository.name)
expect(page).to have_content('Please enter your bug report or feature request')
end
end
context 'captcha is correct' do
before { override_captcha true }
scenario 'submits issue' do
visit repository_public_path(repository.holder_name, repository.name)
fill_in 'name', with: 'Joe Schmoe'
fill_in 'email', with: 'joe.schmoe@gmail.com'
fill_in 'details', with: 'Your code is broken!'
fill_in 'captcha', with: 'asdfgh'
click_on I18n.t('submit_form.label.submit')
expect(page).to have_content('Thanks for submitting your report!')
# Should have queued issue submission
expect(enqueued_jobs.size).to eq(1)
expect(enqueued_jobs.first[:args]).to eq(['submit_issue', 1, 'Joe Schmoe', 'joe.schmoe@gmail.com', true, nil, 'Your code is broken!'])
end
scenario 'submits issue without public email' do
visit repository_public_path(repository.holder_name, repository.name)
fill_in 'name', with: 'Joe Schmoe'
fill_in 'email', with: 'joe.schmoe@gmail.com'
uncheck I18n.t('submit_form.label.email_public')
fill_in 'details', with: 'Your code is broken!'
fill_in 'captcha', with: 'asdfgh'
click_on I18n.t('submit_form.label.submit')
expect(page).to have_content('Thanks for submitting your report!')
# Should have queued issue submission
expect(enqueued_jobs.size).to eq(1)
expect(enqueued_jobs.first[:args]).to eq(['submit_issue', 1, 'Joe Schmoe', 'joe.schmoe@gmail.com', false, nil, 'Your code is broken!'])
end
end
context 'captcha is incorrect' do
before { override_captcha false }
scenario 'prefills issue page and shows error' do
visit repository_public_path(repository.holder_name, repository.name)
fill_in 'name', with: 'Joe Schmoe'
fill_in 'email', with: 'joe.schmoe@gmail.com'
uncheck I18n.t('submit_form.label.email_public')
fill_in 'details', with: 'Your code is broken!'
fill_in 'captcha', with: 'asdfgh'
click_on I18n.t('submit_form.label.submit')
expect(page).to have_content('Incorrect CAPTCHA; please retry!')
expect(find_field('name').value).to eq('Joe Schmoe')
expect(find_field('email').value).to eq('joe.schmoe@gmail.com')
expect(find_field(I18n.t('submit_form.label.email_public'))).to_not be_checked
expect(find_field('details').value).to eq('Your code is broken!')
end
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/spec/mailers/notification_mailer_spec.rb | spec/mailers/notification_mailer_spec.rb | describe NotificationMailer do
describe '#issue_submitted_email' do
context 'when not including submitter email' do
let!(:repository) { create :repository, name: 'CoolCode', owner: 'CoolOrg', notification_emails: 'joe@email.com' }
subject { NotificationMailer.issue_submitted_email(repository.id, 1) }
it 'sends notification mail without submitter email' do
expect(subject.body).to have_content('New issue submitted to repository CoolCode!')
end
end
context 'when including submitter email' do
let!(:repository) { create :repository, name: 'CoolCode', owner: 'CoolOrg', notification_emails: 'joe@email.com', include_submitter_email: true }
subject { NotificationMailer.issue_submitted_email(repository.id, 1, submitter_name: 'Scott', submitter_email: 'Scott@Scott.com') }
it 'sends notification mail with submitter information in subject' do
expect(subject).to have_content('Subject: New Issue Submitted to CoolCode by Scott: Scott@Scott.com')
end
end
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/application.rb | config/application.rb | require File.expand_path('../boot', __FILE__)
require 'rails'
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_view/railtie'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module GitReports
class Application < Rails::Application
# Use errors controller for exceptions.
config.exceptions_app = routes
# Use Sidekiq to back ActiveJob.
config.active_job.queue_adapter = :sidekiq
# Use public/assets rather than public/webpack
config.webpack.output_dir = 'public/assets'
config.webpack.public_path = 'assets'
config.webpack.manifest_filename = 'webpack_manifest.json'
config.webpack.dev_server.manifest_port = 3808
config.webpack.dev_server.port = 3808
config.webpack.dev_server.host = ENV.fetch('WEBPACK_DEV_HOST', 'lvh.me')
config.webpack.dev_server.enabled = Rails.env.development?
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/environment.rb | config/environment.rb | # Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
GitReports::Application.initialize!
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/routes.rb | config/routes.rb | require 'sidekiq/web'
GitReports::Application.routes.draw do
# Error pages.
%w[404 422 500].each do |code|
match code, to: "errors#error_#{code}", via: :all
end
# Authentication routes
get '/login', to: 'authentications#login', as: 'login'
get '/github_callback', to: 'authentications#callback'
get '/logout', to: 'authentications#logout', as: 'logout'
get '/login_rate_limited', to: 'authentications#login_rate_limited', as: 'login_rate_limited'
# Repository routes
get '/profile', to: 'repositories#index', as: 'profile'
scope :issue do
get ':username/:repositoryname', to: 'issues#new', as: 'repository_public', repositoryname: %r{[^\/]+}
post ':username/:repositoryname', to: 'issues#create', repositoryname: %r{[^\/]+}
get ':username/:repositoryname/submitted', to: 'issues#created', as: 'submitted', repositoryname: %r{[^\/]+}
end
resources :repositories, only: %i[show edit update] do
collection do
get :load_status
end
end
# Sidekiq monitoring
constraints ->(request) { User.find_by(id: request.session[:user_id])&.is_admin } do
mount Sidekiq::Web => '/admin/sidekiq'
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/boot.rb | config/boot.rb | # Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/initializers/sidekiq.rb | config/initializers/sidekiq.rb | require 'sidekiq'
require 'sidekiq-status'
Sidekiq.configure_client do |config|
config.client_middleware do |chain|
chain.add Sidekiq::Status::ClientMiddleware
end
end
Sidekiq.configure_server do |config|
config.server_middleware do |chain|
chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes # default
end
config.client_middleware do |chain|
chain.add Sidekiq::Status::ClientMiddleware
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/initializers/session_store.rb | config/initializers/session_store.rb | # Be sure to restart your server when you modify this file.
GitReports::Application.config.session_store :cookie_store, key: '_git-reports_session'
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/initializers/high_voltage.rb | config/initializers/high_voltage.rb | HighVoltage.configure do |config|
config.home_page = 'home'
config.route_drawer = HighVoltage::RouteDrawers::Root
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/initializers/wrap_parameters.rb | config/initializers/wrap_parameters.rb | # 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] if respond_to?(:wrap_parameters)
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 | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/initializers/simple_captcha.rb | config/initializers/simple_captcha.rb | SimpleCaptcha.setup do |sc|
# default: 100x28
# sc.image_size = '400x150'
# default: 5
sc.length = 6
# default: simply_blue
# possible values:
# 'embosed_silver',
# 'simply_red',
# 'simply_green',
# 'simply_blue',
# 'distorted_black',
# 'all_black',
# 'charcoal_grey',
# 'almost_invisible'
# 'random'
sc.image_style = 'all_black'
# default: low
# possible values: 'low', 'medium', 'high', 'random'
sc.distortion = 'medium'
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/initializers/sentry.rb | config/initializers/sentry.rb | if Rails.env.production?
Raven.configure do |config|
config.dsn = ENV['SENTRY_DSN']
config.excluded_exceptions = [
'GithubRateLimitError',
# Mostly bots trying WordPress URLs.
'ActionController::RoutingError',
# Revoked/expired credentials.
'Octokit::Forbidden',
'Octokit::Unauthorized'
]
end
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/environments/test.rb | config/environments/test.rb | GitReports::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 static asset server for tests with Cache-Control for performance.
config.serve_static_files = true
config.static_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
# 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
# Set host for email links
config.action_mailer.default_url_options = { host: 'localhost:3000' }
# Access to rack session
config.middleware.use RackSessionAccess::Middleware
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/environments/development.rb | config/environments/development.rb | GitReports::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 and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = 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
# Set host for email links
config.action_mailer.default_url_options = { host: 'localhost:3000' }
# Load assets from webpack server.
config.action_controller.asset_host = "http://#{ENV.fetch('WEBPACK_DEV_HOST', 'lvh.me')}:3808"
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
schneidmaster/gitreports.com | https://github.com/schneidmaster/gitreports.com/blob/0b86f285220dbfe12a70913bf07001a882dd0e32/config/environments/production.rb | config/environments/production.rb | GitReports::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 thread 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
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_files = false
# 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
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# Set to :debug to see everything in the log.
config.log_level = :info
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# 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 can not be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Set host for email links
config.action_mailer.default_url_options = { host: 'https://gitreports.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
authentication: :plain,
address: 'smtp.mailgun.org',
port: 587,
domain: 'gitreports.com',
user_name: 'postmaster@gitreports.com',
password: ENV['MAILGUN_PASSWORD']
}
end
| ruby | MIT | 0b86f285220dbfe12a70913bf07001a882dd0e32 | 2026-01-04T17:44:54.224551Z | false |
madx/roy | https://github.com/madx/roy/blob/7f9d96b146c15c7b2d3f4019a8a2078475983186/test/custom_options_test.rb | test/custom_options_test.rb | require_relative 'helper'
class CustomOptionsTestObject
include Roy
roy foo: :bar
end
class CustomOptionsTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
def app
CustomOptionsTestObject.new
end
def test_custom_options
assert_equal :bar, app.class.conf.foo
end
end
| ruby | MIT | 7f9d96b146c15c7b2d3f4019a8a2078475983186 | 2026-01-04T17:45:03.561436Z | false |
madx/roy | https://github.com/madx/roy/blob/7f9d96b146c15c7b2d3f4019a8a2078475983186/test/prefix_test.rb | test/prefix_test.rb | require_relative 'helper'
class PrefixTestObject
include Roy
roy allow: [:get], prefix: :http_
def http_get(path)
'success'
end
end
class PrefixTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
def app
PrefixTestObject.new
end
def test_prefixing
get '/'
assert_equal 'success', last_response.body
end
end
| ruby | MIT | 7f9d96b146c15c7b2d3f4019a8a2078475983186 | 2026-01-04T17:45:03.561436Z | false |
madx/roy | https://github.com/madx/roy/blob/7f9d96b146c15c7b2d3f4019a8a2078475983186/test/helper.rb | test/helper.rb | require 'bundler'
Bundler.require(:default, :development)
require 'minitest/autorun'
require 'rack/test'
require 'roy'
module CustomTestMethods
private
def ok!
assert_predicate last_response, :ok?
end
def fail!
refute_predicate last_response, :ok?
end
end
Rack::Test::Methods.send(:include, CustomTestMethods)
| ruby | MIT | 7f9d96b146c15c7b2d3f4019a8a2078475983186 | 2026-01-04T17:45:03.561436Z | false |
madx/roy | https://github.com/madx/roy/blob/7f9d96b146c15c7b2d3f4019a8a2078475983186/test/defaults_test.rb | test/defaults_test.rb | require_relative 'helper'
Roy::Defaults.tap do |conf|
conf[:prefix] = :http_
conf[:use] = [:halt, :after]
end
class DefaultsTestObject
include Roy
roy after: lambda { |response|
response.status = 404
}
def http_get(path)
'success'
end
end
class DefaultsTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
def app
DefaultsTestObject.new
end
def test_default_settings
get '/'
assert_equal 404, last_response.status
assert_equal 'success', last_response.body
end
end
| ruby | MIT | 7f9d96b146c15c7b2d3f4019a8a2078475983186 | 2026-01-04T17:45:03.561436Z | false |
madx/roy | https://github.com/madx/roy/blob/7f9d96b146c15c7b2d3f4019a8a2078475983186/test/base_test.rb | test/base_test.rb | require_relative 'helper'
class BaseTestObject
include Roy
attr_reader :history
def initialize
@history = []
end
roy allow: [:get, :put, :custom]
def get(path)
history.inspect
end
def put(path)
roy.halt 400 unless roy.params[:body]
history << roy.params[:body]
history << roy.params[:foo] if roy.params[:foo]
get(path)
end
def custom(path)
path
end
end
class BaseTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
def app
BaseTestObject.new
end
def test_provide_call
assert_respond_to app, :call
end
def test_provide_roy
assert_respond_to app.class, :roy
end
def test_defines_roy_attribute_with_defaults
assert_respond_to app, :roy
assert_equal :'', app.roy.conf.prefix
assert_instance_of Set, app.roy.conf.allow
end
def test_forward_allowed_methods
get '/'
ok!
assert_equal app.get('/'), last_response.body
end
def test_block_forbidden_methods
post '/'
fail!
assert_equal 405, last_response.status
end
def test_set_allowed_methods
assert_includes app.class.conf.allow, :get
assert_includes app.class.conf.allow, :put
assert_includes app.class.conf.allow, :custom
refute_includes app.class.conf.allow, :post
end
def test_allowing_get_allows_head
assert_includes app.class.conf.allow, :head
end
def test_roy_halt
assert_throws :halt do
app.roy.halt 200
end
end
def test_head_does_not_have_contents
head '/'
ok!
assert_equal '', last_response.body
end
def test_params
put '/?foo=bar', :body => 'hello'
ok!
assert_equal %w(hello bar).inspect, last_response.body
end
def test_custom_methods
request '/', :method => 'CUSTOM'
ok!
assert_equal '/', last_response.body
end
end
| ruby | MIT | 7f9d96b146c15c7b2d3f4019a8a2078475983186 | 2026-01-04T17:45:03.561436Z | false |
madx/roy | https://github.com/madx/roy/blob/7f9d96b146c15c7b2d3f4019a8a2078475983186/test/plugins/basic_auth_test.rb | test/plugins/basic_auth_test.rb | require_relative '../helper'
class BasicAuthTestObject
include Roy
roy use: [:basic_auth], allow: [:get],
auth: {
realm: "Custom",
logic: ->(_, u, p) { %w(user password) == [u, p] }
}
def get(path)
roy.protected!
'success'
end
end
class BasicAuthTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
def app
BasicAuthTestObject.new
end
def test_basic_auth_realm
get '/'
assert_match /Custom/, last_response['WWW-Authenticate']
end
def test_basic_auth_protected
get '/'
assert_equal 401, last_response.status
end
def test_basic_auth_authorized
authorize 'user', 'password'
get '/'
ok!
end
def test_basic_auth_unauthorized
authorize 'foo', 'bar'
get '/'
fail!
end
end
| ruby | MIT | 7f9d96b146c15c7b2d3f4019a8a2078475983186 | 2026-01-04T17:45:03.561436Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.