Added form fields for the admin podcasts dashboard. (#10517)

* Added form fields for the admin podcasts dashboard.

* Updated podcasts_controller.rb; Added parameters to the allowed params.
Updated edit.html.erb; Removed duplicated field.
Updated podcasts_spec.rb; Updated test.

* Fixed a typo.

* Refactored test which hopefully fixes the build

* Added missing comma.

* Added file fixture uploads.

* Fixed a typo.

* Update spec/requests/admin/podcasts_spec.rb

Co-authored-by: Fernando Valverde <fernando@visualcosita.com>

* Again fixed another typo.

* And again fixed another typo.

* Fixed merge conflicts.

Co-authored-by: Fernando Valverde <fernando@visualcosita.com>
Co-authored-by: rhymes <rhymes@hey.com>
This commit is contained in:
Wouter van Marrum 2020-11-02 17:19:39 +01:00 committed by GitHub
parent 2009aa3817
commit 9946ac221a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 6 deletions

View file

@ -65,7 +65,21 @@ module Admin
def podcast_params
allowed_params = %i[
title feed_url published
title
feed_url
description
itunes_url
overcast_url
android_url
soundcloud_url
website_url
twitter_username
pattern_image
main_color_hex
slug
image
reachable
published
]
params.require(:podcast).permit(allowed_params)
end

View file

@ -64,6 +64,54 @@
<%= f.label :feed_url, for: "podcast_feed_url" %>
<%= f.text_field :feed_url, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :description, for: "description" %>
<%= f.text_area :description, size: "45x10", required: true, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :itunes_url, for: "itunes_url" %>
<%= f.text_field :itunes_url, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :overcast_url, for: "overcast_url" %>
<%= f.text_field :overcast_url, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :android_url, for: "android_url" %>
<%= f.text_field :android_url, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :soundcloud_url, for: "soundcloud_url" %>
<%= f.text_field :soundcloud_url, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :website_url, for: "website_url" %>
<%= f.text_field :website_url, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :twitter_username, for: "twitter_username" %>
<%= f.text_field :twitter_username, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :pattern_image, for: "pattern_image" %>
<%= f.file_field :pattern_image, accept: "image/*", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :main_color_hex, for: "main_color_hex" %>
<%= f.text_field :main_color_hex, placeholder: "FF00FF", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :slug, for: "slug" %>
<%= f.text_field :slug, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :image, for: "image" %>
<%= f.file_field :image, accept: "image/*", class: "form-control" %>
</div>
<div class="crayons-field crayons-field--checkbox">
<%= f.check_box :reachable, class: "crayons-checkbox" %>
<%= f.label :reachable, "Podcast is reachable", class: "crayons-field__label" %>
</div>
<div class="crayons-field crayons-field--checkbox">
<%= f.check_box "published", class: "crayons-checkbox" %>
<label class="crayons-field__label" for="published">

View file

@ -60,19 +60,53 @@ RSpec.describe "/admin/podcasts", type: :request do
end
describe "Updating" do
let(:update_params) do
{
title: "hello",
feed_url: "https://pod.example.com/rss.rss",
description: "Description",
itunes_url: "https://itunes.example.com",
overcast_url: "https://overcast.example.com",
android_url: "https://android.example.com",
soundcloud_url: "https://soundcloud.example.com",
website_url: "https://example.com",
twitter_username: "@ThePracticalDev",
pattern_image: fixture_file_upload("files/800x600.png", "image/png"),
main_color_hex: "ffffff",
image: fixture_file_upload("files/podcast.png", "image/png"),
slug: "postcast-test-url",
reachable: true,
published: true,
}
end
it "updates the podcast" do
put admin_podcast_path(podcast), params: { podcast: { title: "hello",
feed_url: "https://pod.example.com/rss.rss",
published: true } }
put admin_podcast_path(podcast), params: { podcast: update_params }
podcast.reload
expect(podcast.title).to eq("hello")
expect(podcast.feed_url).to eq("https://pod.example.com/rss.rss")
expect(podcast.description).to eq("Description")
expect(podcast.itunes_url).to eq("https://itunes.example.com")
expect(podcast.overcast_url).to eq("https://overcast.example.com")
expect(podcast.android_url).to eq("https://android.example.com")
expect(podcast.soundcloud_url).to eq("https://soundcloud.example.com")
expect(podcast.website_url).to eq("https://example.com")
expect(podcast.twitter_username).to eq("@ThePracticalDev")
expect(podcast.main_color_hex).to eq("ffffff")
expect(podcast.slug).to eq("postcast-test-url")
expect(podcast.reachable).to eq(true)
expect(podcast.published).to eq(true)
end
it "updates image & pattern_image" do
expect do
put admin_podcast_path(podcast), params: { podcast: update_params }
podcast.reload
end.to change(podcast, :image) && change(podcast, :pattern_image)
end
it "redirects after update" do
put admin_podcast_path(podcast), params: { podcast: { title: "hello",
feed_url: "https://pod.example.com/rss.rss" } }
put admin_podcast_path(podcast), params: { podcast: update_params }
expect(response).to redirect_to(admin_podcasts_path)
end
end