Class: Consent::Rspec::ConsentView

Inherits:
Object
  • Object
show all
Defined in:
lib/consent/rspec/consent_view.rb

Instance Method Summary collapse

Constructor Details

#initialize(view_key, conditions) ⇒ ConsentView

Returns a new instance of ConsentView.



7
8
9
10
# File 'lib/consent/rspec/consent_view.rb', line 7

def initialize(view_key, conditions)
  @conditions = comparable_conditions(conditions) if conditions
  @view_key = view_key
end

Instance Method Details

#descriptionObject



17
18
19
20
# File 'lib/consent/rspec/consent_view.rb', line 17

def description
  message = "consents view #{@view_key}"
  "#{message} with conditions #{@conditions}" if @conditions
end

#failure_messageObject



35
36
37
# File 'lib/consent/rspec/consent_view.rb', line 35

def failure_message
  failure_message_base "to"
end

#failure_message_when_negatedObject



39
40
41
# File 'lib/consent/rspec/consent_view.rb', line 39

def failure_message_when_negated
  failure_message_base "to not"
end

#matches?(subject_key) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# File 'lib/consent/rspec/consent_view.rb', line 27

def matches?(subject_key)
  @subject_key = subject_key
  @target = Consent.find_subjects(subject_key)
                   .filter_map { |subject| subject.views[@view_key]&.conditions(*@context) }
                   .map { |c| comparable_conditions(c) }
  @target.include?(@conditions)
end

#to(*context) ⇒ Object



12
13
14
15
# File 'lib/consent/rspec/consent_view.rb', line 12

def to(*context)
  @context = context
  self
end

#with_conditions(conditions) ⇒ Object



22
23
24
25
# File 'lib/consent/rspec/consent_view.rb', line 22

def with_conditions(conditions)
  @conditions = comparable_conditions(conditions)
  self
end