This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

truncating long user agent strings before saving

  • Loading branch information...
jimarnold committed Jun 1, 2012
1 parent 47b5c96 commit 836b53338126dc0e2059b6a8b7dab1517e5da781
Showing with 15 additions and 1 deletion.
  1. +6 −0 app/models/signature.rb
  2. +9 −1 spec/models/signature_spec.rb
@@ -4,4 +4,10 @@ class Signature < ActiveRecord::Base
belongs_to :member
validates_presence_of :name
validates :email, :presence => true, :email => true
before_save :truncate_user_agent
def truncate_user_agent
self.user_agent = self.user_agent[0..254]
end
end
@@ -1,10 +1,18 @@
require 'spec_helper'
describe Signature do
describe "validation" do
context "validation" do
subject { build(:signature) }
it { should validate_presence_of :email }
it { should validate_presence_of :name }
it_behaves_like "email validator"
end
context "given a really long user agent" do
it "truncates it to 255 characters" do
signature = build(:signature, user_agent: "0" * 512)
signature.save!
signature.user_agent.length.should == 255
end
end
end

0 comments on commit 836b533

Please sign in to comment.