Skip to content

Commit

Permalink
Validations based on sequential_id
Browse files Browse the repository at this point in the history
Validations based on sequential_id

Generate sequential_id before validation. Tests passing.

Gemfile debug cleanup

Call Create instead of New for validations test
  • Loading branch information
Jakub Stefanski committed Apr 10, 2014
1 parent 6837b21 commit 1f6f90f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,5 @@ test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache
*.gem
.ruby-version
.ruby-gemset
4 changes: 2 additions & 2 deletions lib/sequenced/acts_as_sequenced.rb
Expand Up @@ -34,7 +34,7 @@ def acts_as_sequenced(options = {})
cattr_accessor :sequenced_options
self.sequenced_options = options

before_save :set_sequential_id
before_validation :set_sequential_id
include Sequenced::ActsAsSequenced::InstanceMethods
end
end
Expand All @@ -45,4 +45,4 @@ def set_sequential_id
end
end
end
end
end
6 changes: 6 additions & 0 deletions test/acts_as_sequenced_test.rb
Expand Up @@ -129,4 +129,10 @@ class ActsAsSequencedTest < ActiveSupport::TestCase
assert_equal 1, zombie.sequential_id
assert_equal 2, werewolf.sequential_id
end

test "validation passing" do
obj = Policeman.create
assert_empty obj.errors[:sequential_id]
assert obj.valid?
end
end
5 changes: 5 additions & 0 deletions test/dummy/app/models/policeman.rb
@@ -0,0 +1,5 @@
class Policeman < ActiveRecord::Base
acts_as_sequenced

validates :sequential_id, presence: true
end
9 changes: 9 additions & 0 deletions test/dummy/db/migrate/20140404195334_create_policemen.rb
@@ -0,0 +1,9 @@
class CreatePolicemen < ActiveRecord::Migration
def change
create_table :policemen do |t|
t.integer :sequential_id

t.timestamps
end
end
end

0 comments on commit 1f6f90f

Please sign in to comment.