1
|
require "date"
|
1
|
2
|
require File.expand_path('../../spec_helper', __FILE__)
|
1
|
3
|
|
|
4
|
describe "Track" do
|
1
|
5
|
|
|
6
|
before do
|
1
|
7
|
@client = stub(Sevendigital::Client)
|
7
|
8
|
@track_manager = mock(Sevendigital::TrackManager)
|
7
|
9
|
@client.stub!(:track).and_return @track_manager
|
7
|
10
|
|
|
11
|
@track = Sevendigital::Track.new(@client)
|
7
|
12
|
@track.id = 1234
|
7
|
13
|
@track.release = Sevendigital::Release.new(@client)
|
7
|
14
|
@track.release.id = 5678
|
7
|
15
|
end
|
|
16
|
|
|
17
|
it "get_details should get track's basic details from track manager " do
|
1
|
18
|
expected_options = {:page => 2}
|
1
|
19
|
fresh_track = fake_track_with_details
|
1
|
20
|
|
|
21
|
@track_manager.should_receive(:get_details_from_release) { |track_id, release_id, options|
|
1
|
22
|
track_id.should == @track.id
|
1
|
23
|
release_id.should == @track.release.id
|
1
|
24
|
(options.keys & expected_options.keys).should == expected_options.keys
|
1
|
25
|
fresh_track
|
1
|
26
|
}
|
|
27
|
@track.get_details(expected_options)
|
1
|
28
|
|
|
29
|
@track.track_number.should == fresh_track.track_number
|
1
|
30
|
@track.duration.should == fresh_track.duration
|
1
|
31
|
@track.explicit_content.should == fresh_track.explicit_content
|
1
|
32
|
@track.isrc.should == fresh_track.isrc
|
1
|
33
|
@track.release.id.should == fresh_track.release.id
|
1
|
34
|
@track.url.should == fresh_track.url
|
1
|
35
|
|
|
36
|
end
|
|
37
|
|
|
38
|
it "preview_url should get preview URL from manager" do
|
1
|
39
|
expected_options = {:country => "mx"}
|
1
|
40
|
fake_preview_url = "http://preview.com/trackid/123456"
|
1
|
41
|
|
|
42
|
@track_manager.should_receive(:build_preview_url) { |track_id, options|
|
1
|
43
|
track_id.should == @track.id
|
1
|
44
|
(options.keys & expected_options.keys).should == expected_options.keys
|
1
|
45
|
fake_preview_url
|
1
|
46
|
}
|
|
47
|
|
|
48
|
@track.preview_url(expected_options).should == fake_preview_url
|
1
|
49
|
|
|
50
|
end
|
|
51
|
|
|
52
|
it "should have a short title without any version in brackets" do
|
1
|
53
|
|
|
54
|
@track.title = "Girl With One Eye (Bayou Percussion Version)"
|
1
|
55
|
@track.short_title.should == "Girl With One Eye"
|
1
|
56
|
|
|
57
|
@track.title = "The Thing I Like Best About Him Is His Girlfriend (Gr's Man-Made Island Edition)"
|
1
|
58
|
@track.short_title.should == "The Thing I Like Best About Him Is His Girlfriend"
|
1
|
59
|
|
|
60
|
@track.title = "Your Head to Your Toes (Live at the BBC)"
|
1
|
61
|
@track.short_title.should == "Your Head to Your Toes"
|
1
|
62
|
|
|
63
|
@track.title = "Welcome To The World of The Plastic Beach (Feat. Snoop Dogg and Hypnotic Brass Ensemble)"
|
1
|
64
|
@track.short_title.should == "Welcome To The World of The Plastic Beach"
|
1
|
65
|
|
|
66
|
@track.title = "(lp version)"
|
1
|
67
|
@track.short_title.should == "(lp version)"
|
1
|
68
|
|
|
69
|
@track.title = "What's the Story (Morning Glory)"
|
1
|
70
|
@track.short_title.should == "What's the Story (Morning Glory)"
|
1
|
71
|
|
|
72
|
@track.title = "track 1 (something else)"
|
1
|
73
|
@track.short_title.should == "track 1 (something else)"
|
1
|
74
|
|
|
75
|
@track.title = "track 1 (dj remix)"
|
1
|
76
|
@track.short_title.should == "track 1"
|
1
|
77
|
|
|
78
|
@track.title = "track 1 ( dj mix )"
|
1
|
79
|
@track.short_title.should == "track 1"
|
1
|
80
|
end
|
|
81
|
|
|
82
|
describe "alternate_version?" do
|
1
|
83
|
|
|
84
|
before do
|
1
|
85
|
@artist1 = Sevendigital::Artist.new(@client)
|
4
|
86
|
@artist2 = Sevendigital::Artist.new(@client)
|
4
|
87
|
@track1 = Sevendigital::Track.new(@client)
|
4
|
88
|
@track1.artist = @artist1
|
4
|
89
|
@track2 = Sevendigital::Track.new(@client)
|
4
|
90
|
@track2.artist = @artist2
|
4
|
91
|
|
|
92
|
@artist1.name = "artist 1"
|
4
|
93
|
@track1.title = "track 1"
|
4
|
94
|
|
|
95
|
end
|
|
96
|
|
|
97
|
it "should be considered alternate version if artist names and titles match" do
|
1
|
98
|
@artist2.name = "Artist 1"
|
1
|
99
|
@track2.title = "Track 1"
|
1
|
100
|
|
|
101
|
@track1.alternate_version_of?(@track2).should == true
|
1
|
102
|
end
|
|
103
|
|
|
104
|
it "should be considered alternate version if artist names and short titles match" do
|
1
|
105
|
@track1.title = "track 1 (uk version)"
|
1
|
106
|
|
|
107
|
@artist2.name = "Artist 1"
|
1
|
108
|
@track2.title = "TRACK 1 (us remix)"
|
1
|
109
|
|
|
110
|
@track1.alternate_version_of?(@track2).should == true
|
1
|
111
|
end
|
|
112
|
|
|
113
|
it "should not be considered alternate version if artist names don't match" do
|
1
|
114
|
@artist2.name = "artist 2"
|
1
|
115
|
@track2.title = "track 1"
|
1
|
116
|
|
|
117
|
@track1.alternate_version_of?(@track2).should == false
|
1
|
118
|
end
|
|
119
|
|
|
120
|
it "should not be considered alternate version if short titles don't match" do
|
1
|
121
|
@artist2.name = "artist 1"
|
1
|
122
|
@track2.title = "track 2"
|
1
|
123
|
|
|
124
|
@track1.alternate_version_of?(@track2).should == false
|
1
|
125
|
end
|
|
126
|
|
|
127
|
|
|
128
|
end
|
|
129
|
|
|
130
|
def fake_track_with_details
|
1
|
131
|
track = Sevendigital::Track.new(@client)
|
1
|
132
|
track.title = "Song 1"
|
1
|
133
|
track.version = "Version 2"
|
1
|
134
|
track.artist = Sevendigital::Artist.new(@client)
|
1
|
135
|
track.track_number = 7
|
1
|
136
|
track.duration = 77
|
1
|
137
|
track.explicit_content = true
|
1
|
138
|
track.isrc = "7D"
|
1
|
139
|
track.release = Sevendigital::Release.new(@client)
|
1
|
140
|
track.release.id = 5678
|
1
|
141
|
track.url = "http://aaa.bbb.ccc/"
|
1
|
142
|
track
|
1
|
143
|
end
|
|
144
|
end
|
|