Skip to content

Commit

Permalink
SRCH-2260 fix affiliate rss feed urls (#745)
Browse files Browse the repository at this point in the history
* SRCH-2260 Update affiliate.rss_feed_urls for MySQL 5.7
  • Loading branch information
jmax-fearless authored Jul 6, 2021
1 parent d21539b commit ebbfb6d
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ executors:
environment:
RAILS_ENV: test

- image: circleci/mysql:5.6
- image: circleci/mysql:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_ROOT_HOST: "%"
Expand Down
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Metrics/BlockLength:
# Exclude ActiveScaffold-based controllers
- app/controllers/admin/**/*

Style/ClassAndModuleChildren:
Enabled: false

Style/LambdaCall:
Exclude:
# Exclude files relying on Jbuilder DSL
Expand Down
26 changes: 13 additions & 13 deletions app/controllers/sites/rss_feeds_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

class Sites::RssFeedsController < Sites::SetupSiteController
include ActionView::Helpers::TextHelper
before_action :setup_rss_feed, only: [:show, :edit, :update]
before_action :setup_non_managed_rss_feed, only: [:destroy]

def index
@rss_feeds = @site.rss_feeds
@rss_feeds = @site.rss_feeds.order(:name)
end

def new
Expand All @@ -23,30 +25,27 @@ def create
assign_rss_feed_urls(rss_feed_params[:rss_feed_urls_attributes])
if @rss_feed.save
redirect_to site_rss_feeds_path(@site),
flash: { success: "You have added #{@rss_feed.name} to this site." }
flash: { success: "You have added #{@rss_feed.name} to this site." }
else
build_url
render action: :new
end
end
end

def show
end
def show; end

def edit
build_url
end

def update
RssFeed.transaction do
@rss_feed.assign_attributes rss_feed_params.except(:rss_feed_urls_attributes)
unless @rss_feed.is_managed?
assign_rss_feed_urls(rss_feed_params[:rss_feed_urls_attributes])
end
@rss_feed.assign_attributes(rss_feed_params.except(:rss_feed_urls_attributes))
assign_rss_feed_urls(rss_feed_params[:rss_feed_urls_attributes]) unless @rss_feed.is_managed?
if @rss_feed.save
redirect_to site_rss_feeds_path(@site),
flash: { success: "You have updated #{@rss_feed.name}." }
flash: { success: "You have updated #{@rss_feed.name}." }
else
build_url
render action: :edit
Expand All @@ -57,7 +56,7 @@ def update
def destroy
@rss_feed.destroy
redirect_to site_rss_feeds_path(@site),
flash: { success: "You have removed #{@rss_feed.name} from this site." }
flash: { success: "You have removed #{@rss_feed.name} from this site." }
end

private
Expand All @@ -74,7 +73,8 @@ def assign_rss_feed_urls(attributes)
rss_feed_urls_attributes.each_value do |url_attributes|
url = url_attributes[:url]
next if url.blank?
rss_feed_url = RssFeedUrl.rss_feed_owned_by_affiliate.find_existing_or_initialize url

rss_feed_url = RssFeedUrl.rss_feed_owned_by_affiliate.find_existing_or_initialize(url)
if rss_feed_url.new_record?
new_urls << rss_feed_url.url
else
Expand All @@ -89,7 +89,7 @@ def assign_rss_feed_urls(attributes)
end

def setup_rss_feed
@rss_feed = @site.rss_feeds.find_by_id(params[:id])
@rss_feed = @site.rss_feeds.find_by(id: params[:id])
redirect_to site_rss_feeds_path(@site) unless @rss_feed
end

Expand All @@ -100,7 +100,7 @@ def rss_feed_params
end

def setup_non_managed_rss_feed
@rss_feed = @site.rss_feeds.non_managed.find_by_id(params[:id])
@rss_feed = @site.rss_feeds.non_managed.find_by(id: params[:id])
redirect_to site_rss_feeds_path(@site) unless @rss_feed
end
end
Loading

0 comments on commit ebbfb6d

Please sign in to comment.