Skip to content

Commit

Permalink
Merge 1bc3c9c into afad4bb
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed May 13, 2016
2 parents afad4bb + 1bc3c9c commit 7f780f7
Show file tree
Hide file tree
Showing 27 changed files with 65 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Account < BaseModel
acts_as_paranoid

belongs_to :opener, -> { with_deleted }, class_name: 'User', foreign_key: 'opener_id'
belongs_to :opener, -> { with_deleted }, class_name: 'User', foreign_key: 'opener_id', touch: true

has_one :address, as: :addressable
has_one :image, -> { where(parent_id: nil) }, class_name: 'AccountImage'
Expand Down
2 changes: 1 addition & 1 deletion app/models/account_image.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: utf-8

class AccountImage < Image
belongs_to :account
belongs_to :account, touch: true
end
2 changes: 1 addition & 1 deletion app/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Address < BaseModel

belongs_to :addressable, polymorphic: true
belongs_to :addressable, polymorphic: true, touch: true

def account
if addressable.is_a?(Account)
Expand Down
4 changes: 2 additions & 2 deletions app/models/audio_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class AudioFile < BaseModel
TRANSFORM_FAILED = 'creating mp3s failed'
TRANSFORMED = 'mp3s created'

belongs_to :account
belongs_to :account, touch: true

belongs_to :audio_version
belongs_to :audio_version, touch: true
has_one :story, through: :audio_version

acts_as_list scope: :audio_version
Expand Down
2 changes: 1 addition & 1 deletion app/models/audio_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class AudioVersion < BaseModel

belongs_to :story, -> { with_deleted }, class_name: 'Story', foreign_key: 'piece_id'
belongs_to :story, -> { with_deleted }, class_name: 'Story', foreign_key: 'piece_id', touch: true
has_many :audio_files, -> { order :position }, dependent: :destroy

acts_as_paranoid
Expand Down
2 changes: 1 addition & 1 deletion app/models/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Format < BaseModel

FORMAT_NAMES = ['Actuality','Aircheck','Archival','Commentary','Daily Segment','Debut (not aired nationally)','Diary','Documentary','Enterprise/Investigative','Essay','Fiction','First-Person Essay','Fundraising for Air','Fundraising for Air: Music','Fundraising for Air: News','Fundraising Sample','Fundraising Sample: Music','Fundraising Sample: News','Hard Feature','Interstitial','Interview','Limited Series','News Analysis','News Reporting','Soft Feature','Special','Weekly Program','Youth-Produced']

belongs_to :story, class_name: 'Story', foreign_key: 'piece_id'
belongs_to :story, class_name: 'Story', foreign_key: 'piece_id', touch: true

validates_inclusion_of :name, in: FORMAT_NAMES
validates_uniqueness_of :name, scope: :story
Expand Down
2 changes: 1 addition & 1 deletion app/models/license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class License < BaseModel
WEBSITE_USAGE = ['as a free MP3 download and stream', 'as a stream only', 'only with permission']
ALLOW_EDIT = ['only with permission', 'without further permission', 'never']

belongs_to :story, -> { with_deleted }, class_name: 'Story', foreign_key: 'piece_id'
belongs_to :story, -> { with_deleted }, class_name: 'Story', foreign_key: 'piece_id', touch: true

acts_as_paranoid

Expand Down
4 changes: 2 additions & 2 deletions app/models/membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class Membership < BaseModel

belongs_to :user, -> { with_deleted }
belongs_to :account, -> { with_deleted }
belongs_to :user, -> { with_deleted }, touch: true
belongs_to :account, -> { with_deleted }, touch: true

scope :approved, -> { where(approved: true) }
end
2 changes: 1 addition & 1 deletion app/models/musical_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class MusicalWork < BaseModel

belongs_to :story, -> { with_deleted }, class_name: 'Story', foreign_key: 'piece_id'
belongs_to :story, -> { with_deleted }, class_name: 'Story', foreign_key: 'piece_id', touch: true

acts_as_list scope: :piece_id

Expand Down
4 changes: 2 additions & 2 deletions app/models/pick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Pick < BaseModel

self.table_name = 'playlistings'

belongs_to :story, foreign_key: 'playlistable_id'
belongs_to :playlist_section
belongs_to :story, foreign_key: 'playlistable_id', touch: true
belongs_to :playlist_section, touch: true

has_one :playlist, through: :playlist_section
has_one :account, through: :playlist_section
Expand Down
2 changes: 1 addition & 1 deletion app/models/playlist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Playlist < BaseModel

acts_as_paranoid

belongs_to :account
belongs_to :account, touch: true

has_many :playlist_sections, foreign_key: 'playlist_id'
has_many :picks, through: :playlist_sections
Expand Down
2 changes: 1 addition & 1 deletion app/models/playlist_section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class PlaylistSection < BaseModel

self.table_name = 'playlist_sections'

belongs_to :playlist
belongs_to :playlist, touch: true
has_many :picks
has_many :stories, through: :picks
has_one :account, through: :playlist
Expand Down
4 changes: 2 additions & 2 deletions app/models/producer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class Producer < BaseModel

belongs_to :story, -> { with_deleted }, foreign_key: 'piece_id'
belongs_to :user, -> { with_deleted }
belongs_to :story, -> { with_deleted }, foreign_key: 'piece_id', touch: true
belongs_to :user, -> { with_deleted }, touch: true

acts_as_paranoid

Expand Down
8 changes: 4 additions & 4 deletions app/models/purchase.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# encoding: utf-8

class Purchase < BaseModel
belongs_to :purchased, class_name: 'Story'
belongs_to :purchaser, -> { with_deleted }, class_name: 'User'
belongs_to :purchaser_account, -> { with_deleted }, class_name: 'Account'
belongs_to :seller_account, -> { with_deleted }, class_name: 'Account'
belongs_to :purchased, class_name: 'Story', touch: true
belongs_to :purchaser, -> { with_deleted }, class_name: 'User', touch: true
belongs_to :purchaser_account, -> { with_deleted }, class_name: 'Account', touch: true
belongs_to :seller_account, -> { with_deleted }, class_name: 'Account', touch: true
end
2 changes: 1 addition & 1 deletion app/models/schedule.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: utf-8

class Schedule < BaseModel
belongs_to :series
belongs_to :series, touch: true
end
5 changes: 3 additions & 2 deletions app/models/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class Series < BaseModel

acts_as_paranoid

belongs_to :account, -> { with_deleted }
belongs_to :creator, -> { with_deleted }, class_name: 'User', foreign_key: 'creator_id'
belongs_to :account, -> { with_deleted }, touch: true
belongs_to :creator, -> { with_deleted }, class_name: 'User', foreign_key: 'creator_id',
touch: true

has_many :stories, -> { where('published_at is not null and network_only_at is null').order('episode_number DESC, position DESC, published_at DESC') }

Expand Down
2 changes: 1 addition & 1 deletion app/models/series_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class SeriesImage < Image

belongs_to :series
belongs_to :series, touch: true

end
7 changes: 4 additions & 3 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def self.paranoia_scope
)
end

belongs_to :account, -> { with_deleted }
belongs_to :creator, -> { with_deleted }, class_name: 'User', foreign_key: 'creator_id'
belongs_to :series
belongs_to :account, -> { with_deleted }, touch: true
belongs_to :creator, -> { with_deleted }, class_name: 'User', foreign_key: 'creator_id',
touch: true
belongs_to :series, touch: true

has_many :images, -> { where(parent_id: nil).order(:position) }, class_name: 'StoryImage', foreign_key: :piece_id
has_many :audio_versions, -> { where(promos: false).includes(:audio_files) }, foreign_key: :piece_id
Expand Down
2 changes: 1 addition & 1 deletion app/models/story_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class StoryImage < Image

self.table_name = 'piece_images'

