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



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

def failure_message
  failure_message_base 'to'
end

#failure_message_when_negatedObject



42
43
44
# File 'lib/consent/rspec/consent_view.rb', line 42

def failure_message_when_negated
  failure_message_base 'to not'
end

#matches?(subject_key) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(subject_key)
  @subject_key = subject_key
  @target = Consent.find_subjects(subject_key)
                   .map do |subject|
                     subject.views[@view_key]&.conditions(*@context)
                   end
                   .compact
                   .map(&method(:comparable_conditions))
  @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