How to use touch method of ActiveMocker Package

Best Active_mocker_ruby code snippet using ActiveMocker.touch

active_record_compatible_api.rb

Source:active_record_compatible_api.rb Github

copy

Full Screen

...52 record.freeze53 expect { record.name = "Justin" }.to raise_error(RuntimeError, /[c|C]an't modify frozen/)54 end55 end56 describe "#touch" do57 it "touches the updated_at column" do58 record = user_class.create(name: "Dustin")59 record.touch60 expect(record.updated_at).to_not eq(nil)61 end62 end63 end64 describe "::create" do65 let(:create_attributes) { attributes }66 it "id with a strings values" do67 expect(user_class.create(id: "a").id).to eq 068 end69 it "mock will take all attributes that AR takes" do70 user_class.create(create_attributes)71 end72 it "new with block" do73 user = user_class.new do |u|74 u.name = "David"75 u.admin = true76 end77 expect(user.name).to eq "David"78 expect(user.admin).to eq true79 end80 it "create with block" do81 user = user_class.create do |u|82 u.name = "David"83 u.admin = true84 end85 expect(user.name).to eq "David"86 expect(user.admin).to eq true87 end88 context "with timestamps feature" do89 before { ActiveMocker::LoadedMocks.features.enable(:timestamps) }90 after { ActiveMocker::LoadedMocks.features.disable(:timestamps) }91 it "touches updated_at and created_at" do92 record = user_class.create(create_attributes)93 expect(record.updated_at).to_not be_nil94 expect(record.created_at).to_not be_nil95 end96 end97 end98 describe "::update" do99 it "Updates one record" do100 user = user_class.create101 user_class.update(user.id, name: "Samuel")102 expect(user_class.find(user.id).name).to eq "Samuel"103 end104 it "Updates multiple records" do105 users = [user_class.create!(email: "1"),...

Full Screen

Full Screen

base.rb

Source:base.rb Github

copy

Full Screen

...37 attributes.collect { |attr| create(attr, &block) }38 else39 record = new(id: attributes.delete(:id) || attributes.delete("id"))40 record.save41 record.touch(:created_at, :created_on) if ActiveMocker::LoadedMocks.features[:timestamps]42 record.assign_attributes(attributes, &block)43 record._create_caller_locations = caller_locations44 record45 end46 end47 alias create! create48 def records49 @records ||= Records.new50 end51 private :records52 delegate :insert, :exists?, :to_a, to: :records53 delegate :first, :last, to: :all54 # Delete an object (or multiple objects) that has the given id.55 #56 # This essentially finds the object (or multiple objects) with the given id and then calls delete on it.57 #58 # ==== Parameters59 #60 # * +id+ - Can be either an Integer or an Array of Integers.61 #62 # ==== Examples63 #64 # # Destroy a single object65 # TodoMock.delete(1)66 #67 # # Destroy multiple objects68 # todos = [1,2,3]69 # TodoMock.delete(todos)70 def delete(id)71 if id.is_a?(Array)72 id.map { |one_id| delete(one_id) }73 else74 find(id).delete75 end76 end77 alias destroy delete78 # Deletes the records matching +conditions+.79 #80 # Post.where(person_id: 5).where(category: ['Something', 'Else']).delete_all81 def delete_all(conditions = nil)82 return records.reset if conditions.nil?83 super84 end85 alias destroy_all delete_all86 # @api private87 def from_limit?88 false89 end90 def abstract_class?91 true92 end93 def build_type(type)94 @@built_types ||= {}95 @@built_types[type] ||= Virtus::Attribute.build(type)96 end97 def classes(klass, fail_hard=false)98 ActiveMocker::LoadedMocks.find(klass).tap do |found_class|99 raise MockNotLoaded, "The ActiveMocker version of #{klass} is not required." if fail_hard && !found_class100 found_class101 end102 end103 # @param [Array<ActiveMocker::Base>] collection, an array of mock instances104 # @return [ScopeRelation] for the given mock so that it will include any scoped methods105 def __new_relation__(collection)106 ScopeRelation.new(collection)107 end108 private :classes, :build_type, :__new_relation__109 public110 # @deprecated111 def clear_mock112 delete_all113 end114 def _find_associations_by_class(klass_name)115 associations_by_class[klass_name.to_s]116 end117 # Not fully Implemented118 # Returns association reflections names with nil values119 #120 # #=> { "user" => nil, "order" => nil }121 def reflections122 associations.each_with_object({}) { |(k, _), h| h[k.to_s] = nil }123 end124 def __active_record_build_version__125 @active_record_build_version126 end127 private128 def mock_build_version(version, active_record: nil)129 @active_record_build_version = Gem::Version.create(active_record)130 if __active_record_build_version__ >= Gem::Version.create("5.1")131 require "active_mocker/mock/compatibility/base/ar51"132 extend AR51133 end134 if __active_record_build_version__ >= Gem::Version.create("5.2")135 require "active_mocker/mock/compatibility/queries/ar52"136 Queries.prepend(Queries::AR52)137 end138 raise UpdateMocksError.new(name, version, ActiveMocker::Mock::VERSION) if version != ActiveMocker::Mock::VERSION139 end140 end141 # @deprecated142 def call_mock_method(method:, caller:, arguments: [])143 self.class.send(:is_implemented, method, '#', caller)144 end145 private :call_mock_method146 def classes(klass, fail_hard = false)147 self.class.send(:classes, klass, fail_hard)148 end149 private :classes150 attr_reader :associations, :types, :attributes151 # @private152 attr_accessor :_create_caller_locations153 # New objects can be instantiated as either empty (pass no construction parameter) or pre-set with154 # attributes.155 #156 # ==== Example:157 # # Instantiates a single new object158 # UserMock.new(first_name: 'Jamie')159 def initialize(attributes = {}, &block)160 if self.class.abstract_class?161 raise NotImplementedError, "#{self.class.name} is an abstract class and cannot be instantiated."162 end163 setup_instance_variables164 assign_attributes(attributes, &block)165 end166 def setup_instance_variables167 @types = self.class.send(:types)168 @attributes = self.class.send(:attributes).deep_dup169 @associations = self.class.send(:associations).dup170 end171 private :setup_instance_variables172 def update(attributes = {})173 assign_attributes(attributes)174 save175 end176 # Allows you to set all the attributes by passing in a hash of attributes with177 # keys matching the attribute names (which again matches the column names).178 #179 # cat = Cat.new(name: "Gorby", status: "yawning")180 # cat.attributes # => { "name" => "Gorby", "status" => "yawning", "created_at" => nil, "updated_at" => nil}181 # cat.assign_attributes(status: "sleeping")182 # cat.attributes # => { "name" => "Gorby", "status" => "sleeping", "created_at" => nil, "updated_at" => nil }183 #184 # Aliased to <tt>attributes=</tt>.185 def assign_attributes(new_attributes)186 yield self if block_given?187 unless new_attributes.respond_to?(:stringify_keys)188 raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."189 end190 return nil if new_attributes.blank?191 attributes = new_attributes.stringify_keys192 attributes.each do |k, v|193 _assign_attribute(k, v)194 end195 end196 alias attributes= assign_attributes197 # @api private198 def _assign_attribute(k, v)199 public_send("#{k}=", v)200 rescue NoMethodError201 if respond_to?("#{k}=")202 raise203 else204 raise UnknownAttributeError.new(self, k)205 end206 end207 def save(*_args)208 self.class.send(:insert, self) unless self.class.exists?(self)209 touch if ActiveMocker::LoadedMocks.features[:timestamps]210 true211 end212 alias save! save213 def touch(*names)214 raise ActiveMocker::Error, "cannot touch on a new record object" unless persisted?215 attributes = [:updated_at, :update_on]216 attributes.concat(names)217 current_time = Time.now.utc218 attributes.each do |column|219 column = column.to_s220 write_attribute(column, current_time) if self.class.attribute_names.include?(column)221 end222 true223 end224 def records225 self.class.send(:records)226 end227 private :records228 def delete...

Full Screen

Full Screen

features_spec.rb

Source:features_spec.rb Github

copy

Full Screen

...33 describe "timestamps" do34 context "when enabled" do35 before(:all) { active_mocker.features.enable(:timestamps) }36 after(:all) { active_mocker.features.disable(:timestamps) }37 it "touches updated_at and created_at" do38 record = User.create39 expect(record.updated_at).to_not be_nil40 expect(record.created_at).to_not be_nil41 end42 context "when touch is called" do43 it "increments the updated at" do44 record = User.create45 first_time = record.updated_at46 record.touch47 expect(record.updated_at > first_time).to eq(true)48 end49 end50 end51 context "when disabled" do52 it "touches updated_at and created_at" do53 record = User.create54 expect(record.updated_at).to be_nil55 expect(record.created_at).to be_nil56 end57 end58 end59 describe "stub_active_record_exceptions", active_mocker: true do60 it "can load these exceptions" do61 ActiveRecord::RecordNotFound62 ActiveRecord::RecordNotUnique63 ActiveRecord::UnknownAttributeError64 end65 end66end...

Full Screen

Full Screen

touch

Using AI Code Generation

copy

Full Screen

1 created_with('1.8.7')2 @attributes ||= HashWithIndifferentAccess.new({"id"=>nil, "name"=>nil, "created_at"=>nil, "updated_at"=>nil, "deleted_at"=>nil}).merge(super)3 @types ||= ActiveMocker::Mock::HashProcess.new({ id: Fixnum, name: String, created_at: DateTime, updated_at: DateTime, deleted_at: DateTime }, method(:build_type)).merge(super)4 @associations ||= {:has_many=>[:things]}.merge(super)5 @associations_by_class ||= {"Thing"=>{:belongs_to=>[:touch]}}.merge(super)6 @mock_foreign_keys ||= {"thing"=>{:column=>"touch_id", :class_name=>"Thing", :primary_key=>"id", :foreign_key=>"touch_id"}}.merge(super)7 @mock_indexes ||= {"index_touches_on_name"=>{:unique=>false, :columns=>["name"], :name=>"index_touches_on_name", :with=>nil}}.merge(super)8 ActiveRecord::Base.send(:remove_const, "Touch") if ActiveRecord::Base.const_defined?("Touch")9 created_with('1.8.7')10 @attributes ||= HashWithIndifferentAccess.new({"id"=>nil, "name"=>nil, "touch_id"=>nil, "created_at"=>nil, "updated_at"=>nil, "deleted_at"=>nil}).merge(super

Full Screen

Full Screen

touch

Using AI Code Generation

copy

Full Screen

1 created_with('1.8.7')2 @attributes ||= HashWithIndifferentAccess.new({"id"=>nil, "name"=>nil, "created_at"=>nil, "updated_at"=>nil}).merge(super)3 @types ||= ActiveMocker::Mock::HashProcess.new({ id: Fixnum, name: String, created_at: DateTime, updated_at: DateTime }, method(:build_type)).merge(super)4 @associations ||= {:posts=>nil, :comments=>nil}.merge(super)5 @associations_by_class ||= {"Post"=>{:has_many=>[:posts]}, "Comment"=>{:has_many=>[:comments]}}.merge(super)6 def human_attribute_name(attr, options = {})7 def mock_foreign_key(type)8 mock_foreign_key("Touch")9 def mock_foreign_type(type)10 mock_foreign_type("Touch")11 def mock_belongs_to(type)

Full Screen

Full Screen

touch

Using AI Code Generation

copy

Full Screen

1 created_with('1.9.3')2 @attributes ||= HashWithIndifferentAccess.new({"id"=>nil, "name"=>nil, "created_at"=>nil, "updated_at"=>nil}).merge(super)3 @types ||= ActiveMocker::Mock::HashProcess.new({ id: Fixnum, name: String, created_at: DateTime, updated_at: DateTime }, method(:build_type)).merge(super)4 @associations ||= {:has_many=>[:screws], :belongs_to=>[:screwdriver]}.merge(super)5 @associations_by_class ||= {"Screw"=>{:has_many=>[:touch]}, "Screwdriver"=>{:belongs_to=>[:touch]}}.merge(super)6 def enum(*args); end7 module Scopes; end8 def initialize(attributes = {}, options = {})9 super(attributes, options)10 created_with('1.9.3')11 @attributes ||= HashWithIndifferentAccess.new({"id"=>nil, "touch_id"=>nil, "created_at"=>nil, "updated_at"=>nil}).merge(super)

Full Screen

Full Screen

touch

Using AI Code Generation

copy

Full Screen

1 created_with('1.7.2')2 @attributes ||= HashWithIndifferentAccess.new({"id"=>nil, "name"=>nil, "created_at"=>nil, "updated_at"=>nil}).merge(super)3 @types ||= ActiveMocker::Mock::HashProcess.new({ id: Fixnum, name: String, created_at: DateTime, updated_at: DateTime }, method(:build_type)).merge(super)4 @associations ||= {:touchables=>nil}.merge(super)5 @associations_by_class ||= {"Touchable"=>{:has_many=>[:touchables]}}.merge(super)6 def enum_for(method = nil)7 y.yield new(id: 1, name: "name_1", created_at: "2014-03-27 09:04:58", updated_at: "2014-03-27 09:04:58")8 y.yield new(id: 2, name: "name_2", created_at: "2014-03-27 09:04:58", updated_at: "2014-03-27 09:04:58")9 y.yield new(id: 3, name: "name_3", created_at: "2014-03-27 09:04:58", updated_at: "2014-03-27 09:04:58")10 super(method)11 Touchable.all.select {|a| a.touch_id == id}12 def touchables=(value)13 value.each {|v| v.touch_id = id }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Active_mocker_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful