Module: Intermodal::RSpec::Macros::Presenters
- Defined in:
- lib/intermodal/rspec/presenters.rb
Instance Method Summary collapse
- #concerned_with_presentation(_model, &blk) ⇒ Object
- #exposes(*fields) ⇒ Object
- #exposes_linked_resources(linked_resources_name, options = {}) ⇒ Object
- #exposes_named_resource ⇒ Object
- #exposes_resource ⇒ Object
- #hides(*fields) ⇒ Object
- #scoped_to(_scope, &blk) ⇒ Object
Instance Method Details
#concerned_with_presentation(_model, &blk) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/intermodal/rspec/presenters.rb', line 23 def concerned_with_presentation(_model, &blk) describe _model do let(:model) { _model } subject { model } context "when concerned with presentation" do instance_eval(&blk) if blk end end end |
#exposes(*fields) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/intermodal/rspec/presenters.rb', line 41 def exposes(*fields) fields.each do |field| it "should present #{field}" do presentation.should contain(field) end end end |
#exposes_linked_resources(linked_resources_name, options = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/intermodal/rspec/presenters.rb', line 70 def exposes_linked_resources(linked_resources_name, = {}) _linked_resource_name, _linking_association = linked_resources_name.to_s.singularize, [:with] context "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) { resource.send(linking_association).send("to_#{linked_resource_ids_name}").to_a } let(:presented_linked_ids) { presentation[linked_resource_ids_name].to_a } exposes "#{_linked_resource_name}_ids" it "should present \"#{_linked_resource_name}_ids\" as a collection of ids" do resource (presented_linked_ids - linked_resource_ids).should be_empty (linked_resource_ids - presented_linked_ids).should be_empty end pending "should only present \"#{_linked_resource_name}_ids\" scoped to account" end end |
#exposes_named_resource ⇒ Object
63 64 65 66 67 68 |
# File 'lib/intermodal/rspec/presenters.rb', line 63 def exposes_named_resource context 'when exposing named resource fields' do exposes_resource exposes 'name' end end |
#exposes_resource ⇒ Object
57 58 59 60 61 |
# File 'lib/intermodal/rspec/presenters.rb', line 57 def exposes_resource context 'when exposing resource fields' do exposes 'id', 'created_at', 'updated_at' end end |
#hides(*fields) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/intermodal/rspec/presenters.rb', line 49 def hides(*fields) fields.each do |field| it "should not present #{field}" do presentation.should_not contain(field) end end end |
#scoped_to(_scope, &blk) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/intermodal/rspec/presenters.rb', line 34 def scoped_to(_scope, &blk) context "when scoped to #{_scope}" do let(:scope) { _scope } instance_eval(&blk) if blk end end |