This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected | |
def index(collection = []) | |
filtered = collection.where(filter_params) | |
render json: filtered.paginate(default_pagination), | |
fields: collection_fields, meta: index_meta(filtered) | |
end | |
private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationSerializer < ActiveModel::Serializer | |
def self.belongs_to_object(attribute, path_name) | |
belongs_to attribute do | |
include_data false | |
if obj_id = object.send(attribute) | |
path = "#{path_name}_url" | |
link(:related) { self.send(path, obj_id) } | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
module V1 | |
class PlatformsControllerTest < ActionDispatch::IntegrationTest | |
# tests | |
private | |
def default_attrs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Place::RegionCountry < ApplicationRecord | |
# RELATIONSHIPS | |
belongs_to :region, class_name: 'Place::Region' | |
belongs_to :country, class_name: 'Place::Country' | |
# VALIDATIONS | |
validates_uniqueness_of :country_id, scope: :region_id | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Game::Note.new | |
(irb):3: warning: toplevel constant Note referenced by Game::Note | |
=> #<Note id: nil, article_id: nil, type: nil, category: nil, body: nil, cite_url: nil, cite_title: nil, cite_website: nil, created_by_id: nil, created_at: nil, updated_at: nil> | |
# ^^ This is a new Note class object, not a Game::Note class object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error: | |
ArticleTest#test_title_cannot_be_more_than_250_chars: | |
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "article_summaries" does not exist | |
LINE 1: DELETE FROM "article_summaries" | |
^ | |
: DELETE FROM "article_summaries" | |
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "article_summaries" does not exist | |
LINE 8: WHERE a.attrelid = '"article_summaries"'::reg... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update? | |
if user.admin? | |
true | |
elsif user.editor? | |
if article.created_by == user || article.published? | |
true | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test 'old avatar file is deleted when user is updated with new avatar' do | |
@user.update(avatar: fixture_file_upload('files/image.gif')) | |
assert File.exist?(@user.reload.avatar.file.path) | |
old = @user.reload.avatar.file.path | |
@user.update(avatar: fixture_file_upload('files/image.gif')) | |
assert_not File.exist?(old) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"data": { | |
"type": "place_countries", | |
"attributes": { | |
"name": "New Country", | |
"also_known_as": ['This', 'That'] | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Place::Country < Place | |
# RELATIONSHIPS | |
belongs_to :parent, class_name: 'Place', optional: true | |
belongs_to :created_by, class_name: 'User' | |
has_many :subdivisions, class_name: 'Place::Subdivision', dependent: :destroy, | |
foreign_key: :parent_id |