Skip to content

Instantly share code, notes, and snippets.

View kitsuneyo's full-sized avatar

Neil Wheatley kitsuneyo

View GitHub Profile
protected
def index(collection = [])
filtered = collection.where(filter_params)
render json: filtered.paginate(default_pagination),
fields: collection_fields, meta: index_meta(filtered)
end
private
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
require 'test_helper'
module V1
class PlatformsControllerTest < ActionDispatch::IntegrationTest
# tests
private
def default_attrs
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
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
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...
def update?
if user.admin?
true
elsif user.editor?
if article.created_by == user || article.published?
true
end
end
end
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
{
"data": {
"type": "place_countries",
"attributes": {
"name": "New Country",
"also_known_as": ['This', 'That']
}
}
}
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