From b6943fc58c196a9cb32dce4e91f053b9f8e5b417 Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Wed, 24 Oct 2018 23:02:23 -0600 Subject: [PATCH] More styling edits --- app/models/announcement.rb | 1 - app/models/book.rb | 16 ++++++++-------- app/models/discussion.rb | 1 - app/models/reading.rb | 8 +++----- app/models/shelving.rb | 6 +++--- app/models/user.rb | 8 +++----- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/app/models/announcement.rb b/app/models/announcement.rb index bb44899..8d85e51 100644 --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -2,5 +2,4 @@ class Announcement < ApplicationRecord validates_presence_of :body, :club_id belongs_to :club - end diff --git a/app/models/book.rb b/app/models/book.rb index e6f8479..9aaa998 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -20,18 +20,18 @@ def self.check_if_duplicate(book_params) def self.only_with_ratings distinct.select('books.item, r.book_id, COUNT(r.book_id) AS review_count, AVG(r.value)') - .joins('INNER JOIN ratings AS r ON books.id = r.book_id') - .group('r.book_id, books.item') - .order('avg DESC') - .limit('20') + .joins('INNER JOIN ratings AS r ON books.id = r.book_id') + .group('r.book_id, books.item') + .order('avg DESC') + .limit('20') end def self.change_count(action, bookshelf) case action - when 'inc' - bookshelf.update(book_count: bookshelf.book_count += 1) - when 'dec' - bookshelf.update(book_count: bookshelf.book_count -= 1) + when 'inc' + bookshelf.update(book_count: bookshelf.book_count += 1) + when 'dec' + bookshelf.update(book_count: bookshelf.book_count -= 1) end end end diff --git a/app/models/discussion.rb b/app/models/discussion.rb index 3ecb3fa..d65ffcd 100644 --- a/app/models/discussion.rb +++ b/app/models/discussion.rb @@ -4,5 +4,4 @@ class Discussion < ApplicationRecord belongs_to :reading belongs_to :user has_many :comments, dependent: :destroy - end diff --git a/app/models/reading.rb b/app/models/reading.rb index a537b98..9bd90d7 100644 --- a/app/models/reading.rb +++ b/app/models/reading.rb @@ -1,12 +1,11 @@ class Reading < ApplicationRecord validates_presence_of :book_id, :club_id - validates_uniqueness_of :book_id, { scope: :club_id } + validates_uniqueness_of :book_id, scope: :club_id belongs_to :club belongs_to :book has_many :discussions, dependent: :destroy - def self.handle_archive(id) to_archive = Reading.find(id) to_archive.is_current = false @@ -16,8 +15,7 @@ def self.handle_archive(id) def self.find_current(club) select("books.item, books.id, readings.id AS reading_id, readings.club_id, readings.start_date, readings.finish_date") - .joins("INNER JOIN books ON readings.book_id = books.id") - .where("readings.club_id = #{club.id} AND readings.is_current = true") + .joins("INNER JOIN books ON readings.book_id = books.id") + .where("readings.club_id = #{club.id} AND readings.is_current = true") end - end diff --git a/app/models/shelving.rb b/app/models/shelving.rb index 62d547d..cadbdf2 100644 --- a/app/models/shelving.rb +++ b/app/models/shelving.rb @@ -1,13 +1,13 @@ class Shelving < ApplicationRecord validates_presence_of :bookshelf_id, :book_id - validates_uniqueness_of :book_id, { scope: :bookshelf_id } + validates_uniqueness_of :book_id, scope: :bookshelf_id belongs_to :book belongs_to :bookshelf def self.with_book(shelf_id) select("books.item, books.id, shelvings.id AS shelving_id, shelvings.bookshelf_id") - .joins("INNER JOIN books ON shelvings.book_id = books.id") - .where("shelvings.bookshelf_id = #{shelf_id}") + .joins("INNER JOIN books ON shelvings.book_id = books.id") + .where("shelvings.bookshelf_id = #{shelf_id}") end end diff --git a/app/models/user.rb b/app/models/user.rb index 33ac3af..c8c287f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -24,9 +24,7 @@ class User < ApplicationRecord def self.valid_login?(email, password) user = find_by(email: email) - if user && user.authenticate(password) - user - end + user if user&.authenticate(password) end def allow_token_to_be_used_only_once @@ -45,8 +43,8 @@ def self.with_unexpired_token(token, period) private def build_default_bookshelves - Bookshelf.create(name: 'Read', user_id: self.id) - Bookshelf.create(name: 'Will Read', user_id: self.id) + Bookshelf.create(name: 'Read', user_id: id) + Bookshelf.create(name: 'Will Read', user_id: id) end def invalidate_token