Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

checkpoint

  • Loading branch information...
commit f702c3e7b5d1cdc7ba612716157bc347b86112b0 1 parent da3952c
@jgoodsen jgoodsen authored
View
4 .bundle/config
@@ -1,2 +1,2 @@
---- {}
-
+---
+BUNDLE_DISABLE_SHARED_GEMS: "1"
View
2  .gitignore
@@ -0,0 +1,2 @@
+
+env_info.txt
View
8 Gemfile.lock
@@ -1,17 +1,10 @@
GEM
remote: http://rubygems.org/
specs:
- activesupport (3.1.3)
- multi_json (~> 1.0)
- gravatar-ultimate (1.0.2)
- sc-core-ext (>= 1.2.0)
jsmin (1.0.1)
- multi_json (1.0.4)
rack (1.3.0)
rack-test (0.6.1)
rack (>= 1.0)
- sc-core-ext (1.2.1)
- activesupport (>= 2.3.5)
sequel (3.31.0)
shotgun (0.9)
rack (>= 1.0)
@@ -34,7 +27,6 @@ PLATFORMS
ruby
DEPENDENCIES
- gravatar-ultimate
sequel
shotgun
sinatra
View
1  application.rb
@@ -1,4 +1,3 @@
-DB = Sequel.sqlite
class MyApp < Sinatra::Base
View
22 models/room.rb
@@ -1,5 +1,10 @@
+require 'sequel'
+DB = Sequel.sqlite
-class Room
+
+class Room < Sequel::Model
+
+ db= DB
def self.make_table
return if DB.table_exists? :rooms
@@ -10,13 +15,16 @@ def self.make_table
end
end
- def self.find(name)
- rooms = DB[:rooms]
- if room = rooms.where(:name => name).first
- return room
- end
- return rooms.insert(:name => name)
+ def self.find_or_create(name)
+ #if rooms.where(:name => name).first
+ self.insert(:name => name)
+ # end
+ return self.where(:name => name).first
end
+ def name
+ self[:name]
+ end
+
make_table
end
View
17 test/room_test.rb
@@ -0,0 +1,17 @@
+require 'test/unit'
+require './models/room'
+
+class RoomTest < Test::Unit::TestCase
+
+ def test_find_or_create_should_create_a_new_room
+ room = Room.find_or_create 'foobar'
+ assert_equal 'foobar', room.name
+ end
+
+ def test_find_or_create_should_retrieve_an_existing_room
+ room = Room.find_or_create 'foobar2'
+ assert_equal room.id, Room.find_or_create('foobar2').id
+ end
+
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.