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 | chordbook/chordbook | https://github.com/chordbook/chordbook | config/environments/test.rb | Ruby | mit | 87 | main | 2,612 | # 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!
Rails.application.configure do
# Settings... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | config/environments/development.rb | Ruby | mit | 87 | main | 2,765 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Make code changes take effect immediately without server restart.
config.enable_reloading = true
# Do not eager load code on boot.
config.eager... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | config/environments/production.rb | Ruby | mit | 87 | main | 3,696 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.enable_reloading = false
# Eager load code on boot for better performance and memory savings (ignor... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/application_system_test_case.rb | Ruby | mit | 87 | main | 1,111 | require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
# Enable forgery protection for system tests
setup do
ActionController::Base.allow_forgery_protection = true
end
# Restore forgery protection fo... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/test_helper.rb | Ruby | mit | 87 | main | 1,447 | ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
require "vcr"
require_relative "factories"
Flipper.configure do |config|
config.default { Flipper.new(Flipper::Adapters::Memory.new) }
end
class ActiveSupport::TestCase
include FactoryBot::Syntax::Methods
include Act... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/factories.rb | Ruby | mit | 87 | main | 1,795 | def refresh_index(model)
model.class.search_index.refresh if Searchkick.callbacks?
end
FactoryBot.define do
factory :artist do
name { Faker::Music.band }
after(:create) { |model| refresh_index(model) }
end
factory :album do
title { Faker::Music.album }
artist
after(:create) { |model| ref... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/system/editor_test.rb | Ruby | mit | 87 | main | 1,430 | require "application_system_test_case"
class EditorTest < ApplicationSystemTestCase
test "creating new song" do
visit "/songsheets/new"
assert_no_js_errors
fill_in_editor_field file_fixture("drunken-sailor.pro").read
# Updates preview
assert_content "Drunken Sailor"
assert_content "Traditio... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/sitemaps_controller_test.rb | Ruby | mit | 87 | main | 535 | require "test_helper"
class SitemapsControllerTest < ActionDispatch::IntegrationTest
test "/sitemaps.xml" do
get sitemaps_url(format: "xml")
assert_response :success
assert_select "sitemapindex>sitemap>loc", 5
end
SitemapsController::SITEMAPS.keys.each do |type|
test "/sitemaps/#{type}.xml" do
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/home_controller_test.rb | Ruby | mit | 87 | main | 355 | require "test_helper"
class Api::HomeControllerTest < ActionDispatch::IntegrationTest
test "show unauthenticated" do
get api_home_path(format: :json)
assert_response :success
end
test "show authenticated" do
user = create(:user)
get api_home_path(format: :json), headers: token_headers(user)
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/flipper_controller_test.rb | Ruby | mit | 87 | main | 802 | require "test_helper"
class Api::FlipperControllerTest < ActionDispatch::IntegrationTest
test "show as anonymous user with no features" do
get api_flipper_path
assert_response :success
assert_equal({}, response.parsed_body)
end
test "show as anonymous user with features" do
Flipper.enable :a
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/albums_controller_test.rb | Ruby | mit | 87 | main | 418 | require "test_helper"
class Api::AlbumsControllerTest < ActionDispatch::IntegrationTest
setup do
@album = create :album
end
test "index" do
get api_artist_albums_url(@album.artist, format: :json)
assert_response :success
body = JSON.parse(response.body)
assert_equal 1, body.length
end
t... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/authenticate_controller_test.rb | Ruby | mit | 87 | main | 2,522 | require "test_helper"
class Api::AuthenticateControllerTest < ActionDispatch::IntegrationTest
test "create" do
user = create(:user)
post api_authenticate_path(format: :json), params: {email: user.email, password: user.password}
assert_response :success
assert_not_nil response.headers["Access-Token"]... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/genres_controller_test.rb | Ruby | mit | 87 | main | 442 | require "test_helper"
class Api::GenresControllerTest < ActionDispatch::IntegrationTest
setup do
@genre = create :genre
end
test "index" do
get api_genres_url(format: :json)
assert_response :success
body = JSON.parse(response.body)
assert_equal 1, body.length
assert_equal @genre.name, bo... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/setlist_items_controller_test.rb | Ruby | mit | 87 | main | 1,533 | require "test_helper"
class Api::SetlistItemsControllerTest < ActionDispatch::IntegrationTest
setup do
@user = create :user
@setlist = create :setlist, user: @user
end
test "create unauthenticated" do
post api_setlist_items_url(@setlist)
assert_response :unauthorized
end
test "create someon... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/artists_controller_test.rb | Ruby | mit | 87 | main | 644 | require "test_helper"
class Api::ArtistsControllerTest < ActionDispatch::IntegrationTest
setup do
@artist = create :artist
end
test "index unauthorized" do
get api_artists_url(format: :json)
assert_response :unauthorized
end
test "index" do
@user = create(:user)
@user.library.add(@artis... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/setlist_controller_test.rb | Ruby | mit | 87 | main | 1,828 | require "test_helper"
class Api::SetlistsControllerTest < ActionDispatch::IntegrationTest
setup do
@user = create :user
end
test "show unauthenticated" do
get api_setlist_url(create(:setlist), format: :json)
assert_response :success
end
test "index requires authentication" do
get api_setlis... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/library_controller_test.rb | Ruby | mit | 87 | main | 1,968 | require "test_helper"
class Api::LibraryControllerTest < ActionDispatch::IntegrationTest
setup do
@user = create :user
end
test "create unauthenticated" do
post api_library_path
assert_response :unauthorized
end
test "create with valid params" do
songsheet = create(:songsheet)
assert_d... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/password_controller_test.rb | Ruby | mit | 87 | main | 1,784 | require "test_helper"
class Api::PasswordControllerTest < ActionDispatch::IntegrationTest
setup do
@user = create(:user)
end
test "create" do
perform_enqueued_jobs do
post api_password_path(format: :json), params: {email: @user.email}
end
assert_response 200
assert_emails 1
assert ... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/discover_controller_test.rb | Ruby | mit | 87 | main | 314 | require "test_helper"
class Api::DiscoverControllerTest < ActionDispatch::IntegrationTest
test "includes top setlists for app user" do
create :setlist, user: User.app
get api_discover_path(format: :json)
assert_response :success
assert_equal 4, response.parsed_body["setlists"].size
end
end |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/tracks_controller_test.rb | Ruby | mit | 87 | main | 726 | require "test_helper"
class Api::TracksControllerTest < ActionDispatch::IntegrationTest
setup do
@track = create :track
end
test "index with album" do
get api_artist_album_tracks_url(@track.artist, @track.album, format: :json)
assert_response :success
body = JSON.parse(response.body)
assert_... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/songsheets_controller_test.rb | Ruby | mit | 87 | main | 3,297 | require "test_helper"
class Api::SongsheetsControllerTest < ActionDispatch::IntegrationTest
setup do
@artist = create :artist, name: "John Mayer"
@songsheet = create :songsheet, title: "Why Georgia", artists: [@artist],
metadata: {media: "vid1"}
end
test "GET /songsheets unauthorized" do
get a... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/users_controller_test.rb | Ruby | mit | 87 | main | 1,330 | require "test_helper"
class Api::UsersControllerTest < ActionDispatch::IntegrationTest
test "create with valid params" do
assert_difference -> { AccessToken.count } => 1 do
assert_enqueued_with job: ActionMailer::MailDeliveryJob do
post api_users_path(format: :json), params: {user: attributes_for(:... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/controllers/api/search_controller_test.rb | Ruby | mit | 87 | main | 1,188 | require "test_helper"
class Api::SearchControllerTest < ActionDispatch::IntegrationTest
setup do
with_search do
@artist = create :artist, name: "Jeff Buckly"
@album = create :album, artist: @artist, title: "Hallelujah"
end
end
test "index" do
get api_search_url(q: @artist.name, format: :... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/jobs/associate_songsheet_metadata_test.rb | Ruby | mit | 87 | main | 3,055 | require "test_helper"
class AssociateSongsheetMetadataTest < ActiveJob::TestCase
test "associates with existing artist and track" do
with_search Artist do
track = create :track, title: "Somewhere Over the Rainbow"
perform_enqueued_jobs only: AssociateSongsheetMetadata do
songsheet = create :... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/jobs/parse_songsheet_metadata_job_test.rb | Ruby | mit | 87 | main | 567 | require "test_helper"
class ParseSongsheetMetadataJobTest < ActiveJob::TestCase
test "updates metadata" do
songsheet = create :songsheet, source: "{t: The Title}\n{key: C}"
ParseSongsheetMetadataJob.new.perform(songsheet)
assert_equal "The Title", songsheet.title
assert_equal({"key" => "C"}, songshee... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/jobs/update_rank_test.rb | Ruby | mit | 87 | main | 3,979 | require "test_helper"
class UpdateRankTest < ActiveJob::TestCase
test "ranks songsheets by plays" do
played_many = create :songsheet
unplayed = create :songsheet
played_once = create :songsheet
play played_many, times: 2
play played_once
UpdateRank.new.perform
assert_equal 1, played_ma... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/jobs/youtube_lookup_test.rb | Ruby | mit | 87 | main | 365 | require "test_helper"
class YoutubeLookupTest < ActiveJob::TestCase
test "finds youtube videos for track" do
track = create :track, title: "Banana Pancakes", artist: create(:artist, name: "Jack Johnson")
VCR.use_cassette("youtube/banana_pancakes") do
YoutubeLookup.new.perform track
assert_equal ... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/jobs/generated_setlists_test.rb | Ruby | mit | 87 | main | 1,807 | require "test_helper"
class GeneratedSetlistsTest < ActiveJob::TestCase
test "enqueues jobs" do
GeneratedSetlists.new.perform
assert_enqueued_jobs 8
end
test "trending" do
songsheets = 101.times.map { |i| create :songsheet, rank: i + 1 }
GeneratedSetlists::Trending.perform_now
trending = U... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/jobs/lookup_metadata_test.rb | Ruby | mit | 87 | main | 2,129 | require "test_helper"
class LookupMetadataTest < ActiveJob::TestCase
setup do
LookupMetadata.throttle = Throttle.new(0)
end
test "new artist" do
VCR.use_cassette("tadb/the_beatles") do
assert_difference -> { Album.count } => 51, -> { Artist.count } => 1 do
LookupMetadata.new.perform "The B... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/jobs/import/ozbcoz_test.rb | Ruby | mit | 87 | main | 1,572 | require "test_helper"
class Import::OzbcozTest < ActiveJob::TestCase
test "all" do
VCR.use_cassette("ozbcoz") do
assert_enqueued_jobs 3322 do
Import::Ozbcoz.all
end
end
end
test "perform" do
assert_difference -> { Songsheet.count } do
songsheet = import "https://ozbcoz.com/... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/jobs/musix_match/get_lyrics_test.rb | Ruby | mit | 87 | main | 597 | require "test_helper"
class MusixMatch::MatchTrackJobTest < ActiveJob::TestCase
setup do
Flipper.enable :musixmatch
end
test "updates reference with lyrics" do
reference = Reference.create! record: create(:track), source: :musixmatch, identifier: 277941381, data: {"track_rating" => 57}
VCR.use_casse... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/jobs/musix_match/match_track_job_test.rb | Ruby | mit | 87 | main | 823 | require "test_helper"
class MusixMatch::MatchTrackJobTest < ActiveJob::TestCase
setup do
Flipper.enable :musixmatch
end
test "saves reference to matched track" do
artist = create :artist, name: "The Beatles"
album = create :album, title: "Let It Be", artist: artist
track = create :track, title: ... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/unit/musix_match_test.rb | Ruby | mit | 87 | main | 352 | require "test_helper"
class MusixMatchTest < ActiveSupport::TestCase
test "match_track" do
VCR.use_cassette("musixmatch/matcher.track.get") do
result = MusixMatch.match_track(q_artist: "The Beatles", q_track: "Let It Be", q_album: "Let It Be")
assert_equal 277941381, result["message"]["body"]["track"... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/unit/throttle_test.rb | Ruby | mit | 87 | main | 639 | require "test_helper"
require "throttle"
class ThrottleTest < ActiveSupport::TestCase
test "sanity" do
duration = 0.1.second
throttle = Throttle.new(duration)
count = 0
start_at = Time.now
threads = 5.times.map do
Thread.new do
5.times do
throttle.call { count += 1 }
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/album_test.rb | Ruby | mit | 87 | main | 1,556 | require "test_helper"
class AlbumTest < ActiveSupport::TestCase
include ActiveJob::TestHelper
test "gets genre from theaudiodb reference" do
album = create(:album)
create(:reference, source: :theaudiodb, record: album, data: {strGenre: "R&B"})
assert_equal album.reload.genre.name, "R&B"
end
test ... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/artist_test.rb | Ruby | mit | 87 | main | 3,159 | require "test_helper"
class ArtistTest < ActiveSupport::TestCase
test "starts_with finds letter" do
norah = create :artist, name: "Norah Jones"
ed = create :artist, name: "Ed Sheeran"
three = create :artist, name: "3 Doors Down"
assert_equal Artist.starts_with(:name, "N").to_a, [norah]
assert_eq... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/track_test.rb | Ruby | mit | 87 | main | 1,399 | require "test_helper"
class TrackTest < ActiveSupport::TestCase
test "adds metadata strMusicVid to media" do
track = create :track, media: ["https://www.youtube.com/watch?v=6XIBdSLRz3o"]
create :reference, record: track, source: :theaudiodb, data: {"strMusicVid" => "http://www.youtube.com/watch?v=T0l_6Zw1828... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/reference_test.rb | Ruby | mit | 87 | main | 279 | require "test_helper"
class ReferenceTest < ActiveSupport::TestCase
test "data= merges values" do
reference = Reference.new(data: {a: 1, b: 2})
reference.data = {"b" => 2, :c => 3}
assert_equal({a: 1, b: 2, c: 3}.with_indifferent_access, reference.data)
end
end |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/access_token_test.rb | Ruby | mit | 87 | main | 2,232 | require "test_helper"
class AccessTokenTest < ActiveSupport::TestCase
test "can encode and decode a token" do
expected = create :access_token
decoded = AccessToken.validate(expected.encode)
assert_equal expected, decoded
assert expected.jti
assert expected.created_at
assert expected.expire_a... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/user_test.rb | Ruby | mit | 87 | main | 1,518 | require "test_helper"
class UserTest < ActiveSupport::TestCase
test "validates email" do
refute build(:user, email: nil).valid?
refute build(:user, email: "").valid?
refute build(:user, email: "nope").valid?
# Technically valid
assert build(:user, email: "a@b").valid?
assert build(:user, ema... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/short_identifier_test.rb | Ruby | mit | 87 | main | 343 | require "test_helper"
class SearchTest < ActiveSupport::TestCase
test "short_id" do
token = create :access_token
assert_match(/\Ax[0-9a-z]{19,22}\z/i, token.uid)
assert_equal token.uid, token.to_param
assert_equal token, ShortIdentifier.locate(token.uid)
assert_equal token, AccessToken.find_by_ui... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/search_test.rb | Ruby | mit | 87 | main | 960 | require "test_helper"
class SearchTest < ActiveSupport::TestCase
setup do
with_search do
@artist = create(:artist, name: "Ed Sheeran")
@album = create(:album, title: "=", artist: @artist)
@track = create(:track, title: "Shivers", album: @album)
@songsheet = create(:songsheet, title: "Bad ... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/songsheet_test.rb | Ruby | mit | 87 | main | 1,380 | require "test_helper"
class SongsheetTest < ActiveSupport::TestCase
test "moves metadata with matching attribute name to stored attribute" do
songsheet = Songsheet.create!(metadata: {title: "Title", subtitle: "Subtitle"})
assert_equal "Title", songsheet.title
assert_nil songsheet.metadata["title"]
end
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/duration_test.rb | Ruby | mit | 87 | main | 497 | require "test_helper"
class DurationTest < ActiveSupport::TestCase
test "parses mm:ss" do
assert_equal 0, Duration.parse("0:00").usec
assert_equal 193000, Duration.parse("3:13").usec
assert_equal 71100, Duration.parse("1:11.1").usec
assert_equal 703000, Duration.parse("11:43").usec
end
test "par... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/concerns/viewable_test.rb | Ruby | mit | 87 | main | 724 | require "test_helper"
class ViewableTest < ActiveSupport::TestCase
test "viewed scope only includes distinct viewed records" do
viewed = create :songsheet
create :songsheet # unviewed
create :event, :view, record: viewed
assert_equal [viewed], Songsheet.viewed
end
test "viewed_by scope only in... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/models/concerns/mergeable_test.rb | Ruby | mit | 87 | main | 541 | require "test_helper"
class MergeableTest < ActiveSupport::TestCase
test "copies attributes and associations" do
songsheet1 = create(:songsheet, setlists: [create(:setlist)])
songsheet2 = create(:songsheet, setlists: [create(:setlist)])
user = create(:user)
user.library.add(songsheet2)
assert_d... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/mailers/user_mailer_test.rb | Ruby | mit | 87 | main | 647 | require "test_helper"
class UserMailerTest < ActionMailer::TestCase
test "welcome" do
user = create(:user)
email = UserMailer.with(user: user).welcome
assert_emails 1 do
email.deliver_now
end
assert_equal [user.email], email.to
end
test "forgot_password" do
user = create(:user)
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/mailers/previews/user_mailer_preview.rb | Ruby | mit | 87 | main | 277 | # Preview all emails at http://localhost:3000/rails/mailers/password_mailer
class UserMailerPreview < ActionMailer::Preview
def welcome
UserMailer.with(user: User.first).welcome
end
def forgot_password
UserMailer.with(user: User.first).forgot_password
end
end |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | test/integration/authentication_test.rb | Ruby | mit | 87 | main | 1,182 | require "test_helper"
class AuthenticationTest < ActionDispatch::IntegrationTest
test "unauthenticated" do
post "/setlists.json", params: {setlist: attributes_for(:setlist)}
assert_response 401
end
test "with valid token" do
post "/setlists.json", params: {setlist: attributes_for(:setlist)},
h... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | lib/throttle.rb | Ruby | mit | 87 | main | 542 | # Only allow a thing to happen once in the given duration
class Throttle
def initialize(duration = 1.second)
@duration = duration
@mutex = Mutex.new
@clock = Time.new(0)
end
def call(&block)
@mutex.synchronize do
# How long do we need to wait for the next call?
wait = @duration - (Tim... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | lib/musix_match.rb | Ruby | mit | 87 | main | 511 | module MusixMatch
extend self
include HTTParty
API_KEY = ENV["MUSIXMATCH_API_KEY"] || "test"
base_uri "https://api.musixmatch.com"
raise_on 400..600
default_params apikey: API_KEY
logger Rails.logger
format :json
def match_track(params = {})
get "/ws/1.1/matcher.track.get", query: params
end
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | lib/tasks/data.rake | Ruby | mit | 87 | main | 2,373 | def track_info(track)
return unless track
"#{track.title} (#{track.listeners}) - by #{track.artist.name} #{track.album.title} #{track.album.released}"
end
namespace :data do
task default: [:reassociate, :cleanup_artists]
task reassociate: :environment do
before = Songsheet.where(track_id: nil).count
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api_controller.rb | Ruby | mit | 87 | main | 1,771 | class ApiController < ActionController::API
include Authentication
include ActionController::Helpers
helper ApplicationHelper
# Authenticate by default. Call `skip_before_action :authenticate!` on actions that don't need it
before_action :authenticate!
before_action :set_paper_trail_whodunnit
private
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/content_controller.rb | Ruby | mit | 87 | main | 425 | class ContentController < ApiController
skip_before_action :authenticate!
def ping
# Execute empty query to ensure database access
ActiveRecord::Base.connection.execute("")
Searchkick.client.ping
head :ok
end
CHANGELOG = Commonmarker.to_html(Rails.root.join("Changelog.md").read, options: {par... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/sitemaps_controller.rb | Ruby | mit | 87 | main | 486 | class SitemapsController < ApplicationController
caches_page :index, :show
# Cache for the day
self.page_cache_directory = -> {
Rails.root.join("tmp/cache/page", Date.today.to_s)
}
SITEMAPS = {
genres: Genre,
songsheets: Songsheet,
artists: Artist,
albums: Album,
setlists: Setlist
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/flipper_controller.rb | Ruby | mit | 87 | main | 257 | class Api::FlipperController < ApiController
skip_before_action :authenticate!
def show
features = Flipper.features.map do |feature|
[feature.key, Flipper.enabled?(feature.key, current_user)]
end
render json: features.to_h
end
end |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/albums_controller.rb | Ruby | mit | 87 | main | 479 | class Api::AlbumsController < ApiController
skip_before_action :authenticate!
def index
@albums = current_scope.with_attachments.order_by_popular
.includes(:artist).merge(Artist.with_attachments).page(params[:page])
set_pagination_header @albums
fresh_when @albums
end
def show
@album = A... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/authenticate_controller.rb | Ruby | mit | 87 | main | 664 | class Api::AuthenticateController < ApiController
rescue_from ActiveRecord::RecordNotFound, with: :access_denied
skip_before_action :authenticate!, :current_token, except: :destroy
def create
@user = User.authenticate!(params[:email], params[:password])
ahoy.authenticate @user
issue_token @user
r... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/songsheets_controller.rb | Ruby | mit | 87 | main | 1,577 | class Api::SongsheetsController < ApiController
before_action :set_songsheet, only: %i[show update destroy]
skip_before_action :authenticate!, only: %i[index show]
# GET /songsheets.json
def index
@songsheets = current_scope.includes_track.page(params[:page])
set_pagination_header @songsheets
fresh... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/tracks_controller.rb | Ruby | mit | 87 | main | 433 | class Api::TracksController < ApiController
skip_before_action :authenticate!
def index
@tracks = current_scope.order_by_popular.includes(:artist, album: :artist)
.merge(Album.with_attachments).merge(Artist.with_attachments).page(params[:page])
set_pagination_header @tracks
fresh_when @tracks
e... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/genres_controller.rb | Ruby | mit | 87 | main | 340 | class Api::GenresController < ApiController
skip_before_action :authenticate!
def index
@genres = Genre.with_attachments.order_by_popular.page(params[:page])
set_pagination_header @genres
fresh_when @genres
end
def show
@genre = Genre.find_by_uid(params[:id])
track_view @genre
fresh_wh... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/library_controller.rb | Ruby | mit | 87 | main | 491 | class Api::LibraryController < ApiController
def create
item = current_user.library.add(record)
if item.valid?
head :created
else
render_error record: item
end
end
def show
current_user.library.find_by!(item: record)
head :ok
end
def destroy
current_user.library.find_... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/autocomplete_controller.rb | Ruby | mit | 87 | main | 444 | class Api::AutocompleteController < ApiController
skip_before_action :authenticate!
def index
case params[:type]
when "title", "t"
@results = Track.includes(:album, :artist).starts_with(:title, params[:query]).limit(10)
when "artist"
@results = Artist.starts_with(:name, params[:query]).limi... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/users_controller.rb | Ruby | mit | 87 | main | 537 | class Api::UsersController < ApiController
skip_before_action :authenticate!, only: :create
def create
@user = User.new(user_params)
if @user.save
ahoy.authenticate @user
issue_token @user
UserMailer.with(user: @user).welcome.deliver_later(wait: 1.hour)
render @user, status: :create... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/home_controller.rb | Ruby | mit | 87 | main | 1,228 | class Api::HomeController < ApiController
skip_before_action :authenticate!
def show
@featured_setlist = User.app.setlists.with_attachments.order_by_popular.first
@sections = [
Section.new(
name: "Keep on playing",
scope: Songsheet.viewed_by(current_user).includes_track,
form... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/setlist_items_controller.rb | Ruby | mit | 87 | main | 829 | class Api::SetlistItemsController < ApiController
before_action :find_setlist, except: :index
before_action :find_item, only: [:update, :destroy]
def create
songsheet = Songsheet.find_by_uid(params[:id])
current_scope.create!(songsheet: songsheet)
current_user.library.add(songsheet)
head :created... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/setlists_controller.rb | Ruby | mit | 87 | main | 777 | class Api::SetlistsController < ApiController
skip_before_action :authenticate!, only: %i[show]
def index
@setlists = current_user.setlists.includes(:user).with_attachments.order_by_recent.page(params[:page])
set_pagination_header @setlists
fresh_when @setlists
end
def show
@setlist = Setlist.... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/history_controller.rb | Ruby | mit | 87 | main | 277 | class Api::HistoryController < ApiController
skip_before_action :authenticate!
# GET /history.json
def show
@songsheets = Songsheet.viewed_by(current_user).includes_track.page(params[:page])
set_pagination_header @songsheets
fresh_when @songsheets
end
end |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/password_controller.rb | Ruby | mit | 87 | main | 986 | class Api::PasswordController < ApiController
skip_before_action :authenticate!
wrap_parameters false
before_action :find_user_by_token, only: %i[show update]
rescue_from ActiveSupport::MessageVerifier::InvalidSignature do
render_error "Your password reset token is expired. Please try again.", status: :unau... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/artists_controller.rb | Ruby | mit | 87 | main | 488 | class Api::ArtistsController < ApiController
skip_before_action :authenticate!
def index
@artists = current_scope.with_attachments.order_by_alphabetical.page(params[:page])
set_pagination_header @artists
fresh_when @artists
end
def show
@artist = Artist.with_attachments.find_by_uid(params[:id]... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/api/search_controller.rb | Ruby | mit | 87 | main | 986 | class Api::SearchController < ApiController
skip_before_action :authenticate!
skip_before_action :track_ahoy_visit, only: :convert
def index
@search = Search.new(
query: params[:q],
load: false,
models: models,
page: params[:page],
per_page: 25,
track: {user_id: current_us... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/concerns/authentication.rb | Ruby | mit | 87 | main | 2,240 | module Authentication
extend ActiveSupport::Concern
included do
rescue_from AccessToken::Invalid, JWT::DecodeError, with: :access_denied
# Make sure we have a valid token before running any action
before_action :current_token
helper_method :current_user
end
private
# Render a 401 response... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/concerns/render_page_cache.rb | Ruby | mit | 87 | main | 436 | # Extension to actionpack-page_caching gem to render cache with custom directory
module RenderPageCache
extend ActiveSupport::Concern
include ActionController::Caching::Pages
def render_cache
file = page_cache.send(:cache_path, request.path, nil)
render file: file if File.exist?(file)
end
class_meth... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/controllers/concerns/alpha_paginate.rb | Ruby | mit | 87 | main | 350 | module AlphaPaginate
extend ActiveSupport::Concern
LETTERS = ["#"] + ("A".."Z").to_a
included do
scope :starts_with, ->(key, letter) {
result = if letter == "#"
where(arel_table[key].matches_regexp("^[0-9]"))
else
where(arel_table[key].matches(letter + "%"))
end
resu... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/mailers/application_mailer.rb | Ruby | mit | 87 | main | 219 | class ApplicationMailer < ActionMailer::Base
SUPPORT_FROM = ENV.fetch("MAIL_FROM", "Chord Book <help@chordbook.app>")
NEWS_FROM = ENV.fetch("MAIL_FROM", "Chord Book <whatsnew@chordbook.app>")
layout "mailer"
end |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/mailers/user_mailer.rb | Ruby | mit | 87 | main | 301 | class UserMailer < ApplicationMailer
def welcome
@user = params[:user]
mail to: @user.email, subject: "Thanks for using Chord Book", from: NEWS_FROM
end
def forgot_password
@user = params[:user]
mail to: @user.email, subject: "Reset your password", from: SUPPORT_FROM
end
end |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/helpers/application_helper.rb | Ruby | mit | 87 | main | 438 | module ApplicationHelper
def variant_url(attachment, variant_name)
return unless attachment&.variable?
variant = attachment.variant(variant_name)
if variant.send(:processed?) && variant.service.public?
# Variant is processed and public, link directly to it.
variant.url
else
# Varian... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/songsheet.rb | Ruby | mit | 87 | main | 2,800 | class Songsheet < ApplicationRecord
include AlphaPaginate
include Viewable
include Mergeable
has_paper_trail
belongs_to :track, optional: true, counter_cache: true
has_many :artist_works, as: :work, dependent: :destroy
has_many :artists, through: :artist_works
has_many :library_items, as: :item, depen... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/library_item.rb | Ruby | mit | 87 | main | 236 | class LibraryItem < ApplicationRecord
belongs_to :user
belongs_to :item, polymorphic: true
validates :item_type, inclusion: %w[Songsheet Artist Album Setlist]
validates_uniqueness_of :user_id, scope: [:item_id, :item_type]
end |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/reference.rb | Ruby | mit | 87 | main | 349 | class Reference < ApplicationRecord
belongs_to :record, polymorphic: true
enum :source, musixmatch: "musixmatch", theaudiodb: "theaudiodb"
before_save { record.reference_updated self }
def data=(new_data)
write_attribute :data, data.merge(new_data)
end
def data
(read_attribute(:data) || {}).with_... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/album.rb | Ruby | mit | 87 | main | 2,061 | class Album < ApplicationRecord
include Referenceable
include Viewable
belongs_to :artist
belongs_to :genre, optional: true
has_many :tracks, -> { Track.order_by_number }, dependent: :destroy
has_many :library_items, as: :item, dependent: :destroy
before_validation :validate_released_year
before_save ... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/search.rb | Ruby | mit | 87 | main | 604 | class Search
MODELS = [Songsheet, Artist, Album, Setlist]
MODEL_INCLUDES = {
Songsheet => [{track: :album}],
Album => [:artist]
}
DEFAULTS = {
models: MODELS,
fields: ["title^2", "everything"],
model_includes: MODEL_INCLUDES,
boost_by: [:boost],
match: :word_start
}
def initial... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/genre.rb | Ruby | mit | 87 | main | 717 | class Genre < ApplicationRecord
include Viewable
has_many :artists, -> { Artist.order_by_popular }, dependent: :nullify
has_many :tracks, -> { Track.order_by_popular }, dependent: :nullify
has_many :albums, -> { Album.order_by_popular }, dependent: :nullify
has_paper_trail
has_one_attached :image do |att... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/section.rb | Ruby | mit | 87 | main | 489 | class Section
include ActiveModel::Model
include ActiveModel::Attributes
attribute :name, :string
attribute :scope
attribute :scopes, array: true
attribute :limit, :integer, default: 12
attribute :format, :string, default: "item"
attribute :href, :string
def items
@items ||= if scope
scope... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/user.rb | Ruby | mit | 87 | main | 1,655 | class User < ApplicationRecord
has_many :access_tokens, dependent: :delete_all
has_many :owned_setlists, class_name: "Setlist", dependent: :destroy
has_many :library, class_name: "LibraryItem", dependent: :destroy do
def add(item)
find_or_create_by(item: item)
end
end
has_many :artists, through:... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/artist.rb | Ruby | mit | 87 | main | 3,231 | class Artist < ApplicationRecord
include AlphaPaginate
include Referenceable
include Viewable
has_paper_trail
has_many :albums, dependent: :destroy
has_many :tracks, dependent: :destroy
has_many :artist_works, dependent: :destroy
has_many :songsheets, through: :artist_works, source: :work, source_type... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/access_token.rb | Ruby | mit | 87 | main | 2,906 | class AccessToken < ApplicationRecord
# Module to tag errors with
module Invalid; end
# Signing secret derived from secret_key_base
class_attribute :secret, default: Rails.application.key_generator.generate_key("access_token")
# Default expiry for access tokens
class_attribute :expiry, default: 1.hour
... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/application_record.rb | Ruby | mit | 87 | main | 278 | class ApplicationRecord < ActiveRecord::Base
include ShortIdentifier
self.abstract_class = true
before_save :strip_attrs
private
def strip_attrs
changes.each do |attr, (_, value)|
write_attribute attr, value.strip if value.is_a?(String)
end
end
end |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/setlist.rb | Ruby | mit | 87 | main | 1,577 | class Setlist < ApplicationRecord
include Viewable
has_paper_trail
belongs_to :user
has_many :items, -> { order(position: :asc) }, class_name: "SetlistItem", dependent: :destroy,
after_add: :update_thumbnails, after_remove: :update_thumbnails
has_many :songsheets, through: :items
has_many :tracks, thr... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/track.rb | Ruby | mit | 87 | main | 2,133 | class Track < ApplicationRecord
include AlphaPaginate
include Referenceable
include PgSearch::Model
has_paper_trail
belongs_to :artist
belongs_to :album, optional: true
belongs_to :genre, optional: true
has_many :songsheets, dependent: :nullify
scope :order_by_has_songsheet, -> {
order(Arel.sq... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/duration.rb | Ruby | mit | 87 | main | 466 | class Duration
attr_reader :usec
def self.parse(input)
if input.is_a?(String) && input.include?(":")
min, sec = input.split(":", 2)
seconds = (min.to_i * 60) + sec.to_f
new(seconds * 1000)
else
new(input.to_f * 1000)
end
end
def initialize(usec)
@usec = usec.round
end... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/concerns/viewable.rb | Ruby | mit | 87 | main | 508 | module Viewable
extend ActiveSupport::Concern
included do
scope :viewed, -> {
joins(
"JOIN (
SELECT uuid(ahoy_events.properties->>'id') as record_id, user_id, MAX(time) AS time
FROM ahoy_events
WHERE name = 'view'
GROUP BY record_id, user_id
) views... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/concerns/mergeable.rb | Ruby | mit | 87 | main | 1,047 | module Mergeable
IGNORED_ATTRIBUTES = %w[id created_at updated_at]
IGNORED_ASSOCIATIONS = %w[versions]
# Merge the other object into this object
def merge(other)
raise ArgumentError, "Can't merge #{other.class} with #{self.class}" unless is_a?(other.class)
other.attributes.without(IGNORED_ATTRIBUTES).... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/concerns/referenceable.rb | Ruby | mit | 87 | main | 228 | module Referenceable
extend ActiveSupport::Concern
included do
has_many :references, as: :record, dependent: :destroy
has_one :theaudiodb_reference, -> { theaudiodb }, class_name: "Reference", as: :record
end
end |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/models/concerns/short_identifier.rb | Ruby | mit | 87 | main | 753 | module ShortIdentifier
extend ActiveSupport::Concern
PREFIXES = {
"x" => "AccessToken",
"r" => "Album",
"a" => "Artist",
"g" => "Genre",
"s" => "Setlist",
"c" => "Songsheet",
"t" => "Track",
"u" => "User"
}.freeze
# Unique prefixed short id
def uid
ShortIdentifier.generat... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/jobs/update_rank.rb | Ruby | mit | 87 | main | 5,455 | # Updates `rank` column on all models
class UpdateRank < ApplicationJob
queue_as :low
WINDOW = 1.month
def perform
rank_songsheets
rank_tracks
rank_albums
rank_artists
rank_genres
end
# Rank songsheets by:
# 1. Number of distinct recent players (all anonymous users count as 1)
# 2. ... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/jobs/lookup_metadata.rb | Ruby | mit | 87 | main | 2,368 | require "throttle"
class LookupMetadata < ApplicationJob
include HTTParty
API_KEY = ENV["THEAUDIODB_API_KEY"] || "2" # default public key
base_uri "https://www.theaudiodb.com"
raise_on 400..600
queue_as :metadata
delegate :get, :path, to: :class
class_attribute :throttle, default: Throttle.new(2.5.seco... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/jobs/generated_setlists.rb | Ruby | mit | 87 | main | 591 | class GeneratedSetlists < ApplicationJob
def perform
Trending.perform_later
WhatsNew.perform_later
RecentlyUpdated.perform_later
Favorites.perform_later
Decades.perform_later
Unmatched.perform_later
TooManyVersions.perform_later
KeyOf.perform_later
end
def update_setlist(title, at... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/jobs/download_attachment.rb | Ruby | mit | 87 | main | 590 | class DownloadAttachment < ApplicationJob
include HTTParty
queue_as :low
raise_on 400..600
def perform(record, attachable, urls, client: DownloadAttachment)
src = Array(urls).map(&:presence).compact.first
attachment = record.send(attachable)
if src && (!attachment.attached? || attachment.metadata... |
github | chordbook/chordbook | https://github.com/chordbook/chordbook | app/jobs/performable_method.rb | Ruby | mit | 87 | main | 231 | # Perform any method later
#
# Usage:
# PerformableMethod.perform_later(thing, :method, *args)
#
class PerformableMethod < ApplicationJob
queue_as :low
def perform(target, method, ...)
target.send(method, ...)
end
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.