-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from lionelchauvin/issue-218
fix issue #218: before_validation :update_permalink, on: :create is n…
- Loading branch information
Showing
4 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'spec_helper' | ||
require 'test_components' | ||
|
||
describe 'callbacks', js: true do | ||
before(:all) do | ||
class ActiveRecord::Base | ||
class << self | ||
def public_columns_hash | ||
@public_columns_hash ||= {} | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe 'before_validation :callback_method on create', js: true do | ||
before(:each) do | ||
policy_allows_all | ||
|
||
isomorphic do | ||
class ModelWithCallback < ActiveRecord::Base | ||
|
||
def self.build_tables | ||
connection.create_table(:model_with_callbacks, force: true) do |t| | ||
t.integer :call_count, default: 0 | ||
t.timestamps | ||
end | ||
ActiveRecord::Base.public_columns_hash[name] = columns_hash | ||
end | ||
|
||
before_validation :callback_method, on: :create | ||
|
||
def callback_method | ||
self.call_count += 1 | ||
end | ||
end | ||
end | ||
|
||
ModelWithCallback.build_tables | ||
end | ||
|
||
it "should be called" do | ||
expect_promise do | ||
model = ModelWithCallback.new | ||
model.save.then do | ||
model.call_count | ||
end | ||
end.to eq 1 | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters