* fixing associations

This commit is contained in:
Seth Call 2014-02-06 21:41:35 +00:00
parent 28c2298931
commit 1c6c1da027
8 changed files with 20 additions and 5 deletions

View File

@ -13,7 +13,7 @@ module JamRuby
belongs_to :genre, :class_name => "JamRuby::Genre"
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", :as => :shareable
has_one :share_token, :class_name => "JamRuby::ShareToken", :inverse_of => :shareable, :foreign_key => 'shareable_id'
before_create :generate_share_token

View File

@ -22,7 +22,7 @@ module JamRuby
has_many :music_session_user_histories, :class_name => "JamRuby::MusicSessionUserHistory", :foreign_key => "music_session_id"
has_many :comments, :class_name => "JamRuby::MusicSessionComment", :foreign_key => "music_session_id"
has_many :likes, :class_name => "JamRuby::MusicSessionLiker", :foreign_key => "music_session_id"
has_one :share_token, :class_name => "JamRuby::ShareToken", :as => :shareable
has_one :share_token, :class_name => "JamRuby::ShareToken", :inverse_of => :shareable, :foreign_key => 'shareable_id'
before_create :generate_share_token
@ -160,7 +160,6 @@ module JamRuby
private
def generate_share_token
self.id = music_session.id # unify music_session.id and music_session_history.id
token = loop do

View File

@ -13,7 +13,9 @@ describe ShareToken do
it "can reference a music session" do
music_session.touch # should create a MSH, and a token, too
ShareToken.count.should == 1
music_session.music_session_history.share_token.should_not be_nil
token = ShareToken.find_by_shareable_id!(music_session.id)
token.should == music_session.music_session_history.share_token
token.shareable_id.should == music_session.id
token.shareable_type.should == 'session'
end
@ -21,7 +23,9 @@ describe ShareToken do
it "can reference a claimed recording" do
claimed_recording.touch # should create a share token
ShareToken.count.should == 2 # one for MSH, one for recording
claimed_recording.share_token.should_not be_nil
token = ShareToken.find_by_shareable_id!(claimed_recording.id)
claimed_recording.share_token.should == token
token.shareable_type.should == 'recording'
end

View File

@ -0,0 +1,4 @@
module ShareTokenHelper
end

View File

@ -6,6 +6,10 @@ object @claimed_recording
attributes :id, :name, :description, :is_public, :is_downloadable, :genre_id
node :share_url do|claimed_recording|
share_token_url(claimed_recording.share_token.token)
end
child(:recording => :recording) {
attributes :id, :created_at, :duration, :comment_count, :like_count, :play_count

View File

@ -12,6 +12,10 @@ if :is_recording?
end
end
node :share_url do|music_session|
share_token_url(music_session.music_session_history.share_token.token)
end
child(:connections => :participants) {
collection @music_sessions, :object_root => false
attributes :ip_address, :client_id

View File

@ -65,7 +65,7 @@ SampleApp::Application.routes.draw do
match '/listen_in', to: 'spikes#listen_in'
# share tokens
match '/s/:id', to: 'share_tokens#shareable_resolver'
match '/s/:id', to: 'share_tokens#shareable_resolver', :as => 'share_token'
# password reset
match '/request_reset_password' => 'users#request_reset_password', :via => :get

View File

@ -1,6 +1,6 @@
require 'spec_helper'
describe ApiSharedTokenController do
describe SharedTokenController do
render_views
let(:user) { FactoryGirl.create(:user) }