spec/apitizer/routing/path_spec.rb in apitizer-0.0.1 vs spec/apitizer/routing/path_spec.rb in apitizer-0.0.2

- old
+ new

@@ -1,102 +1,22 @@ require 'spec_helper' -describe Apitizer::Routing::Path do - extend ResourceHelper - include FactoryHelper +RSpec.describe Apitizer::Routing::Path do + let(:subject_class) { Apitizer::Routing::Path } - describe '#<<' do + describe '#advance' do it 'builds up addresses' do - [ :articles, 'xxx', :sections, 'yyy' ].each { |step| subject << step } - expect(subject.address).to eq('articles/xxx/sections/yyy') + subject.advance('articles', node: double) + subject.advance('xxx', node: double) + expect(subject.address).to eq('articles/xxx') end end - describe '#advance' do - it 'keeps track of destinations' do - nodes = [ double('articles'), double('sections') ] - nodes.each { |node| subject.advance(node) } - expect(subject.node).to be(nodes.last) - end - end - - an_adequate_guard = Proc.new do |only_actions = restful_actions| - (restful_collection_actions & only_actions).each do |action| - it "is true for #{ action } collection action" do - path = root.trace(steps) - expect(path.permitted?(action)).to be_true - end - end - - (restful_member_actions & only_actions).each do |action| - it "is true for #{ action } member actions" do - path = root.trace([ *steps, 'xxx' ]) - expect(path.permitted?(action)).to be_true - end - end - - (restful_collection_actions - only_actions).each do |action| - it "is false for #{ action } collection action" do - path = root.trace(steps) - expect(path.permitted?(action)).to be_false - end - end - - (restful_member_actions - only_actions).each do |action| - it "is false for #{ action } member actions" do - path = root.trace([ *steps, 'xxx' ]) - expect(path.permitted?(action)).to be_false - end - end - - restful_member_actions.each do |action| - it "is false for #{ action } actions to collections" do - path = root.trace(steps) - expect(path.permitted?(action)).to be_false - end - end - - restful_collection_actions.each do |action| - it "is false for #{ action } actions to members" do - path = root.trace([ *steps, 'xxx' ]) - expect(path.permitted?(action)).to be_false - end - end - end - - describe '#permitted?' do - context 'when working with plain collections' do - let(:root) { create_tree(:articles) } - let(:steps) { [ :articles ] } - - instance_exec(&an_adequate_guard) - end - - context 'when working with nested collections' do - let(:root) { create_tree(:articles, :sections) } - let(:steps) { [ :articles, 'yyy', :sections ] } - - instance_exec(&an_adequate_guard) - end - - context 'when working with collections restricted to index and show' do - let(:root) { create_tree([ :articles, [ :index, :show ] ]) } - let(:steps) { [ :articles ] } - - instance_exec([ :index, :show ], &an_adequate_guard) - end - - restful_member_actions.each do |action| - it "is true for custom #{ action } operations on members" do - root = create_tree(:articles, shred: action) - path = root.trace([ :articles, 'xxx', :shred ]) - expect(path.permitted?(action)).to be_true - end - - it "is true for custom #{ action } operations with variable names" do - root = create_tree(:articles, ':paragraph' => action) - path = root.trace([ :articles, 'xxx', 'zzz' ]) - expect(path.permitted?(action)).to be_true - end + describe '#clone' do + it 'properly does its job' do + subject.advance('articles', node: double) + another = subject.clone + another.advance('xxx', node: double) + expect(subject.address).to eq('articles') end end end