Sha256: 9c2b10349055fce362b4238eb49d32934d476962f258dc7a89d136cb1c1271b7

Contents?: true

Size: 1.85 KB

Versions: 4

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'

describe OpenConferenceWare::NormalizeUrlMixin do
  NormalizeUrlMixin = OpenConferenceWare::NormalizeUrlMixin

  describe "normalize_url!" do
    it "should preserve valid URLs as-is" do
      NormalizeUrlMixin.normalize_url!('http://foo.bar/').should == 'http://foo.bar/'
    end

    it "should append trailing slash to URLs" do
      NormalizeUrlMixin.normalize_url!('http://foo.bar').should == 'http://foo.bar/'
    end

    it "should preserve valid URLs with paths as-is" do
      NormalizeUrlMixin.normalize_url!('http://foo.bar/baz').should == 'http://foo.bar/baz'
    end

    it "should add http schema to pure hostnames" do
      NormalizeUrlMixin.normalize_url!('foo.bar').should == 'http://foo.bar/'
    end

    it "should add http schema to hostname/paths" do
      NormalizeUrlMixin.normalize_url!('foo.bar/baz').should == 'http://foo.bar/baz'
    end
  end

  describe "validation" do
    fixtures :open_conference_ware_users
    # TODO Mock an entire ActiveRecord model to isolate these behaviors, rather than relying on User
    before(:each) do
      @record = users(:aaron)
    end

    it "should handle nil" do
      @record.website = nil
      @record.should be_valid
      @record.website.should be_blank
    end

    it "should handle blank" do
      @record.website = ''
      @record.should be_valid
      @record.website.should be_blank
    end

    it "should handle valid" do
      @record.website = 'http://foo.bar/'
      @record.should be_valid
      @record.website.should == 'http://foo.bar/'
    end

    it "should handle unqualified" do
      @record.website = 'foo.bar'
      @record.should be_valid
      @record.website.should == 'http://foo.bar/'
    end

    it "should fail invalid" do
      @record.website = '<asdf>'
      @record.should_not be_valid
      @record.errors[:website].should == ["is invalid"]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
open_conference_ware-1.0.0.pre4 spec/mixins/open_conference_ware/normalize_url_mixin_spec.rb
open_conference_ware-1.0.0.pre3 spec/mixins/open_conference_ware/normalize_url_mixin_spec.rb
open_conference_ware-1.0.0.pre2 spec/mixins/open_conference_ware/normalize_url_mixin_spec.rb
open_conference_ware-1.0.0.pre1 spec/mixins/open_conference_ware/normalize_url_mixin_spec.rb