* VRFS-1135 only one recording comes back; not per claimed recording

This commit is contained in:
Seth Call 2014-02-16 13:10:00 +00:00
parent 06a9dde2c2
commit f7d0ef2b05
9 changed files with 118 additions and 57 deletions

View File

@ -107,4 +107,5 @@ recordings_all_discarded.sql
recordings_via_admin_web.sql
relax_band_model_varchar.sql
add_piano.sql
feed.sql
feed.sql
feed_use_recording.sql

View File

@ -0,0 +1,4 @@
DELETE from feeds;
ALTER TABLE feeds DROP COLUMN claimed_recording_id;
ALTER TABLE feeds ADD COLUMN recording_id VARCHAR(64) UNIQUE REFERENCES recordings(id) ON DELETE CASCADE;

View File

@ -9,7 +9,6 @@ module JamRuby
has_many :recorded_tracks, :through => :recording, :class_name => "JamRuby::RecordedTrack"
has_many :playing_sessions, :class_name => "JamRuby::MusicSession"
has_one :share_token, :class_name => "JamRuby::ShareToken", :inverse_of => :shareable, :foreign_key => 'shareable_id'
has_one :feed, :class_name => "JamRuby::Feed", :inverse_of => :claimed_recording, :foreign_key => 'claimed_recording_id', :dependent => :destroy
validates :name, no_profanity: true, length: {minimum: 3, maximum: 64}, presence: true
@ -21,17 +20,11 @@ module JamRuby
validates_uniqueness_of :user_id, :scope => :recording_id
validate :user_belongs_to_recording
before_create :add_to_feed
before_create :generate_share_token
SHARE_TOKEN_LENGTH = 8
def add_to_feed
feed = Feed.new
feed.claimed_recording = self
end
def user_belongs_to_recording
if user && recording && !recording.users.exists?(user)
errors.add(:user, ValidationMessages::NOT_PART_OF_RECORDING)

View File

@ -2,11 +2,11 @@
module JamRuby
class Feed < ActiveRecord::Base
belongs_to :claimed_recording, class_name: "JamRuby::ClaimedRecording", inverse_of: :feed, foreign_key: 'claimed_recording_id'
belongs_to :recording, class_name: "JamRuby::Recording", inverse_of: :feed, foreign_key: 'recording_id'
belongs_to :music_session_history, class_name: "JamRuby::MusicSessionHistory", inverse_of: :feed, foreign_key: 'music_session_id'
def self.index(params = {})
Feed.includes(:claimed_recording).includes(:music_session_history).order('created_at DESC').limit(20)
Feed.includes(:recording).includes(:music_session_history).order('created_at DESC').limit(20)
end
end
end

View File

@ -12,6 +12,7 @@ module JamRuby
has_many :comments, :class_name => "JamRuby::RecordingComment", :foreign_key => "recording_id"
has_many :likes, :class_name => "JamRuby::RecordingLiker", :foreign_key => "recording_id"
has_many :plays, :class_name => "JamRuby::RecordingPlay", :foreign_key => "recording_id"
has_one :feed, :class_name => "JamRuby::Feed", :inverse_of => :recording, :foreign_key => 'recording_id', :dependent => :destroy
belongs_to :owner, :class_name => "JamRuby::User", :inverse_of => :owned_recordings, :foreign_key => 'owner_id'
belongs_to :band, :class_name => "JamRuby::Band", :inverse_of => :recordings
@ -26,6 +27,13 @@ module JamRuby
validate :only_one_mix
before_save :sanitize_active_admin
before_create :add_to_feed
def add_to_feed
feed = Feed.new
feed.recording = self
end
def sanitize_active_admin
self.owner_id = nil if self.owner_id == ''

View File

@ -154,7 +154,7 @@ FactoryGirl.define do
association :user, factory: :user
before(:create) { |claimed_recording|
claimed_recording.recording = FactoryGirl.create(:recording_with_track, owner: claimed_recording.user)
claimed_recording.recording = FactoryGirl.create(:recording_with_track, owner: claimed_recording.user) unless claimed_recording.recording
}
end

View File

@ -8,10 +8,24 @@ describe Feed do
it "one claimed recording" do
claimed_recording = FactoryGirl.create(:claimed_recording)
MusicSessionHistory.delete_all # the factory makes a music_session while making the recording/claimed_recording
feeds = Feed.index()
feeds.length.should == 2 # the factory makes a music_session while making the recording/claimed_recording
feeds[0].music_session_history == claimed_recording.recording.music_session.music_session_history
feeds[1].claimed_recording == claimed_recording
feeds.length.should == 1
feeds[0].recording == claimed_recording.recording
end
it "two claimed recordings for the same recording should only return one" do
recording = FactoryGirl.create(:claimed_recording).recording
second_track = FactoryGirl.create(:recorded_track, recording: recording)
recording.recorded_tracks << second_track
FactoryGirl.create(:claimed_recording, recording: recording, user: second_track.user)
MusicSessionHistory.delete_all
# verify the mess above only made one recording
Recording.count.should == 1
feeds = Feed.index()
feeds.length.should == 1
end
it "one music session" do

View File

@ -20,61 +20,63 @@ glue :music_session_history do
end
end
glue :claimed_recording do
glue :recording do
node :type do |i|
'claimed_recording'
'recording'
end
attributes :id, :name, :description, :is_public, :is_downloadable, :genre_id
attributes :id, :band, :created_at, :duration, :comment_count, :like_count, :play_count
node :share_url do |claimed_recording|
unless claimed_recording.share_token.nil?
share_token_url(claimed_recording.share_token.token)
end
end
child(:band => :band) {
attributes :id, :name, :location, :photo_url
}
child(:recording => :recording) {
attributes :id, :created_at, :duration, :comment_count, :like_count, :play_count
child(:owner => :owner) {
attributes :id, :name, :location, :photo_url
}
child(:band => :band) {
attributes :id, :name, :location, :photo_url
}
child(:mixes => :mixes) {
attributes :id, :is_completed
child(:owner => :owner) {
attributes :id, :name, :location, :photo_url
}
node :mp3_url do |mix|
mix[:mp3_url]
end
child(:mixes => :mixes) {
attributes :id, :is_completed
node :ogg_url do |mix|
mix[:ogg_url]
end
}
node :mp3_url do |mix|
mix[:mp3_url]
end
child(:recorded_tracks => :recorded_tracks) {
attributes :id, :fully_uploaded, :client_track_id, :client_id, :instrument_id
node :ogg_url do |mix|
mix[:ogg_url]
end
}
child(:recorded_tracks => :recorded_tracks) {
attributes :id, :fully_uploaded, :client_track_id, :client_id, :instrument_id
node :url do |recorded_track|
node :url do |recorded_track|
recorded_track[:url]
end
end
child(:user => :user) {
attributes :id, :first_name, :last_name, :name, :city, :state, :country, :location, :photo_url
}
}
child(:comments => :comments) {
attributes :comment, :created_at
child(:user => :creator) {
attributes :id, :first_name, :last_name, :photo_url
}
child(:user => :user) {
attributes :id, :first_name, :last_name, :city, :state, :country, :location, :photo_url
}
}
child(:comments => :comments) {
attributes :comment, :created_at
child(:user => :creator) {
attributes :id, :first_name, :last_name, :photo_url
}
}
child(:claimed_recordings => :claimed_recordings) {
attributes :id, :name, :description, :is_public, :is_downloadable, :genre_id
node :share_url do |claimed_recording|
unless claimed_recording.share_token.nil?
share_token_url(claimed_recording.share_token.token)
end
end
}
end

View File

@ -2,6 +2,26 @@ object @recording
attributes :id, :band, :created_at, :duration, :comment_count, :like_count, :play_count
child(:band => :band) {
attributes :id, :name, :location, :photo_url
}
child(:owner => :owner) {
attributes :id, :name, :location, :photo_url
}
child(:mixes => :mixes) {
attributes :id, :is_completed
node :mp3_url do |mix|
mix[:mp3_url]
end
node :ogg_url do |mix|
mix[:ogg_url]
end
}
child(:recorded_tracks => :recorded_tracks) {
attributes :id, :fully_uploaded, :client_track_id, :client_id, :instrument_id
@ -10,6 +30,25 @@ child(:recorded_tracks => :recorded_tracks) {
end
child(:user => :user) {
attributes :id, :first_name, :last_name, :city, :state, :country, :photo_url
attributes :id, :first_name, :last_name, :city, :state, :country, :location, :photo_url
}
}
child(:comments => :comments) {
attributes :comment, :created_at
child(:user => :creator) {
attributes :id, :first_name, :last_name, :photo_url
}
}
child(:claimed_recordings => :claimed_recordings) {
attributes :id, :name, :description, :is_public, :is_downloadable, :genre_id
node :share_url do |claimed_recording|
unless claimed_recording.share_token.nil?
share_token_url(claimed_recording.share_token.token)
end
end
}