Class: Defender::Test::Comment

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks, ActiveModel::Naming
Includes:
Spammable
Defined in:
lib/defender/test/comment.rb

Overview

A fake Comment class to use. No need to require ActiveRecord and set up an actual database. We will use ActiveModel for callbacks though.

Constant Summary

Constants included from Spammable

Spammable::DEFENSIO_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Spammable

included

Instance Attribute Details

#authorObject

Returns the value of attribute author.



17
18
19
# File 'lib/defender/test/comment.rb', line 17

def author
  @author
end

#author_ipObject

Returns the value of attribute author_ip.



17
18
19
# File 'lib/defender/test/comment.rb', line 17

def author_ip
  @author_ip
end

#bodyObject

Returns the value of attribute body.



17
18
19
# File 'lib/defender/test/comment.rb', line 17

def body
  @body
end

#created_atObject

Returns the value of attribute created_at.



17
18
19
# File 'lib/defender/test/comment.rb', line 17

def created_at
  @created_at
end

#defensio_sigObject

Returns the value of attribute defensio_sig.



17
18
19
# File 'lib/defender/test/comment.rb', line 17

def defensio_sig
  @defensio_sig
end

#spamObject

Returns the value of attribute spam.



17
18
19
# File 'lib/defender/test/comment.rb', line 17

def spam
  @spam
end

Instance Method Details

#new_record?Boolean

Returns true if save has been called, false otherwise.

Returns:

  • (Boolean)


20
21
22
# File 'lib/defender/test/comment.rb', line 20

def new_record?
  !(@saved ||= false)
end

#save(with_callbacks = true) ⇒ Object

Run save callback and make new_record? return false.

The with_callbacks method is only for using this as a test interface.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/defender/test/comment.rb', line 27

def save(with_callbacks=true)
  if with_callbacks
    _run_save_callbacks do
      # We're not actually saving anything, just letting Defender know we
      # would be.
      unless defined?(@saved) && @saved
        _run_create_callbacks do
          @saved = true
        end
      end
    end
  else
    @saved = true
  end
end

#update_attribute(name, value) ⇒ Object



43
44
45
46
# File 'lib/defender/test/comment.rb', line 43

def update_attribute(name, value)
  self.send("#{name}=".to_sym, value)
  self.save
end