Skip to content

Commit

Permalink
Merge pull request #36 from jc00ke/limit-number-links-in-desceiption
Browse files Browse the repository at this point in the history
Limit the # of links allowed in event description
  • Loading branch information
reidab committed Jun 5, 2013
2 parents c9f188e + 97c9210 commit c8bd3e3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ def create
flash[:failure] = "<h3>Evil Robot</h3> We didn't create this event because we think you're an evil robot. If you're really not an evil robot, look at the form instructions more carefully. If this doesn't work please file a bug report and let us know."
end

if too_many_links = too_many_links?(@event.description)
flash[:failure] = "We allow a maximum of 3 links in a description. You have too many links."
end

respond_to do |format|
if !evil_robot && params[:preview].nil? && @event.save
if !evil_robot && !too_many_links && params[:preview].nil? && @event.save
flash[:success] = 'Your event was successfully created. '
format.html {
if has_new_venue && !params[:venue_name].blank?
Expand Down Expand Up @@ -108,8 +112,12 @@ def update
flash[:failure] = "<h3>Evil Robot</h3> We didn't update this event because we think you're an evil robot. If you're really not an evil robot, look at the form instructions more carefully. If this doesn't work please file a bug report and let us know."
end

if too_many_links = too_many_links?(@event.description)
flash[:failure] = "We allow a maximum of 3 links in a description. You have too many links."
end

respond_to do |format|
if !evil_robot && params[:preview].nil? && @event.update_attributes(params[:event])
if !evil_robot && !too_many_links && params[:preview].nil? && @event.update_attributes(params[:event])
flash[:success] = 'Event was successfully updated.'
format.html {
if has_new_venue && !params[:venue_name].blank?
Expand Down Expand Up @@ -219,6 +227,12 @@ def clone

protected

# Checks if the description has too many links
# which is probably spam
def too_many_links?(description)
description.scan(/http/).size > 3
end

# Export +events+ to an iCalendar file.
def ical_export(events=nil)
events = events || Event.future.non_duplicates
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@
flash[:failure].should match /evil robot/i
end

it "should not allow too many links in the description" do
@params[:event][:description] = <<-DESC
http://example.com
https://example.com
http://example.net
https://example.net
DESC
post "create", @params
response.should render_template :new
flash[:failure].should match /too many links/i
end

it "should allow the user to preview the event" do
event = Event.new(:title => "Awesomeness")
Event.should_receive(:new).and_return(event)
Expand Down Expand Up @@ -555,6 +567,18 @@
flash[:failure].should match /evil robot/i
end

it "should not allow too many links in the description" do
@params[:event][:description] = <<-DESC
http://example.com
https://example.com
http://example.net
https://example.net
DESC
post "create", @params
response.should render_template :new
flash[:failure].should match /too many links/i
end

it "should allow the user to preview the event" do
tags = []
tags.should_receive(:reload)
Expand Down

0 comments on commit c8bd3e3

Please sign in to comment.