From 5508d03729a8abb6f59089d838a38bdd038409a0 Mon Sep 17 00:00:00 2001 From: Alex Abramov Date: Thu, 26 Dec 2024 21:22:17 +0700 Subject: [PATCH] add feature basic tests --- app/views/podcasts/show.html.erb | 33 ++++++----- spec/features/podcasts/edit_update_spec.rb | 67 ++++++++++++++++++++++ spec/features/podcasts/new_create_spec.rb | 54 +++++++++++++++++ spec/features/podcasts/show_spec.rb | 30 ++++++++++ spec/models/podcast_spec.rb | 2 +- spec/models/user_spec.rb | 2 +- 6 files changed, 172 insertions(+), 16 deletions(-) create mode 100644 spec/features/podcasts/edit_update_spec.rb create mode 100644 spec/features/podcasts/new_create_spec.rb create mode 100644 spec/features/podcasts/show_spec.rb diff --git a/app/views/podcasts/show.html.erb b/app/views/podcasts/show.html.erb index f481137..3500f7c 100644 --- a/app/views/podcasts/show.html.erb +++ b/app/views/podcasts/show.html.erb @@ -2,17 +2,20 @@
- <% if @podcast.photo.attached? %> - <%= image_tag @podcast.photo, height: 500 %> - <% else %> - - <% end %> - - <% if @podcast.audio.attached? %> - <%= audio_tag @podcast.audio, controls: true %> - <% else %> - - <% end %> +
+ <% if @podcast.photo.attached? %> + <%= image_tag @podcast.photo, height: 500 %> + <% else %> + + <% end %> +
+
+ <% if @podcast.audio.attached? %> + <%= audio_tag @podcast.audio, controls: true %> + <% else %> + + <% end %> +
@@ -29,8 +32,10 @@
-
- <%= link_to "Редактировать Podcast", edit_podcast_path(@podcast), class: "btn btn-secondary mb-2" %> - <%= button_to "Удалить Podcast", podcast_path(@podcast), method: :delete, data: { confirm: "Вы уверены?" }, class: "btn btn-danger mb-2" %> +
+
+ <%= link_to "Редактировать Podcast", edit_podcast_path(@podcast), class: "btn btn-secondary mb-2" %> + <%= button_to "Удалить Podcast", podcast_path(@podcast), method: :delete, data: { confirm: "Вы уверены?" }, class: "btn btn-danger mb-2" %> +
diff --git a/spec/features/podcasts/edit_update_spec.rb b/spec/features/podcasts/edit_update_spec.rb new file mode 100644 index 0000000..59e18df --- /dev/null +++ b/spec/features/podcasts/edit_update_spec.rb @@ -0,0 +1,67 @@ +require 'rails_helper' + +RSpec.feature "Podcasts#edit", type: :feature do + let(:podcast) do + FactoryBot.create(:podcast, title: Faker::ProgrammingLanguage.name, + description: Faker::Markdown.emphasis) + end + + before do + visit edit_podcast_path(podcast) + end + + context 'user sees' do + scenario "the current podcast details in the form" do + expect(page).to have_content("Редактировать Podcast: #{podcast.title}") + + expect(find_field('podcast[title]').value).to eq(podcast.title) + expect(find_field('podcast[description]').value).to eq(podcast.description) + end + + scenario "the form fields for uploading a photo and audio" do + expect(page).to have_field('podcast_photo') + expect(page).to have_field('podcast_audio') + end + + scenario "the back button" do + expect(page).to have_link("Назад", href: podcast_path(podcast)) + end + end + + # context 'user updates the podcast' do + # scenario "successfully updates the podcast title and description" do + # fill_in 'podcast[title]', with: "Updated Podcast Title" + # fill_in 'podcast[description]', with: "Updated description." + # click_button 'Submit Podcast' + + # expect(page).to have_content("Podcast was successfully updated.") + # expect(page).to have_content("Updated Podcast Title") + # expect(page).to have_content("Updated description.") + # end + + # scenario "uploads a new photo" do + # attach_file('podcast[photo]', Rails.root.join('spec/fixtures/files/sample_image.png')) + # fill_in 'podcast[title]', with: "Updated Podcast Title" + # fill_in 'podcast[description]', with: "Updated description." + # click_button 'Submit Podcast' + + # expect(page).to have_content("Podcast was successfully updated.") + # end + + # scenario "uploads a new audio file" do + # attach_file('podcast[audio]', Rails.root.join('spec/fixtures/files/sample_audio.mp3')) + # fill_in 'podcast[title]', with: "Updated Podcast Title" + # fill_in 'podcast[description]', with: "Updated description." + # click_button 'Submit Podcast' + + # expect(page).to have_content("Podcast was successfully updated.") + # end + # end + + # context 'user navigates back' do + # scenario "returns to the podcast show page" do + # click_link "Назад" + # expect(current_path).to eq(podcast_path(podcast)) + # end + # end +end diff --git a/spec/features/podcasts/new_create_spec.rb b/spec/features/podcasts/new_create_spec.rb new file mode 100644 index 0000000..ff10253 --- /dev/null +++ b/spec/features/podcasts/new_create_spec.rb @@ -0,0 +1,54 @@ +require 'rails_helper' + +RSpec.feature "Podcasts#edit", type: :feature do + before do + visit new_podcast_path + end + + context 'user sees' do + scenario "the podcast creation form" do + expect(page).to have_content("Создать Podcast") + expect(page).to have_field('podcast[title]') + expect(page).to have_field('podcast[description]') + expect(page).to have_field('podcast_photo') + expect(page).to have_field('podcast_audio') + end + end + + # context 'user updates the podcast' do + # scenario "successfully updates the podcast title and description" do + # fill_in 'podcast[title]', with: "Updated Podcast Title" + # fill_in 'podcast[description]', with: "Updated description." + # click_button 'Submit Podcast' + + # expect(page).to have_content("Podcast was successfully updated.") + # expect(page).to have_content("Updated Podcast Title") + # expect(page).to have_content("Updated description.") + # end + + # scenario "uploads a new photo" do + # attach_file('podcast[photo]', Rails.root.join('spec/fixtures/files/sample_image.png')) + # fill_in 'podcast[title]', with: "Updated Podcast Title" + # fill_in 'podcast[description]', with: "Updated description." + # click_button 'Submit Podcast' + + # expect(page).to have_content("Podcast was successfully updated.") + # end + + # scenario "uploads a new audio file" do + # attach_file('podcast[audio]', Rails.root.join('spec/fixtures/files/sample_audio.mp3')) + # fill_in 'podcast[title]', with: "Updated Podcast Title" + # fill_in 'podcast[description]', with: "Updated description." + # click_button 'Submit Podcast' + + # expect(page).to have_content("Podcast was successfully updated.") + # end + # end + + # context 'user navigates back' do + # scenario "returns to the podcast show page" do + # click_link "Назад" + # expect(current_path).to eq(podcast_path(podcast)) + # end + # end +end diff --git a/spec/features/podcasts/show_spec.rb b/spec/features/podcasts/show_spec.rb new file mode 100644 index 0000000..fa818da --- /dev/null +++ b/spec/features/podcasts/show_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +RSpec.feature "Podcasts#show", type: :feature do + let(:podcast) do + FactoryBot.create(:podcast, title: Faker::ProgrammingLanguage.name, + description: Faker::Markdown.emphasis) + end + + before do + visit podcast_path(podcast) + end + + context 'user see' do + scenario "podcast details" do + expect(page).to have_content(podcast.title) + expect(page).to have_content(podcast.description) + expect(page).to have_content(podcast.created_at) + end + + scenario "special notice cuz no photo" do + expect(page).to have_selector("div.alert.alert-warning", text: "No Photo Available!") + expect(page).to have_selector("div.alert.alert-warning", text: "No Audio Available!") + end + + scenario "manipulation buttons" do + expect(page).to have_link("Редактировать Podcast", href: edit_podcast_path(podcast)) + expect(page).to have_button("Удалить Podcast") + end + end +end diff --git a/spec/models/podcast_spec.rb b/spec/models/podcast_spec.rb index ba9e668..fad0e5c 100644 --- a/spec/models/podcast_spec.rb +++ b/spec/models/podcast_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' RSpec.describe Podcast, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + # pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 47a31bb..11aa1c4 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' RSpec.describe User, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + # pending "add some examples to (or delete) #{__FILE__}" end