Skip to content

Commit

Permalink
Upgrade to latest RSpec.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Mar 17, 2015
1 parent 6b967c0 commit bc43ece
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
.DS_Store
pkg
*.lock
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--color
3 changes: 1 addition & 2 deletions Gemfile
@@ -1,3 +1,2 @@
source :rubygems

source 'https://rubygems.org'
gemspec
77 changes: 0 additions & 77 deletions Gemfile.lock

This file was deleted.

9 changes: 3 additions & 6 deletions normalize_attributes.gemspec
@@ -1,6 +1,4 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "normalize_attributes/version"
require "./lib/normalize_attributes/version"

Gem::Specification.new do |s|
s.name = "normalize_attributes"
Expand All @@ -17,9 +15,8 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency "activerecord", ">= 3.0.0"
s.add_development_dependency "rspec", ">= 2.0.0"
s.add_dependency "activerecord"
s.add_development_dependency "rspec"
s.add_development_dependency "sqlite3-ruby"
s.add_development_dependency "actionpack"
s.add_development_dependency "ruby-debug19"
end
36 changes: 18 additions & 18 deletions spec/normalize_attributes_spec.rb
Expand Up @@ -6,49 +6,49 @@
end

it "should respond to aliases" do
User.should respond_to(:normalize)
User.should respond_to(:normalize_attr)
User.should respond_to(:normalize_attrs)
User.should respond_to(:normalize_attribute)
User.should respond_to(:normalize_attributes)
expect(User).to respond_to(:normalize)
expect(User).to respond_to(:normalize_attr)
expect(User).to respond_to(:normalize_attrs)
expect(User).to respond_to(:normalize_attribute)
expect(User).to respond_to(:normalize_attributes)
end

it "should apply single normalization method" do
User.normalize :email, :with => :downcase
user = User.create(:email => "JOHN@DOE.COM")

user.email.should == "john@doe.com"
expect(user.email).to eq("john@doe.com")
end

it "should apply multiple normalization methods" do
User.normalize :email, :with => [:downcase, :reverse]
user = User.create(:email => "JOHN@DOE.COM")

user.email.should == "moc.eod@nhoj"
expect(user.email).to eq("moc.eod@nhoj")
end

it "should apply proc" do
User.normalize(:email) {|v| v.downcase }
user = User.create(:email => "JOHN@DOE.COM")

user.email.should == "john@doe.com"
expect(user.email).to eq("john@doe.com")
end

it "should apply instance method" do
User.normalize(:username, :with => :normalize_username)
user = User.create(:username => "JOHNDOE")

user.username.should == "johndoe"
expect(user.username).to eq("johndoe")
end

it "should use value before type casting" do
User.normalize(:age, :raw => true) do |v|
v.should == "1.2"
expect(v).to eq("1.2")
v.to_f * 10
end

user = User.create(:age => "1.2")
user.age.should == 12
expect(user.age).to eq(12)
end

it "should apply normalizers to accessor" do
Expand All @@ -59,15 +59,15 @@
User.normalize(:email, :with => :downcase) {|v| v.reverse }
user = User.create(:email => "JOHN@DOE.COM")

user.email.should == "moc.eod@nhoj"
expect(user.email).to eq("moc.eod@nhoj")
end

it "should normalize multiple attributes" do
User.normalize :email, :username, :with => :downcase
user = User.create(:email => "JOHN@DOE.COM", :username => "JOHN")

user.email.should == "john@doe.com"
user.username.should == "john"
expect(user.email).to eq("john@doe.com")
expect(user.username).to eq("john")
end

it "should not apply on associations" do
Expand All @@ -83,22 +83,22 @@
User.normalize :email
user = User.create(:email => " \n\t john@doe.com \t\t\n\r\n", :username => "john")

user.email.should == "john@doe.com"
expect(user.email).to eq("john@doe.com")
end

it "should apply default filter on arrays" do
User.normalize :preferences
user = User.create(:preferences => [nil, :games, :music])
user.preferences.should == [:games, :music]
expect(user.preferences).to eq([:games, :music])
end

it "should not apply default filter on unknown objects" do
User.normalize :username

expect {
user = User.create(:username => 100)
user.username.should == 100
}.to_not raise_error
expect(user.username).to eq("100")
}.not_to raise_error
end

it "should not apply filter when object do not respond to normalizer" do
Expand Down

0 comments on commit bc43ece

Please sign in to comment.