Skip to content

Instantly share code, notes, and snippets.

@jasiek
Created May 22, 2009 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasiek/116223 to your computer and use it in GitHub Desktop.
Save jasiek/116223 to your computer and use it in GitHub Desktop.
diff --git a/app/models/sample.rb b/app/models/sample.rb
new file mode 100644
index 0000000..7d523a9
--- /dev/null
+++ b/app/models/sample.rb
@@ -0,0 +1,3 @@
+class Sample < ActiveRecord::Base
+ validates_presence_of :value
+end
diff --git a/db/migrate/20090522160717_create_samples.rb b/db/migrate/20090522160717_create_samples.rb
new file mode 100644
index 0000000..3f84e3f
--- /dev/null
+++ b/db/migrate/20090522160717_create_samples.rb
@@ -0,0 +1,12 @@
+class CreateSamples < ActiveRecord::Migration
+ def self.up
+ create_table :samples do |t|
+ t.boolean :value
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :samples
+ end
+end
diff --git a/log/development.log b/log/development.log
deleted file mode 100644
index e69de29..0000000
diff --git a/test/unit/sample_test.rb b/test/unit/sample_test.rb
new file mode 100644
index 0000000..21fbf01
--- /dev/null
+++ b/test/unit/sample_test.rb
@@ -0,0 +1,14 @@
+require 'test_helper'
+
+class SampleTest < ActiveSupport::TestCase
+ def test_validation
+ s = Sample.new
+ assert ! s.valid?
+ s.value = true
+ assert s.valid?
+ s.value = nil
+ assert ! s.valid?
+ s.value = false
+ assert s.valid?
+ end
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment