Module: Intermodal::RSpec::Macros::Acceptors

Defined in:
lib/intermodal/rspec/acceptors.rb

Instance Method Summary collapse

Instance Method Details

#concerned_with_acceptance(_model, &blk) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/intermodal/rspec/acceptors.rb', line 28

def concerned_with_acceptance(_model, &blk)
  describe _model do
    context "when concerned with acceptance" do
      subject { _model }
      instance_eval(&blk) if blk
    end
  end
end

#imposes(*fields) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/intermodal/rspec/acceptors.rb', line 37

def imposes(*fields)
  fields.each do |field|
    it "should accept #{field}" do
      expects_acceptance({ field => random_field_data }, { field.to_sym => random_field_data })
    end
  end
end

#imposes_linked_resources(linked_resources_name, options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/intermodal/rspec/acceptors.rb', line 59

def imposes_linked_resources(linked_resources_name, options = {})
  _linked_resource_name, _linking_association = linked_resources_name.to_s.singularize, options[:with]
  pending "when exposing linked resources, #{_linked_resource_name}" do
    let(:linked_resource_ids_name) { :"#{_linked_resource_name}_ids" }
    let(:linking_association) { :"#{_linking_association}" }
    let(:linked_resource_ids) { subject.send(linking_association).send("to_#{linked_resource_ids_name}") }

    it { should accept "#{_linked_resource_name}_ids" }
    it "should accept \"#{_linked_resource_name}_ids\" as a collection of ids" do
      resource
      (presenter[linked_resource_ids_name].to_a & linked_resource_ids.to_a).should be_empty
    end

    pending "should only accept \"#{_linked_resource_name}_ids\" scoped to account"
  end
end

#imposes_named_resourceObject



53
54
55
56
57
# File 'lib/intermodal/rspec/acceptors.rb', line 53

def imposes_named_resource
  context 'when exposing named resource fields' do
    imposes 'name'
  end
end

#rejects(*fields) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/intermodal/rspec/acceptors.rb', line 45

def rejects(*fields)
  fields.each do |field|
    it "should reject #{field}" do
      expects_rejection({ field => random_field_data }, { field.to_sym => random_field_data })
    end
  end
end