bakineggs (owner)

Revisions

gist: 117263 Download_button fork
public
Public Clone URL: git://gist.github.com/117263.git
Embed All Files: show embed
app/models/wall.rb #
1
2
3
4
5
6
7
8
9
class Wall < ActiveRecord::Base
 
  # snip
 
  validates_uniqueness_of :name, :scope => [:latitude, :longitude], :case_sensitive => false
 
  # snip
 
end
db/example_data.rb #
1
2
3
4
5
6
7
8
9
module FixtureReplacement
  attributes_for :wall do |wall|
    wall.name = Faker::Lorem.sentence(1)
    wall.city = Faker::Address.city
    wall.state = Faker::Address.us_state
    wall.latitude = (rand * 180 - 90).round 4
    wall.longitude = (rand * 360 - 180).round 4
  end
end
spec/models/wall_spec.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
describe Wall do
 
  # snip
 
  it 'should not allow walls with duplicate name, latitude, and longitude' do
    wall = create_wall
    wall.should be_valid
    wall.should_not be_new_record
    new_wall(:name => wall.name).should be_valid
    new_wall(:latitude => wall.latitude, :longitude => wall.longitude).should be_valid
    check_wall = new_wall :name => wall.name, :latitude => wall.latitude, :longitude => wall.longitude
    check_wall.name.should == wall.name
    check_wall.latitude.should == wall.latitude
    check_wall.longitude.should == wall.longitude
    check_wall.should_not be_valid
  end
 
  # snip
 
end
Text only #
1
2
3
4
5
6
7
8
9
10
11
/opt/local/bin/ruby /Users/dan/graffiti/vendor/plugins/rspec/bin/spec spec/models/wall_spec.rb -O spec/spec.opts
........F...
 
1)
'Wall should not allow walls with duplicate name, latitude, and longitude' FAILED
expected valid? to return false, got true
./spec/models/wall_spec.rb:48:
 
Finished in 0.44227 seconds
 
12 examples, 1 failure