source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | spec/features/create_user_links.rb | Ruby | mit | 19 | master | 647 | # frozen_string_literal: true
require 'rails_helper'
RSpec.feature 'create user links' do
let(:admin) { users(:admin) }
let(:volunteer) { users(:volunteer) }
let(:member) { users(:member) }
scenario 'when user is an admin or a volunteer' do
[admin, volunteer].each do |user|
sign_in user
visit... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | spec/features/carrier_spec.rb | Ruby | mit | 19 | master | 6,651 | # frozen_string_literal: true
RSpec.describe Carrier do
let(:carrier) { carriers(:carrier) }
let(:user) { users(:user) }
describe 'USER role' do
before do
visit root_url
sign_in user
end
scenario 'SHOW' do
visit carriers_url
click_link carrier.name
expect(page).to hav... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | spec/features/location_spec.rb | Ruby | mit | 19 | master | 1,270 | # frozen_string_literal: true
RSpec.describe Location, type: :feature do
let(:user) { users(:admin) }
# TODO: add tests to make sure if you're not logged in as an admin,
# you can't do these things to a location
before do
visit '/'
sign_in user
end
it 'allows admin to CREATE new locations' do
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | spec/features/carriers/loans_spec.rb | Ruby | mit | 19 | master | 1,252 | # frozen_string_literal: true
RSpec.feature 'Loan spec', type: :feature do
let(:admin) { users(:admin) }
let(:volunteer) { users(:volunteer) }
let(:borrower) { users(:borrower) }
let(:carrier) { carriers(:carrier) }
scenario "Member can't create perform checkout" do
sign_in borrower
visit car... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | spec/jobs/reminder_email_job_spec.rb | Ruby | mit | 19 | master | 2,715 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe ReminderEmailJob, type: :job do
let(:all_loans) { %i[due_today_1 due_today_2 due_one_week one_week_overdue two_weeks_overdue] }
let(:loan1) { loans(:due_today_1) }
let(:loan2) { loans(:due_today_2) }
describe '#perform' do
context 'with ... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/puma.rb | Ruby | mit | 19 | master | 1,414 | # Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/application.rb | Ruby | mit | 19 | master | 1,659 | require_relative 'boot'
require "rails"
require "csv"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "ac... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/puma.production.rb | Ruby | mit | 19 | master | 514 | environment "production"
bind "unix:///home/babywearing/app/shared/tmp/sockets/puma.sock"
pidfile "/home/babywearing/app/shared/tmp/pids/puma.pid"
state_path "/home/babywearing/app/shared/tmp/puma.state"
directory "/home/babywearing/app/current"
workers 1
threads 1,2
daemonize false
stdout_redirect "/home/babywear... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/routes.rb | Ruby | mit | 19 | master | 1,374 | Rails.application.routes.draw do
devise_for :users, controllers: {registrations: "users/registrations"}
get 'home/index'
resources :users, except: [:destroy, :new] do
resources :memberships, except: :index, controller: 'users/memberships'
resources :signatures, except: %i[:destroy, :edit, :update], cont... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/boot.rb | Ruby | mit | 19 | master | 228 | $stdout.sync = true
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'bootsnap/setup' # Speed up boot time by caching expensive operations. |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/initializers/money.rb | Ruby | mit | 19 | master | 521 | MoneyRails.configure do |config|
# Defaults will change with next major release
config.locale_backend = :i18n
config.default_currency = :usd
# Specify a rounding mode
# Any one of:
#
# BigDecimal::ROUND_UP,
# BigDecimal::ROUND_DOWN,
# BigDecimal::ROUND_HALF_UP,
# BigDecimal::ROUND_HALF_DOWN,
# B... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/initializers/sidekiq.rb | Ruby | mit | 19 | master | 337 | Sidekiq.configure_server do |config|
config.redis = { url: 'redis://localhost:6379/0' }
schedule_file = "config/schedule.yml"
if File.exists?(schedule_file)
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
end
end
Sidekiq.configure_client do |config|
config.redis = { url: 'redis://localho... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/initializers/devise.rb | Ruby | mit | 19 | master | 14,485 | # frozen_string_literal: true
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render inv... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/environments/development.rb | Ruby | mit | 19 | master | 2,684 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web serv... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/environments/test.rb | Ruby | mit | 19 | master | 2,089 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suit... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | config/environments/production.rb | Ruby | mit | 19 | master | 4,754 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web serve... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | deploy/deploy.rb | Ruby | mit | 19 | master | 3,676 | # frozen_string_literal: true
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv' # for rbenv support. (https://rbenv.org)
require 'mina/puma'
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
# repository - Git repo to clone from. (needed by mina/git)
#... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | lib/email_template_parser.rb | Ruby | mit | 19 | master | 502 | # frozen_string_literal: true
class EmailTemplateParser
attr_accessor :due_date, :user_name, :carrier_name
def initialize(
user_name:,
due_date: nil,
carrier_name: nil
)
@user_name = user_name
@due_date = due_date.to_s
@carrier_name = carrier_name
end
def parse_body(template_body)
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | lib/modal_responder.rb | Ruby | mit | 19 | master | 583 | # frozen_string_literal: true
# Custom responder that is used for modals inside the app.
# If you want to render modal call this responder like this
#
# respond_modal_with @record
#
class ModalResponder < ActionController::Responder
cattr_accessor :modal_layout
self.modal_layout = 'modal'
def render(*args)
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | lib/tasks/carrier_images.rake | Ruby | mit | 19 | master | 1,750 | # frozen_string_literal: true
# rubocop:disable Metrics/BlockLength, Metrics/BlockNesting
namespace :db do
namespace :image_seeds do
desc 'Load carrier images from seeds'
task carriers: :environment do
organization = Organization.find_by(subdomain: 'midatlantic')
photos_added = 0
carriers_p... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | lib/tasks/credentials.rake | Ruby | mit | 19 | master | 737 | # frozen_string_literal: true
namespace :credentials do
desc 'Update credentials file'
task :update, [:key, :value] do |_t, args|
key_path = File.join(Rails.root, 'config', 'master.key').strip
content_path = File.join(Rails.root, 'config', 'credentials.yml.enc')
encrypted = Rails.application.encrypted(... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/validators/subdomain_validator.rb | Ruby | mit | 19 | master | 1,055 | # frozen_string_literal: true
class SubdomainValidator < ActiveModel::EachValidator
# https://gist.github.com/stuartbain/7212385
def validate_each(object, attribute, value)
return unless value.present?
reserved_names = %w[www ftp mail pop smtp ssl sftp]
reserved_names = options[:reserved] if options[:... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/location_policy.rb | Ruby | mit | 19 | master | 442 | # frozen_string_literal: true
class LocationPolicy < ApplicationPolicy
attr_reader :user, :location
def initialize(user, location)
@user = user
@location = location
end
def index?
authorized_admin?
end
def new?
authorized_admin?
end
def create?
authorized_admin?
end
def edi... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/category_policy.rb | Ruby | mit | 19 | master | 441 | # frozen_string_literal: true
class CategoryPolicy < ApplicationPolicy
attr_reader :user, :category
def initialize(user, category)
@user = user
@category = category
end
def new?
authorized?
end
def create?
authorized?
end
def edit?
authorized?
end
def update?
authorized... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/agreement_policy.rb | Ruby | mit | 19 | master | 447 | # frozen_string_literal: true
class AgreementPolicy < ApplicationPolicy
attr_reader :user, :agreement
def initialize(user, agreement)
@user = user
@agreement = agreement
end
def index?
authorized_admin?
end
def new?
authorized_admin?
end
def create?
authorized_admin?
end
de... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/application_policy.rb | Ruby | mit | 19 | master | 684 | # frozen_string_literal: true
class ApplicationPolicy
attr_reader :user, :users
def initialize(user, users)
@user = user
@users = users
end
def authorized_admin?
user&.admin?
end
def authorized_admin_or_volunteer?
user && (user.admin? || user.volunteer?)
end
def index?
false
e... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/agreement_version_policy.rb | Ruby | mit | 19 | master | 527 | # frozen_string_literal: true
class AgreementVersionPolicy < ApplicationPolicy
attr_reader :user, :agreement_version
def initialize(user, agreement_version)
@user = user
@agreement_version = agreement_version
end
def index?
authorized_admin?
end
def new?
authorized_admin?
end
def sh... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/user_policy.rb | Ruby | mit | 19 | master | 662 | # frozen_string_literal: true
class UserPolicy < ApplicationPolicy
attr_reader :user, :users
def initialize(user, users)
@user = user
@users = users
end
def index?
authorized?
end
def new?
authorized?
end
def create?
authorized?
end
def edit?
authorized?
end
def up... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/carrier_policy.rb | Ruby | mit | 19 | master | 774 | # frozen_string_literal: true
class CarrierPolicy < ApplicationPolicy
attr_reader :user, :carrier
def initialize(user, carrier)
@user = user
@carrier = carrier
end
def new?
authorized_admin?
end
def create?
authorized_admin?
end
def edit?
authorized_admin_or_volunteer?
end
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/loan_policy.rb | Ruby | mit | 19 | master | 443 | # frozen_string_literal: true
class LoanPolicy < ApplicationPolicy
attr_reader :user, :loan
def initialize(user, loan)
@user = user
@loan = loan
end
def create?
authorized_admin_or_volunteer?
end
def edit?
authorized_admin_or_volunteer?
end
def index?
authorized_admin_or_volunte... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/membership_policy.rb | Ruby | mit | 19 | master | 451 | # frozen_string_literal: true
class MembershipPolicy < ApplicationPolicy
attr_reader :user, :membership
def initialize(user, membership)
@user = user
@membership = membership
end
def new?
authorized?
end
def create?
authorized?
end
def edit?
authorized?
end
def update?
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/fee_type_policy.rb | Ruby | mit | 19 | master | 482 | # frozen_string_literal: true
class FeeTypePolicy < ApplicationPolicy
attr_reader :user, :fee_type
def initialize(user, fee_type)
@user = user
@fee_type = fee_type
end
def create?
authorized_admin?
end
def destroy?
authorized_admin?
end
def edit?
authorized_admin?
end
def i... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/email_template_policy.rb | Ruby | mit | 19 | master | 512 | # frozen_string_literal: true
class EmailTemplatePolicy < ApplicationPolicy
attr_reader :user, :email_template
def initialize(user, email_template)
@user = user
@email_template = email_template
end
def create?
authorized_admin?
end
def destroy?
authorized_admin?
end
def edit?
au... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/policies/membership_type_policy.rb | Ruby | mit | 19 | master | 476 | # frozen_string_literal: true
class MembershipTypePolicy < ApplicationPolicy
attr_reader :user, :membership_type
def initialize(user, membership_type)
@user = user
@membership_type = membership_type
end
def new?
authorized_admin?
end
def create?
authorized_admin?
end
def index?
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/fee_types_controller.rb | Ruby | mit | 19 | master | 1,281 | # frozen_string_literal: true
class FeeTypesController < ApplicationController
before_action :set_fee_type, only: %i[show edit update destroy]
# GET /fee_types
def index
@fee_types = FeeType.all
authorize @fee_types
end
# GET /fee_types/1
def show
authorize @fee_type
end
# GET /fee_types... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/categories_controller.rb | Ruby | mit | 19 | master | 1,436 | # frozen_string_literal: true
class CategoriesController < ApplicationController
before_action :set_category, only: %i[show edit update destroy]
# GET /categories
def index
@categories = Category.where(parent_id: nil).includes(:subcategories).order(:name)
end
# GET /categories/1
def show
end
# G... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/application_controller.rb | Ruby | mit | 19 | master | 1,347 | # frozen_string_literal: true
require 'modal_responder'
class ApplicationController < ActionController::Base
before_action :set_tenant_by_subdomain
include Authentication
include Pundit
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
rescue_from Pundit::NotAuthorizedError, with: :render_... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/locations_controller.rb | Ruby | mit | 19 | master | 1,127 | # frozen_string_literal: true
class LocationsController < ApplicationController
before_action :set_location, only: %i[show edit update destroy]
def index
@locations = Location.all
authorize @locations
end
def show
end
def new
@location = authorize Location.new
end
def create
@locati... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/agreements_controller.rb | Ruby | mit | 19 | master | 1,010 | # frozen_string_literal: true
class AgreementsController < ApplicationController
before_action :set_agreement, only: %i[show edit update destroy]
def index
@agreements = Agreement.order(:name)
end
def new
@agreement = authorize Agreement.new
end
def create
@agreement = authorize Agreement.ne... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/photos_controller.rb | Ruby | mit | 19 | master | 300 | # frozen_string_literal: true
class PhotosController < ApplicationController
def destroy
@photo = ActiveStorage::Attachment.find(params[:id])
carrier = @photo.record
@photo.purge
flash[:success] = 'Photo successfully destroyed'
redirect_to edit_carrier_path(carrier)
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/email_templates_controller.rb | Ruby | mit | 19 | master | 1,323 | # frozen_string_literal: true
class EmailTemplatesController < ApplicationController
def index
authorize @email_templates = EmailTemplate.order(active: :desc)
end
def show
@email_template = authorize EmailTemplate.find(params[:id])
end
def new
@email_template = authorize EmailTemplate.new
end... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/users_controller.rb | Ruby | mit | 19 | master | 1,184 | # frozen_string_literal: true
class UsersController < ApplicationController
before_action :set_user, only: %i[edit update show]
def index
init_filters || return
@users = authorize @filterrific.find.page(params[:page])
respond_to do |format|
format.html
format.js
format.csv { send_da... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/home_controller.rb | Ruby | mit | 19 | master | 279 | # frozen_string_literal: true
class HomeController < ApplicationController
skip_before_action :authenticate_user!
def index
@domain = [request.subdomains.last, request.domain].reject(&:blank?).join('.')
@organizations = Organization.nonadmin.order(:name)
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/loan_listing_controller.rb | Ruby | mit | 19 | master | 884 | # frozen_string_literal: true
class LoanListingController < ApplicationController
def index
init_filters || return
@loans = @filterrific.find.page(params[:page])
authorize @loans
respond_to do |format|
format.html
format.js
end
end
private
def init_filters
@filterrific = ... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/carriers_controller.rb | Ruby | mit | 19 | master | 3,266 | # frozen_string_literal: true
class CarriersController < ApplicationController
skip_before_action :authenticate_user!, only: [:index]
before_action :set_carrier, only: %i[show edit update]
before_action :set_loan, only: [:show]
def index
@carriers = Carrier.with_attached_photos.includes(:home_location)
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/membership_types_controller.rb | Ruby | mit | 19 | master | 1,675 | # frozen_string_literal: true
class MembershipTypesController < ApplicationController
before_action :set_membership_type, only: %i[show edit update destroy]
# GET /membership_types
def index
authorize @membership_types = MembershipType.all
end
# GET /membership_types/1
def show
end
# GET /member... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/organizations_controller.rb | Ruby | mit | 19 | master | 1,379 | # frozen_string_literal: true
class OrganizationsController < ApplicationController
before_action :set_organization, only: %i[show edit update destroy]
def index
@organizations = Organization.order(:name)
end
def new
@organization = Organization.new
end
# # GET /categories/1/edit
# def edit
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/concerns/carrier_scoped.rb | Ruby | mit | 19 | master | 214 | # frozen_string_literal: true
module CarrierScoped
extend ActiveSupport::Concern
included do
before_action :set_carrier
end
def set_carrier
@carrier = Carrier.find(params[:carrier_id])
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/concerns/authentication.rb | Ruby | mit | 19 | master | 324 | # frozen_string_literal: true
module Authentication
extend ActiveSupport::Concern
included do
protect_from_forgery with: :exception
before_action :authenticate_user!
before_action :set_current_user, if: -> { current_user }
end
private
def set_current_user
Current.user = current_user
end
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/concerns/agreement_scoped.rb | Ruby | mit | 19 | master | 226 | # frozen_string_literal: true
module AgreementScoped
extend ActiveSupport::Concern
included do
before_action :set_agreement
end
def set_agreement
@agreement = Agreement.find(params[:agreement_id])
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/users/signatures_controller.rb | Ruby | mit | 19 | master | 906 | # frozen_string_literal: true
module Users
class SignaturesController < ApplicationController
include UserScoped
def create
@signature = @user.signatures.new(signature_params.merge(signed_at: Time.zone.now))
if @signature.save
redirect_to user_signatures_path(@user), notice: 'Agreement s... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/users/deactivate_controller.rb | Ruby | mit | 19 | master | 276 | # frozen_string_literal: true
module Users
class DeactivateController < ApplicationController
def create
user = User.find(params[:id])
user.deactivated? ? user.activate : user.deactivate
redirect_back(fallback_location: users_path)
end
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/users/registrations_controller.rb | Ruby | mit | 19 | master | 1,235 | # frozen_string_literal: true
module Users
class RegistrationsController < Devise::RegistrationsController
skip_before_action :require_no_authentication, only: %i[new create]
def create
super
return unless resource.persisted?
set_flash_message!(:notice, current_user == resource ? :signed_... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/users/memberships_controller.rb | Ruby | mit | 19 | master | 1,368 | # frozen_string_literal: true
module Users
class MembershipsController < ApplicationController
before_action :set_user
respond_to :html, :json
def create
@membership = authorize @user.memberships.new(membership_params)
if @membership.save
redirect_to user_path(@user), notice: 'Membe... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/carriers/loans_controller.rb | Ruby | mit | 19 | master | 1,436 | # frozen_string_literal: true
module Carriers
class LoansController < ApplicationController
include CarrierScoped
before_action :verify_state, except: %i[edit update]
respond_to :html, :json
def create
@loan = @carrier.loans.new(loan_params)
authorize @loan
@loan.save
respon... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/controllers/agreements/versions_controller.rb | Ruby | mit | 19 | master | 1,826 | # frozen_string_literal: true
module Agreements
class VersionsController < ApplicationController
include AgreementScoped
def create
@version = authorize @agreement.versions.create(version_params.merge(last_modified_by_id: current_user.id))
if @version.errors.any?
flash[:error] = @versio... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/helpers/email_templates_helper.rb | Ruby | mit | 19 | master | 518 | # frozen_string_literal: true
module EmailTemplatesHelper
def types_for_select
[%w[Checkout CheckoutEmailTemplate],
%w[Reminder ReminderEmailTemplate],
%w[Welcome WelcomeEmailTemplate]]
end
def when_days_display(email_template)
return 'N/A' unless email_template.is_a?(ReminderEmailTemplate)
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/helpers/loans_helper.rb | Ruby | mit | 19 | master | 224 | # frozen_string_literal: true
module LoansHelper
def loans_default_selected_date_for(carrier)
return Date.current unless carrier.default_loan_length_days
Date.current + carrier.default_loan_length_days
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/helpers/devise_helper.rb | Ruby | mit | 19 | master | 597 | # frozen_string_literal: true
module DeviseHelper
def devise_error_messages!
return '' if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
html = <<-HTML
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<button ty... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/helpers/users_helper.rb | Ruby | mit | 19 | master | 401 | # frozen_string_literal: true
module UsersHelper
def user_initials(user)
user.name.initials
end
def user_roles_select
User.roles.keys.map { |role| [role.humanize, role] }
end
def membership_status(user)
return 'None' if user.memberships.empty?
latest = user.latest_membership
return 'Ex... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/helpers/application_helper.rb | Ruby | mit | 19 | master | 573 | # frozen_string_literal: true
module ApplicationHelper
def boolean_display(item)
item ? 'Yes' : 'No'
end
def flash_class(level)
case level.to_sym
when :notice then 'alert alert-info'
when :success then 'alert alert-success'
when :error then 'alert alert-error'
when :alert then 'alert ale... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/helpers/forms_helper.rb | Ruby | mit | 19 | master | 529 | # frozen_string_literal: true
# View helpers for the forms
module FormsHelper
# Used to render errors on the forms
#
# USAGE
# <%= form_errors @record %>
#
def form_errors(model)
render 'shared/form_errors', model: model
end
def number_to_word(num)
conversion = {
10 => 'ten',
9 =... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/helpers/carriers_helper.rb | Ruby | mit | 19 | master | 319 | # frozen_string_literal: true
module CarriersHelper
def carrier_badge_class(carrier)
if carrier.available?
'badge badge-success'
else
'badge badge-danger'
end
end
def carrier_editable_states_for_select
Carrier.aasm.states_for_select.reject { |s| s.first == 'Checked out' }
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/mailers/reminder_mailer.rb | Ruby | mit | 19 | master | 756 | # frozen_string_literal: true
require 'email_template_parser'
class ReminderMailer < ApplicationMailer
def reminder_email(loan, template)
ActsAsTenant.with_tenant(loan.carrier.organization) do
return unless template.organization == ActsAsTenant.current_tenant && template.active
parse_body(loan, tem... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/mailers/custom_mailer.rb | Ruby | mit | 19 | master | 332 | # frozen_string_literal: true
class CustomMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
default template_path: 'devise/mailer' # to make sure that your mailer uses the devis... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/mailers/checkout_mailer.rb | Ruby | mit | 19 | master | 740 | # frozen_string_literal: true
require 'email_template_parser'
class CheckoutMailer < ApplicationMailer
def checkout_email(loan)
organization = loan.carrier.organization
template = CheckoutEmailTemplate.active.where(organization_id: organization.id).last
return unless template.present?
build_body(lo... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/mailers/welcome_mailer.rb | Ruby | mit | 19 | master | 650 | # frozen_string_literal: true
require 'email_template_parser'
class WelcomeMailer < CustomMailer
include Sidekiq::Worker
def welcome_email(user_id)
@user = User.find(user_id)
template = WelcomeEmailTemplate.active.where(organization_id: @user.organization_id).last
return unless template.present?
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/jobs/reminder_email_job.rb | Ruby | mit | 19 | master | 1,350 | # frozen_string_literal: true
class ReminderEmailJob < ApplicationJob
queue_as :mailers
def perform(*_args)
overdues
due_todays
due_in_futures
end
private
def overdues
Organization.all.each do |org|
ActsAsTenant.with_tenant(org) do
org.reminder_email_templates.active.after_du... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/reminder_email_template.rb | Ruby | mit | 19 | master | 398 | # frozen_string_literal: true
class ReminderEmailTemplate < EmailTemplate
enum when_sent: { before_due_date: 'before_due_date', after_due_date: 'after_due_date', on_due_date: 'on_due_date' }
validates_presence_of :when_days, if: :when_days_required?
validates_presence_of :when_sent
private
def when_days_r... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/membership_type.rb | Ruby | mit | 19 | master | 236 | # frozen_string_literal: true
class MembershipType < ApplicationRecord
acts_as_tenant(:organization)
monetize :fee_cents, as: 'fee'
validates :name, :short_name, :fee_cents, :duration_days, :number_of_items, presence: true
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/agreement_version.rb | Ruby | mit | 19 | master | 1,144 | # frozen_string_literal: true
class AgreementVersion < ApplicationRecord
belongs_to :agreement
belongs_to :last_modified_by, class_name: 'User'
has_many :signatures, dependent: :destroy
before_destroy :active_indestructable
validates_presence_of :title, :content, :version
validates_uniqueness_of :versio... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/organization.rb | Ruby | mit | 19 | master | 1,445 | # frozen_string_literal: true
class Organization < ApplicationRecord
# TODO: Some of these attributes would be best managed in an organization/settings model and controller so
# that they can be managed by an organization admin (currently they can only be managed by an admin in the
# admin organization)
valida... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/agreement.rb | Ruby | mit | 19 | master | 396 | # frozen_string_literal: true
class Agreement < ApplicationRecord
acts_as_tenant(:organization)
belongs_to :organization
has_many :signed_agreements
has_many :versions, dependent: :destroy, class_name: 'AgreementVersion'
validates_presence_of :name
validates_uniqueness_to_tenant(:name, case_sensitive: fa... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/membership.rb | Ruby | mit | 19 | master | 650 | # frozen_string_literal: true
class Membership < ApplicationRecord
belongs_to :user
belongs_to :membership_type
before_validation :ensure_expiration
validate :check_expiration
validates_presence_of :effective
def expired?
expiration < Time.zone.today
end
private
def ensure_expiration
re... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/email_template.rb | Ruby | mit | 19 | master | 475 | # frozen_string_literal: true
class EmailTemplate < ApplicationRecord
acts_as_tenant(:organization)
PLACEHOLDERS = {
'%CARRIER_NAME%' => 'Name of checked out carrier',
'%DUE_DATE%' => 'Due date of carrier',
'%USER_NAME%' => 'First name of user receiving email'
}.freeze
validates_presence_of :name... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/user.rb | Ruby | mit | 19 | master | 3,862 | # frozen_string_literal: true
class User < ApplicationRecord
acts_as_tenant(:organization)
include User::FilterImpl
has_person_name
devise :database_authenticatable, :registerable,
:recoverable, :rememberable
validates :first_name, :last_name, :street_address, :city,
:state, :postal_co... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/signature.rb | Ruby | mit | 19 | master | 266 | # frozen_string_literal: true
class Signature < ApplicationRecord
belongs_to :user
belongs_to :agreement_version
validates_presence_of :signature, :signed_at
scope :active, -> { joins(:agreement_version).where('agreement_versions.active = ?', true) }
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/carrier.rb | Ruby | mit | 19 | master | 1,474 | # frozen_string_literal: true
class Carrier < ApplicationRecord
acts_as_tenant(:organization)
include AASM
include Carrier::FilterImpl
belongs_to :category
belongs_to :current_location, class_name: 'Location'
belongs_to :home_location, class_name: 'Location'
belongs_to :organization
has_many :loans,... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/loan.rb | Ruby | mit | 19 | master | 1,873 | # frozen_string_literal: true
class Loan < ApplicationRecord
include Loan::FilterImpl
belongs_to :carrier
belongs_to :borrower, class_name: 'User', optional: true, inverse_of: :loans # see presence validation below
belongs_to :checkout_volunteer, class_name: 'User', default: -> { Current.user }
belongs_to :... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/category.rb | Ruby | mit | 19 | master | 309 | # frozen_string_literal: true
class Category < ApplicationRecord
validates :name, presence: true, uniqueness: true
has_many :carriers
has_many :subcategories, class_name: 'Category',
foreign_key: 'parent_id'
belongs_to :parent, class_name: 'Category', optional: true
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/loan/filter_impl.rb | Ruby | mit | 19 | master | 1,829 | # frozen_string_literal: true
class Loan
module FilterImpl
extend ActiveSupport::Concern
included do
scope :search_carrier, ->(query) { joins(:carrier).where('carriers.model ilike ?', "%#{query}%") }
scope :with_due_date_before, ->(date) { where('due_date <= ?', "%#{date}%") }
scope :with_... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/carrier/filter_impl.rb | Ruby | mit | 19 | master | 1,271 | # frozen_string_literal: true
class Carrier
module FilterImpl
extend ActiveSupport::Concern
included do
scope :search_manufacturer, ->(query) { where('manufacturer ilike ?', "%#{query}%") }
scope :search_item_id, ->(query) { where('item_id ilike ?', "%#{query}%") }
scope :search_model, ->(... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | app/models/user/filter_impl.rb | Ruby | mit | 19 | master | 1,648 | # frozen_string_literal: true
class User
module FilterImpl
extend ActiveSupport::Concern
included do
scope :search_name, lambda(&method(:name_search))
scope :search_email, ->(email) { where('email ilike ?', "%#{email}%") }
scope :with_created_after, ->(date) { where('users.created_at > ?',... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/seeds.rb | Ruby | mit | 19 | master | 12,906 | # frozen_string_literal: true
require 'csv'
require 'uri'
include ActionView::Helpers::SanitizeHelper # included for strip_tags method to remove html from carrier descriptions
if Organization.count.zero?
puts "Creating organizations..."
Organization.create!(name: "Babywearing Admin", subdomain: "admin",
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/schema.rb | Ruby | mit | 19 | master | 8,725 | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
#... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20200208181232_create_memberships.rb | Ruby | mit | 19 | master | 342 | class CreateMemberships < ActiveRecord::Migration[5.2]
def change
create_table :memberships do |t|
t.references :user, foreign_key: true
t.references :membership_type, foreign_key: true
t.date :effective, null: false, index: true
t.date :expiration, null: false, index: true
t.timesta... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20191016050734_add_home_and_current_location_to_carrier.rb | Ruby | mit | 19 | master | 462 | class AddHomeAndCurrentLocationToCarrier < ActiveRecord::Migration[5.2]
def change
add_reference :carriers, :home_location, foreign_key: { to_table: :locations }
add_reference :carriers, :current_location, foreign_key: { to_table: :locations }
Carrier.all.each do |carrier|
carrier.update(home_locat... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20190728154543_add_volunteer_to_cart.rb | Ruby | mit | 19 | master | 201 | class AddVolunteerToCart < ActiveRecord::Migration[5.2]
def change
change_table :carts do |t|
t.rename :user_id, :member_id
t.integer :volunteer_id, nullable: false
end
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20190727180939_create_loans.rb | Ruby | mit | 19 | master | 258 | class CreateLoans < ActiveRecord::Migration[5.2]
def change
create_table :loans do |t|
t.integer :cart_id, nullable: false
t.integer :carrier_id, nullable: false
t.date :due_date, nullable: false
t.timestamps
end
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20200621184058_drop_signed_agreements.rb | Ruby | mit | 19 | master | 439 | class DropSignedAgreements < ActiveRecord::Migration[6.0]
def change
drop_table :signed_agreements do |t|
t.bigint :user_id
t.bigint :agreement_id
t.string :signature
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.index [:agreement_id], name: :index_s... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20190727141720_rolify_create_roles.rb | Ruby | mit | 19 | master | 441 | class RolifyCreateRoles < ActiveRecord::Migration[5.2]
def change
create_table(:roles) do |t|
t.string :name
t.references :resource, :polymorphic => true
t.timestamps
end
create_table(:users_roles, :id => false) do |t|
t.references :user
t.references :role
end
... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20190727202234_create_signed_agreements.rb | Ruby | mit | 19 | master | 234 | class CreateSignedAgreements < ActiveRecord::Migration[5.2]
def change
create_table :signed_agreements do |t|
t.belongs_to :user
t.belongs_to :agreement
t.string :signature
t.timestamps
end
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20200806162039_create_email_templates.rb | Ruby | mit | 19 | master | 392 | class CreateEmailTemplates < ActiveRecord::Migration[6.0]
def change
create_table :email_templates do |t|
t.references :organization, null: false, foreign_key: true
t.string :type, null: false
t.string :name
t.string :subject, null: false
t.text :body, null: false
t.string :whe... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20191024023740_merge_cart_and_loan.rb | Ruby | mit | 19 | master | 437 | class MergeCartAndLoan < ActiveRecord::Migration[5.2]
def change
add_reference :loans, :checkin_volunteer, foreign_key: { to_table: :users }
add_reference :loans, :checkout_volunteer, foreign_key: { to_table: :users }
add_reference :loans, :member, foreign_key: { to_table: :users }, null: false
add_c... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20200326184711_create_organizations.rb | Ruby | mit | 19 | master | 384 | class CreateOrganizations < ActiveRecord::Migration[6.0]
def change
create_table :organizations do |t|
t.string :name, null: false
t.string :subdomain, null: false, index: true
t.string :email
t.string :phone
t.text :notes
t.string :address
t.string :city
t.string :... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20191016053330_require_home_and_current_location_on_carrier.rb | Ruby | mit | 19 | master | 220 | class RequireHomeAndCurrentLocationOnCarrier < ActiveRecord::Migration[5.2]
def change
change_column_null :carriers, :home_location_id, false
change_column_null :carriers, :current_location_id, false
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20190726143702_create_categories.rb | Ruby | mit | 19 | master | 243 | class CreateCategories < ActiveRecord::Migration[5.2]
def change
create_table :categories do |t|
t.string :name, null: false
t.string :description
t.references :parent, index: true
t.timestamps
end
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20190726141822_create_carriers.rb | Ruby | mit | 19 | master | 363 | class CreateCarriers < ActiveRecord::Migration[5.2]
def change
create_table :carriers do |t|
t.string :item_id
t.string :name
t.string :manufacturer
t.string :model
t.string :color
t.integer :size
t.integer :location_id
t.integer :default_loan_length_days, :default ... |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20191109162417_drop_rolify_tables.rb | Ruby | mit | 19 | master | 316 | class DropRolifyTables < ActiveRecord::Migration[5.2]
def change
drop_table(:roles) do |t|
t.string :name
t.references :resource, :polymorphic => true
t.timestamps
end
drop_table(:users_roles, :id => false) do |t|
t.references :user
t.references :role
end
end
end |
github | rubyforgood/babywearing | https://github.com/rubyforgood/babywearing | db/migrate/20200322214338_activation_refactor.rb | Ruby | mit | 19 | master | 372 | class ActivationRefactor < ActiveRecord::Migration[5.2]
def up
remove_column :users, :deactivated_at
add_column :memberships, :blocked, :boolean, default: false
add_column :memberships, :notes, :text
end
def down
add_column :users, :deactivated_at, :datetime
remove_column :memberships, :block... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.