diff --git a/.gitignore b/.gitignore index e1f9578..b5f8a49 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,6 @@ # Ignore master key for decrypting credentials and more. /config/master.key -/db/mysql_data/* \ No newline at end of file +/db/mysql_data/* +.coverage +.coverage.* diff --git a/app/helpers/tracks_helper.rb b/app/helpers/tracks_helper.rb index c0fc492..a3ec03a 100644 --- a/app/helpers/tracks_helper.rb +++ b/app/helpers/tracks_helper.rb @@ -1,36 +1,4 @@ # frozen_string_literal: true module TracksHelper - def spotify_info(track) - RSpotify::Track.find(track.spotify_id) - end - - def album_id(track) - RSpotify::Track.find(track.spotify_id).album.id - end - - def album_name(track) - RSpotify::Track.find(track.spotify_id).album.name - end - - def album_image(track) - images = RSpotify::Track.find(track.spotify_id).album.images - images.blank? ? 'no_image.png' : images[0]['url'] - end - - def album_type(track) - RSpotify::Track.find(track.spotify_id).album.album_type - end - - def album_release_date(track) - RSpotify::Track.find(track.spotify_id).album.release_date - end - - def artist_id(track) - RSpotify::Track.find(track.spotify_id).artists[0].id - end - - def artist_name(track) - RSpotify::Track.find(track.spotify_id).artists[0].name - end end diff --git a/coverage/.resultset.json b/coverage/.resultset.json new file mode 100644 index 0000000..3eb01e3 --- /dev/null +++ b/coverage/.resultset.json @@ -0,0 +1,982 @@ +{ + "RSpec": { + "coverage": { + "/myapp/spec/controllers/reviews_controller_spec.rb": [ + null, + null, + 1, + null, + 1, + 9, + 7, + 2, + 5, + null, + 1, + 1, + 3, + null, + 1, + 2, + null, + null, + null, + 1, + 2, + null, + null, + 1, + 1, + 1, + null, + null, + null, + 1, + 3, + null, + 1, + 2, + null, + null, + null, + 1, + 2, + null, + null, + 1, + 1, + 1, + null, + null, + null, + null, + 1, + 1, + 1, + 2, + 2, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + null, + null + ], + "/myapp/spec/rails_helper.rb": [ + null, + null, + null, + 1, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + 0, + 0, + null, + 1, + 2, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + 1, + null, + null, + null + ], + "/myapp/config/environment.rb": [ + null, + null, + null, + 1, + null, + null, + 1 + ], + "/myapp/config/application.rb": [ + null, + null, + 1, + null, + 1, + null, + null, + null, + 1, + null, + 1, + 1, + null, + 1, + null, + null, + null, + null, + null, + 1, + 1, + null, + null + ], + "/myapp/config/boot.rb": [ + null, + null, + 1, + null, + 1, + 1 + ], + "/myapp/config/environments/development.rb": [ + null, + null, + 1, + null, + null, + null, + null, + null, + 1, + null, + null, + 1, + null, + null, + 1, + null, + null, + null, + 1, + 0, + null, + 0, + 0, + null, + null, + null, + 1, + null, + 1, + null, + null, + null, + 1, + null, + null, + 1, + null, + 1, + null, + null, + 1, + null, + null, + 1, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + 1, + 1, + null + ], + "/myapp/config/initializers/application_controller_renderer.rb": [ + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/myapp/config/initializers/assets.rb": [ + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null + ], + "/myapp/config/initializers/backtrace_silencers.rb": [ + null, + null, + null, + null, + null, + null, + null, + null + ], + "/myapp/config/initializers/content_security_policy.rb": [ + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/myapp/config/initializers/cookies_serializer.rb": [ + null, + null, + null, + null, + null, + null, + 1 + ], + "/myapp/config/initializers/devise.rb": [ + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/myapp/config/initializers/filter_parameter_logging.rb": [ + null, + null, + null, + null, + null, + 1 + ], + "/myapp/config/initializers/inflections.rb": [ + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/myapp/config/initializers/mime_types.rb": [ + null, + null, + null, + null, + null + ], + "/myapp/config/initializers/wrap_parameters.rb": [ + null, + null, + null, + null, + null, + null, + null, + null, + 1, + 2, + null, + null, + null, + null, + null, + null + ], + "/myapp/spec/factories/review.rb": [ + null, + null, + 1, + 1, + 1, + 5, + 5, + 5, + 1, + 1, + null, + null + ], + "/myapp/spec/factories/track.rb": [ + null, + null, + 1, + 1, + 5, + 13, + 13, + 13, + 13, + 13, + null, + null + ], + "/myapp/spec/factories/user.rb": [ + null, + null, + 1, + 1, + 1, + 7, + 7, + 7, + 7, + 7, + null, + null, + 1, + 1, + 2, + 2, + 2, + 2, + 2, + null, + null + ], + "/myapp/app/models/user.rb": [ + null, + null, + 1, + null, + null, + 1, + null, + 1, + 1, + null, + 1, + null + ], + "/myapp/app/models/application_record.rb": [ + null, + null, + 1, + 1, + null + ], + "/myapp/config/routes.rb": [ + null, + null, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + 1, + null + ], + "/myapp/app/helpers/albums_helper.rb": [ + null, + null, + 1, + null + ], + "/myapp/app/helpers/application_helper.rb": [ + null, + null, + 1, + 1, + 0, + 0, + 0, + null, + null + ], + "/myapp/app/helpers/artists_helper.rb": [ + null, + null, + 1, + null + ], + "/myapp/app/helpers/music_helper.rb": [ + null, + null, + 1, + null + ], + "/myapp/app/helpers/reviews_helper.rb": [ + null, + null, + 1, + null + ], + "/myapp/app/helpers/tracks_helper.rb": [ + null, + null, + 1, + null + ], + "/myapp/app/helpers/users_helper.rb": [ + null, + null, + 1, + null + ], + "/myapp/spec/support/controller_macros.rb": [ + null, + null, + 1, + 1, + 3, + 3, + null, + null + ], + "/myapp/app/controllers/reviews_controller.rb": [ + null, + null, + 1, + 1, + 1, + 1, + 4, + 4, + null, + null, + 1, + 3, + 3, + 3, + 3, + 3, + 3, + 6, + 3, + null, + 0, + null, + null, + null, + 1, + 0, + 0, + 0, + null, + 0, + null, + null, + null, + 1, + 0, + 0, + 0, + null, + 0, + null, + null, + null, + 1, + null, + 1, + 4, + 0, + null, + 4, + null, + null, + null, + 1, + 0, + null, + null, + 1, + 3, + null, + null + ], + "/myapp/app/controllers/application_controller.rb": [ + null, + null, + 1, + 1, + 1, + 1, + 1, + null, + 1, + 0, + null, + null, + 1, + null, + 1, + 0, + 0, + 0, + 0, + null, + null, + 1, + null, + 1, + 8, + 8, + null, + null, + 1, + 8, + null, + null + ], + "/myapp/app/models/review.rb": [ + null, + null, + 1, + 1, + 1, + null, + 1, + 1, + 1, + null + ], + "/myapp/app/models/track.rb": [ + null, + null, + 1, + 1, + 1, + 1, + 1, + 1, + null, + 1, + 0, + null, + null, + 1, + 0, + 0, + null, + 0, + null, + null, + null + ] + }, + "timestamp": 1576440671 + } +} diff --git a/coverage/.resultset.json.lock b/coverage/.resultset.json.lock new file mode 100644 index 0000000..e69de29 diff --git a/spec/controllers/reviews_controller_spec.rb b/spec/controllers/reviews_controller_spec.rb index 13bc8f4..d6eaa1e 100644 --- a/spec/controllers/reviews_controller_spec.rb +++ b/spec/controllers/reviews_controller_spec.rb @@ -3,8 +3,10 @@ require 'rails_helper' describe ReviewsController, type: :controller do - let(:track) { create(:track) } + let(:track) { create(:track, spotify_id: '7BUBM2XnhnWnYZhGDU1Mvm') } let(:user) { create(:user) } + let(:another_user) { create(:another_user) } + let(:review) { create(:review, user_id: user.id, track_spotify_id: '7BUBM2XnhnWnYZhGDU1Mvm') } describe '#create' do context 'can save' do @@ -21,7 +23,7 @@ it 'redirects to track_path' do subject - expect(response).to redirect_to(track_path(track.spotify_id)) + expect(response).to redirect_to(track_path('7BUBM2XnhnWnYZhGDU1Mvm')) end end @@ -39,7 +41,45 @@ it 'redirects to track_path' do subject - expect(response).to redirect_to(track_path(track.spotify_id)) + expect(response).to redirect_to(track_path('7BUBM2XnhnWnYZhGDU1Mvm')) + end + end + end + + describe '#edit' do + context 'log in' do + before do + login user + get :edit, params: { track_spotify_id: track.spotify_id, id: review.id } + end + + it 'assigns @review' do + expect(assigns(:review)).to eq review + end + + it 'renders the :edit template' do + expect(response).to render_template :edit + end + end + + context 'log in by another user' do + before do + login another_user + get :edit, params: { track_spotify_id: track.spotify_id, id: review.id } + end + + it 'redirects to root_path' do + expect(response).to redirect_to(root_path) + end + end + + context 'not log in' do + before do + get :edit, params: { track_spotify_id: track.spotify_id, id: review.id } + end + + it 'redirects to new_user_session_path' do + expect(response).to redirect_to(new_user_session_path) end end end diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 3433abf..7318be0 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -9,4 +9,13 @@ password_confirmation { password } avatar { File.open("#{Rails.root}/public/images/test_image.png") } end + + factory :another_user, class: User do + password = Faker::Internet.password(min_length: 8) + name { Faker::Name.last_name } + email { Faker::Internet.free_email } + password { password } + password_confirmation { password } + avatar { File.open("#{Rails.root}/public/images/test_image.png") } + end end