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

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

- (Object) author

Returns the value of attribute author



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

def author
  @author
end

- (Object) author_ip

Returns the value of attribute author_ip



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

def author_ip
  @author_ip
end

- (Object) body

Returns the value of attribute body



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

def body
  @body
end

- (Object) created_at

Returns the value of attribute created_at



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

def created_at
  @created_at
end

- (Object) defensio_sig

Returns the value of attribute defensio_sig



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

def defensio_sig
  @defensio_sig
end

- (Object) spam

Returns the value of attribute spam



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

def spam
  @spam
end

Instance Method Details

- (Boolean) new_record?

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

- (Object) save(with_callbacks = true)

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

- (Object) update_attribute(name, value)



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