Skip to content

Commit

Permalink
add feature basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
o-200 committed Dec 26, 2024
1 parent 8a808e6 commit 5508d03
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 16 deletions.
33 changes: 19 additions & 14 deletions app/views/podcasts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
<div class="d-flex">
<div class="px-2">
<div class="card d-flex flex-column mb-3">
<% if @podcast.photo.attached? %>
<%= image_tag @podcast.photo, height: 500 %>
<% else %>
<div class="alert alert-warning" role="alert">No Photo Available!</div>
<% end %>

<% if @podcast.audio.attached? %>
<%= audio_tag @podcast.audio, controls: true %>
<% else %>
<div class="alert alert-warning" role="alert">No Audio Available!</div>
<% end %>
<div class="photo">
<% if @podcast.photo.attached? %>
<%= image_tag @podcast.photo, height: 500 %>
<% else %>
<div class="alert alert-warning" role="alert">No Photo Available!</div>
<% end %>
</div>
<div class="audio">
<% if @podcast.audio.attached? %>
<%= audio_tag @podcast.audio, controls: true %>
<% else %>
<div class="alert alert-warning" role="alert">No Audio Available!</div>
<% end %>
</div>
</div>
</div>

Expand All @@ -29,8 +32,10 @@
</div>
</div>

<div class="d-flex flex-column mb-3">
<%= 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" %>
<div class="control-buttons">
<div class="d-flex flex-column mb-3">
<%= 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" %>
</div>
</div>
</turbo_frame>
67 changes: 67 additions & 0 deletions spec/features/podcasts/edit_update_spec.rb
Original file line number Diff line number Diff line change
@@ -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

Check failure on line 31 in spec/features/podcasts/edit_update_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/CommentIndentation: Incorrect indentation detected (column 2 instead of 4).
# 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

Check failure on line 40 in spec/features/podcasts/edit_update_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/CommentIndentation: Incorrect indentation detected (column 4 instead of 2).

# 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
54 changes: 54 additions & 0 deletions spec/features/podcasts/new_create_spec.rb
Original file line number Diff line number Diff line change
@@ -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

Check failure on line 18 in spec/features/podcasts/new_create_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/CommentIndentation: Incorrect indentation detected (column 2 instead of 4).
# 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

Check failure on line 27 in spec/features/podcasts/new_create_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/CommentIndentation: Incorrect indentation detected (column 4 instead of 2).

# 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
30 changes: 30 additions & 0 deletions spec/features/podcasts/show_spec.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/models/podcast_spec.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5508d03

Please sign in to comment.