Skip to content

Commit 9a45075

Browse files
committed
Add Artist test
1 parent 23577fe commit 9a45075

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

test/models/artist_test.rb

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,37 @@
22

33
class ArtistTest < ActiveSupport::TestCase
44

5-
setup do
6-
Artist.create_index!(force: true)
7-
end
8-
95
test "Artist #new" do
10-
artist = Artist.new(name: 'Common', profile: 'etc etc', members: ['dave', 'diana'])
6+
artist = Artist.new(name: 'Common', profile: 'etc etc', members: ['Jack', 'Larry'])
117
assert artist.name == 'Common'
128
assert artist.profile == 'etc etc'
13-
assert artist.members == ['dave', 'diana']
9+
assert artist.members == ['Jack', 'Larry']
1410
end
1511

16-
test "Artist #mappings" do
17-
expected_mappings = {:_doc=>
18-
{:properties=>
19-
{:created_at=>{:type=>"date"},
20-
:updated_at=>{:type=>"date"},
21-
:name=>{:type=>"text", :fields=>{:name=>{:type=>"text", :analyzer=>"snowball"}, :raw=>{:type=>"keyword"}}},
22-
:profile=>{:type=>"text"},
23-
:members=>{:type=>"text", :fields=>{:name=>{:type=>"text", :analyzer=>"snowball"}, :raw=>{:type=>"keyword"}}},
24-
:artist_suggest=>{:type=>"object", :properties=>{:name=>{:type=>"completion"}, :members=>{:type=>"completion"}}}}}}
25-
26-
assert expected_mappings[:_doc][:properties].keys.to_set ==
27-
Artist.mappings.to_hash[:_doc][:properties].keys.to_set
28-
assert expected_mappings[:_doc][:properties].all? do |key|
29-
Artist.mappings.to_hash[:_doc][:properties][key] == expected_mappings[:_doc][:properties][key]
30-
end
12+
test "Artist #attributes" do
13+
artist = Artist.new(name: 'Common', profile: 'etc etc', members: ['Jack', 'Larry'])
14+
assert artist.attributes[:name] == 'Common'
15+
assert artist.attributes[:profile] == 'etc etc'
16+
assert artist.attributes[:members] == ['Jack', 'Larry']
3117
end
3218

33-
test "Artist #to_hash" do
34-
artist = Artist.new(name: 'Common', profile: 'etc etc', members: ['dave', 'diana'])
35-
hash_representation = artist.to_hash
36-
assert hash_representation[:artist_suggest][:members] == { input: ['dave', 'diana'] }
37-
assert hash_representation[:artist_suggest][:name] == { input: [ 'Common' ]}
19+
test "Artist mutability" do
20+
artist = Artist.new(name: 'Common', profile: 'etc etc')
21+
artist.name = 'FKA Twigs'
22+
assert artist.name == 'FKA Twigs'
23+
assert artist.profile == 'etc etc'
3824
end
3925

40-
test "Artist#all" do
41-
Artist.create({ name: 'Common' }, refresh: true)
42-
Artist.create({ name: 'Common' }, refresh: true)
43-
assert Artist.all.collect(&:name) == ['Common', 'Common']
26+
test "Artist #to_hash" do
27+
artist = Artist.new(name: 'Common', profile: 'etc etc', members: ['Jack', 'Larry'])
28+
hash = artist.to_hash
29+
assert hash[:name] == 'Common'
30+
assert hash[:profile] == 'etc etc'
31+
assert hash[:members] == ['Jack', 'Larry']
4432
end
4533

4634
test "Artist validation" do
47-
artist = Artist.new(profile: 'etc etc', members: ['dave', 'diana'])
48-
assert_not artist.save
49-
end
50-
51-
test "Artist#albums" do
52-
artist = Artist.create(name: 'Common', profile: 'etc etc', members: ['dave', 'diana'])
53-
Album.create({ title: 'Like Water for Chocolate', artist: artist }, refresh: true)
54-
assert artist.albums.first.title == 'Like Water for Chocolate'
35+
artist = Artist.new(profile: 'etc etc', members: ['Jack', 'Larry'])
36+
assert_not artist.valid?
5537
end
56-
end
38+
end

0 commit comments

Comments
 (0)