belongs_to :story, -> { with_deleted }, class_name: 'Story', foreign_key: 'piece_id'
belongs_to :story, -> { with_deleted }, class_name: 'Story', foreign_key: 'piece_id', touch: true

acts_as_list scope: :piece_id

Expand Down
4 changes: 2 additions & 2 deletions app/models/tagging.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# encoding: utf-8

class Tagging < BaseModel
belongs_to :user_tag, foreign_key: :tag_id
belongs_to :taggable, polymorphic: true
belongs_to :user_tag, foreign_key: :tag_id, touch: true
belongs_to :taggable, polymorphic: true, touch: true

validates_uniqueness_of :tag_id, scope: [:taggable_id, :taggable_type]
end
2 changes: 1 addition & 1 deletion app/models/tone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Tone < BaseModel

TONE_NAMES = ['Amusing','Authoritative','Contemplative','Dark','Delicate','Disturbing','Earnest','Edgy','Elaborate','Emotional','Engaging','Esoteric','Experimental','Fresh Air-ish','Humorous','Informational','Inspiring','Intimate','Intriguing','Light','Lighthearted','Melancholic','NPR NewsMagazine-y','Offbeat','Opinionated','Personal','Polished','Political','Provocative','Quirky','Raw','Real','Rough','Sad','Sentimental','Simple','Sound-Rich','Surprising','Suspenseful','Sweet','This American Life-esque','Thorough','Thoughtful','Unconventional','Unusual','Upbeat']

belongs_to :story, class_name: 'Story', foreign_key: 'piece_id'
belongs_to :story, class_name: 'Story', foreign_key: 'piece_id', touch: true

validates_inclusion_of :name, :in => TONE_NAMES
validates_uniqueness_of :name, scope: :story
Expand Down
2 changes: 1 addition & 1 deletion app/models/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Topic < BaseModel
'Instructional','International','Labor','Latino','Literature','Media','Music','Native','News','Politics',
'Public Affairs','Religious','Science','Senior','Sports','Technology','Travel','War','Women','Youth']

belongs_to :story, class_name: 'Story', foreign_key: 'piece_id'
belongs_to :story, class_name: 'Story', foreign_key: 'piece_id', touch: true
validates_inclusion_of :name, in: TOPIC_NAMES
validates_uniqueness_of :name, scope: :story

Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class User < BaseModel
acts_as_paranoid

# DON'T touch the account, as you'll create an infinite loop
belongs_to :default_account, -> { with_deleted }, class_name: 'Account', foreign_key: 'account_id'

has_one :address, as: :addressable
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class UserImage < Image

belongs_to :user
belongs_to :user, touch: true

end
2 changes: 1 addition & 1 deletion app/models/website.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8

class Website < BaseModel
belongs_to :browsable, polymorphic: true
belongs_to :browsable, polymorphic: true, touch: true

SEARCH = /^(?!http)./
REPLACE = 'http://\\0'
Expand Down
18 changes: 18 additions & 0 deletions test/models/audio_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,22 @@
audio_file_uploaded.url_expires_at(expiration: 3600).must_equal (n + 3600)
end
end

it 'updates story and version timestamps' do
story = create(:story)
version = create(:audio_version, story: story)
audio_file.update_attribute(:audio_version_id, version.id)

stamp = 2.minutes.ago
story.update_attribute(:updated_at, stamp)
version.update_attribute(:updated_at, stamp)

audio_file.filename = 'something'
audio_file.save!
story.reload
version.reload

story.updated_at.must_be :>, stamp
version.updated_at.must_be :>, stamp
end
end
9 changes: 9 additions & 0 deletions test/models/tagging_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@

tagging2.must_be :valid?
end

it 'updates the taggable\'s timestamp' do
taggable = create(:story)
taggable.update_attribute(:updated_at, 3.minutes.ago)
stamp = taggable.updated_at
create(:tagging, taggable: taggable)
taggable.reload
stamp.must_be :<, taggable.updated_at
end
end

0 comments on commit 7f780f7

Please sign in to comment.