Have you ever wanted to temporarily disable all validations? Well, ActiveRecord doesn't support this, but that doesn't mean we can't add it. This episode will show you how to open up an existing class and change its behavior.
# test_helper.rb
class Test::Unit::TestCase
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
def disable_validation
ActiveRecord::Base.disable_validation!
yield
ActiveRecord::Base.enable_validation!
end
end
module ValidationDisabler
def self.included(base)
base.class_eval do
extend ClassMethods
alias_method_chain :valid?, :disable_check
end
end
def valid_with_disable_check?
if self.class.validation_disabled?
true
else
valid_without_disable_check?
end
end
module ClassMethods
def disable_validation!
@@disable_validation = true
end
def enable_validation!
@@disable_validation = false
end
def validation_disabled?
@@disable_validation ||= false
end
end
end
class ActiveRecord::Base
include ValidationDisabler
end
分享到:
相关推荐
hacking hacking hacking hacking
Hacking_ A 101 Hacking Guide,hack参考书,值的一看。
Web Hacking 101: How to Make Money Hacking Ethically By 作者: Peter Yaworski Pub Date: 2018 ISBN: n/a Pages: 255 Language: English Format: PDF Size: 10 Mb With a Foreword written by HackerOne Co-...
CAN总线脱敏数据集,包含韩国HCLR实验室所用的Car Hacking和Road两个数据集,包含的攻击模式有Fuzzy/Ddos/Spoofing等。可直接拿来做异常检测。基于该数据集的论文有Song, Hyun Min, Jiyoung Woo, and Huy Kang Kim. ...
比较新的Hacking攻防的概念和技术,具有很好的指导价值。
Title: Python Hacking Essentials Author: Earnest Wish Length: 214 pages Edition: 1 Language: English Publisher: CreateSpace Independent Publishing Platform Publication Date: 2015-04-01 ISBN-10: ...
Learn the basics of ethical hacking and gain insights into the logic, algorithms, and syntax of Python. This book will set you up with a foundation that will help you understand the advanced concepts ...
HackingTeam RCSAndroid sample
hacking Web learning book
Ethical Hacking & Countermeasures
WiFi Hacking for Beginners - Learn Hacking by Hacking WiFi networks (2017) (Azw3)
google hacking
《GoogleHacking技术手册》采纳了详尽的Google语法与工具。在发挥Google的最大搜索效用后,你又将如何反其道,让自己的信息无法被别人搜索到呢?只要你细细品读书中的讲解,顺着作者的逆向思维提示,便可轻松地找到...
WiFi Hacking for Beginners - Learn Hacking by Hacking WiFi networks (2017) (Epub)
Hacking Tutorials
Google Hacking
google hacking 技术手册
这个是Game Console Hacking的相关篇目,由于很难找所以从外国网盘拖了回来。仅供于学习参考用途。
Web Hacking 101 中文版