fix channel video_id validation when updating
This commit is contained in:
parent
167f1ea6ae
commit
c0bc92b7e2
@ -202,7 +202,8 @@ class ChannelsController < ApplicationController
|
|||||||
@channel.assign_attributes(channel_params)
|
@channel.assign_attributes(channel_params)
|
||||||
|
|
||||||
if !@channel.valid?
|
if !@channel.valid?
|
||||||
flash[:alert] = @channel.errors.full_messages.join(', ')
|
@channel.errors.add(:base, t(:channel_video_type_blank))
|
||||||
|
flash[:alert] = @channel.errors.full_messages.join('. ')
|
||||||
redirect_to channel_path(@channel.id, :anchor => "channelsettings") and return
|
redirect_to channel_path(@channel.id, :anchor => "channelsettings") and return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class Channel < ActiveRecord::Base
|
|||||||
|
|
||||||
before_destroy :delete_feeds
|
before_destroy :delete_feeds
|
||||||
|
|
||||||
validates :video_type, :presence => { :message => I18n.t(:channel_video_type_blank) }, :if => lambda{ |channel| channel.video_id.present? }
|
validates :video_type, :presence => true, :if => lambda{ |channel| channel.video_id.present? }
|
||||||
|
|
||||||
scope :public_viewable, lambda { where("public_flag = true AND social != true") }
|
scope :public_viewable, lambda { where("public_flag = true AND social != true") }
|
||||||
scope :not_social, lambda { where("social != true") }
|
scope :not_social, lambda { where("social != true") }
|
||||||
|
File diff suppressed because one or more lines are too long
@ -26,12 +26,20 @@ describe ChannelsController do
|
|||||||
channel.windows.where(window_type: 'chart').count.should eq(2)
|
channel.windows.where(window_type: 'chart').count.should eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not allow channel to be updated with invalid parameters' do
|
||||||
|
@channel.update_attributes({video_type: nil, video_id: nil})
|
||||||
|
put :update, id: @channel, channel: {video_id: 'invalid_id'}
|
||||||
|
flash[:alert].should match /#{I18n.t(:channel_video_type_blank)}/
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
it "should allow a channel to be edited" do
|
it "should allow a channel to be edited" do
|
||||||
@channel.public_flag = true
|
@channel.public_flag = true
|
||||||
put :update, id: @channel, channel: {name: 'new name'}, tags: FactoryGirl.attributes_for(:tag)
|
put :update, id: @channel, channel: {name: 'new name'}, tags: FactoryGirl.attributes_for(:tag)
|
||||||
@channel.reload
|
@channel.reload
|
||||||
@channel.name.should eq('new name')
|
@channel.name.should eq('new name')
|
||||||
response.should redirect_to channel_path(@channel.id)
|
response.should redirect_to channel_path(@channel.id)
|
||||||
|
flash[:notice].should eq(I18n.t(:channel_update_success))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should allow a channel to be deleted " do
|
it "should allow a channel to be deleted " do
|
||||||
|
Loading…
Reference in New Issue
Block a user