aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
authorLuc Donnet2018-02-19 11:04:29 +0100
committerLuc Donnet2018-02-19 11:04:29 +0100
commit7b17deff51545358009cb417cbb9d796565e7540 (patch)
treea43a5586ad39d838dd607e600dbc15ff18a58ab3 /spec/lib
parent89428163fc93a7e09ebb0ca47939f8558afeb5eb (diff)
parent5f6008d165df4499319a2121a71842657d6ac3c9 (diff)
downloadchouette-core-7b17deff51545358009cb417cbb9d796565e7540.tar.bz2
Merge branch 'master' into 0000-docker
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/af83/decorator/decorator_link_spec.rb79
-rw-r--r--spec/lib/af83/decorator/decorator_spec.rb824
-rw-r--r--spec/lib/range_ext_spec.rb51
-rw-r--r--spec/lib/stif/netex_file/frame_spec.rb13
-rw-r--r--spec/lib/stif/netex_file_spec.rb4
-rw-r--r--spec/lib/stif/permission_translator_spec.rb16
6 files changed, 985 insertions, 2 deletions
diff --git a/spec/lib/af83/decorator/decorator_link_spec.rb b/spec/lib/af83/decorator/decorator_link_spec.rb
new file mode 100644
index 000000000..0b2939421
--- /dev/null
+++ b/spec/lib/af83/decorator/decorator_link_spec.rb
@@ -0,0 +1,79 @@
+RSpec.describe AF83::Decorator::Link, type: :decorator do
+ describe "#complete?" do
+ context "on a imcomplete link" do
+ it "should be false" do
+ expect(AF83::Decorator::Link.new.complete?).to be_falsy
+ expect(AF83::Decorator::Link.new(content: "foo").complete?).to be_falsy
+ expect(AF83::Decorator::Link.new(href: "foo").complete?).to be_falsy
+ end
+ end
+
+ context "on a complete link" do
+ it "should be true" do
+ expect(AF83::Decorator::Link.new(href: "foo", content: "foo").complete?).to be_truthy
+ end
+ end
+ end
+
+ describe "#class" do
+ let(:link){
+ AF83::Decorator::Link.new(href: "foo", content: "foo", class: "initial_class")
+ }
+
+ it "should override exisiting class" do
+ expect(link.html_options[:class]).to eq "initial_class"
+ link.class "new_class"
+ expect(link.html_options[:class]).to eq "new_class"
+ link.class = "another_class"
+ expect(link.html_options[:class]).to eq "another_class"
+ link.class = %w(foo bar)
+ expect(link.html_options[:class]).to eq "foo bar"
+ end
+ end
+
+ describe "#add_class" do
+ let(:link){
+ AF83::Decorator::Link.new(href: "foo", content: "foo", class: "initial_class")
+ }
+
+ it "should add to exisiting class" do
+ expect(link.html_options[:class]).to eq "initial_class"
+ link.add_class "new_class"
+ expect(link.html_options[:class]).to eq "initial_class new_class"
+ link.add_class "another_class"
+ expect(link.html_options[:class]).to eq "initial_class new_class another_class"
+ link.add_class %w(foo bar)
+ expect(link.html_options[:class]).to eq "initial_class new_class another_class foo bar"
+ end
+ end
+
+ describe "#type" do
+
+ let(:link){
+ AF83::Decorator::Link.new(href: "foo", content: "foo")
+ }
+
+ let(:context){
+ Class.new do
+ def h
+ Class.new do
+ def link_to *args
+ HTMLElement.new(:a, 'foo', {}).to_html
+ end
+ end.new
+ end
+ end.new
+ }
+
+ it "should allow for buttons" do
+ link.type = :button
+ expect(link.to_html).to match /\<button.*\<\/button\>/
+ end
+
+ it "should fallback to <a>" do
+ link.type = :spaghetti
+ link.bind_to_context context, :show
+ expect(link.to_html).to match /\<a.*\<\/a\>/
+ end
+ end
+end
diff --git a/spec/lib/af83/decorator/decorator_spec.rb b/spec/lib/af83/decorator/decorator_spec.rb
new file mode 100644
index 000000000..61a849b9d
--- /dev/null
+++ b/spec/lib/af83/decorator/decorator_spec.rb
@@ -0,0 +1,824 @@
+RSpec.describe AF83::Decorator, type: :decorator do
+ describe(:parse_options) do
+ let(:options){
+ {primary: true, secondary: %i(index show), policy: :blublu, weight: 12}
+ }
+ let(:link_options){
+ {foo: :foo, bar: :bar}
+ }
+ let(:args){ options.dup.update(link_options.dup) }
+ it "should separate options from link_options" do
+ _options, _link_options = AF83::Decorator.instance_decorator.send :parse_options, args
+ expect(_options).to eq({weight: 12})
+ link_options.each do |k, v|
+ expect(_link_options[k]).to eq v
+ end
+ expect(_link_options[:_groups][:primary]).to eq true
+ expect(_link_options[:_groups][:secondary]).to eq %i(index show)
+ expect(_link_options[:_policy]).to eq :blublu
+ end
+ end
+
+ link_should_match_options = ->(link, options){
+ options.each do |k, v|
+ expect(link.send(k)).to eq v
+ end
+ }
+
+ context "as an collection decorator" do
+ let(:link_options) do
+ {
+ href: "/foo/bar",
+ content: "Blublu"
+ }
+ end
+
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.action_link link_options
+ klass
+ end
+
+ let(:decorated) do
+ 3.times { create :line }
+ decorator.decorate(Chouette::Line.all)
+ end
+
+ it "should return the links" do
+ links = decorated.action_links
+ instance_exec links.first, link_options, &link_should_match_options
+ end
+ end
+
+ context "as an instance decorator" do
+ describe("with the actual decorator") do
+ before(:each) do
+ Draper::HelperProxy.any_instance.stub(:policy){
+ klass = Class.new do
+ def method_missing *args
+ true
+ end
+ end.new
+ }
+ end
+
+ let(:decorated) do
+ line = create :line
+ line.decorate(context: {line_referential: line.line_referential})
+ end
+
+ it "should return the links" do
+ expect{ decorated.action_links }.to_not raise_error
+ end
+ end
+
+ describe(:action_links) do
+ let(:decorated) do
+ obj = create :line
+ decorator.decorate(obj)
+ end
+
+ context "without links" do
+ let(:decorator) do
+ Class.new(AF83::Decorator)
+ end
+
+ it "should return no link" do
+ links = decorated.action_links
+ expect(links.size).to eq 0
+ end
+ end
+
+ context "with a single link" do
+ let(:link_options) do
+ {
+ href: "/foo/bar",
+ content: "Blublu"
+ }
+ end
+
+ context "incompletetly defined" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link href: "bar"
+ end
+ klass
+ end
+
+ it "should raise an error" do
+ expect{decorator}.to raise_error(AF83::Decorator::IncompleteLinkDefinition)
+ end
+ end
+
+ context "defined inline" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options
+ end
+ klass
+ end
+
+ it "should return the defined link" do
+ links = decorated.action_links
+ expect(links.size).to eq 1
+ instance_exec links.first, link_options, &link_should_match_options
+ end
+ end
+
+ context "defined in a block" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link do |l|
+ l.href link_options[:href]
+ l.content link_options[:content]
+ end
+ end
+ klass
+ end
+
+ it "should return the defined link" do
+ links = decorated.action_links
+ expect(links.size).to eq 1
+ instance_exec links.first, link_options, &link_should_match_options
+ end
+ end
+
+ context "with proc attributes" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link do |l|
+ l.href { context[:href] }
+ l.content "Blublu"
+ end
+ end
+ klass
+ end
+
+ let(:decorated) do
+ obj = create :line
+ decorator.decorate(obj, context: {href: link_options[:href]})
+ end
+
+ it "should return the defined link" do
+ links = decorated.action_links
+ expect(links.size).to eq 1
+ expect(links.first.href).to eq link_options[:href]
+ end
+ end
+
+ context "with a method attributes" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link do |l|
+ l.href "/foo/bar"
+ l.content "Blublu"
+ l.method :put
+ end
+ end
+ klass
+ end
+
+ let(:decorated) do
+ obj = create :line
+ decorator.decorate(obj, context: {href: link_options[:href]})
+ end
+
+ it "should return the defined method" do
+ links = decorated.action_links
+ expect(links.size).to eq 1
+ expect(links.first.method).to eq :put
+ end
+ end
+ end
+
+ context "with 2 links" do
+ let(:link_options_1) do
+ {
+ href: "/foo/bar",
+ content: "Blublu"
+ }
+ end
+
+ let(:link_options_2) do
+ {
+ href: "/foo/bar/baz",
+ content: "Foo"
+ }
+ end
+
+ context "without weight" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options_1
+ instance_decorator.action_link link_options_2
+ end
+ klass
+ end
+
+ it "should return links in the sequence they were defined" do
+ links = decorated.action_links
+ expect(links.size).to eq 2
+ instance_exec links.first, link_options_1, &link_should_match_options
+ instance_exec links.last, link_options_2, &link_should_match_options
+ end
+ end
+
+ context "with weight" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options_1.update(weight: 10)
+ instance_decorator.action_link link_options_2
+ end
+ klass
+ end
+
+ it "should return links in the correct sequence" do
+ links = decorated.action_links
+ expect(links.size).to eq 2
+ instance_exec links.first, link_options_2, &link_should_match_options
+ instance_exec links.last, link_options_1, &link_should_match_options
+ end
+ end
+
+ context "scoped by action" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options_1.update(action: :index)
+ instance_decorator.action_link link_options_2
+ end
+ klass
+ end
+
+ it "should only return links defined for the given action" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 1
+ instance_exec links.first, link_options_2, &link_should_match_options
+ end
+ end
+
+ context "with a policy" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link href: "foo", content: "foo", policy: :edit
+ end
+ klass
+ end
+
+ context "when the policy is not met" do
+ before(:each) do
+ Draper::HelperProxy.any_instance.stub(:policy){
+ klass = Class.new do
+ def edit?
+ false
+ end
+ end.new
+ }
+ end
+
+ it "should not return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 0
+ end
+ end
+
+ context "when the policy is met" do
+ before(:each) do
+ Draper::HelperProxy.any_instance.stub(:policy){
+ klass = Class.new do
+ def edit?
+ true
+ end
+ end.new
+ }
+ end
+
+ it "should not return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 1
+ end
+ end
+ end
+
+ context "with a feature" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link href: "foo", content: "foo", feature: :foo
+ end
+ klass
+ end
+
+ context "when the feature is not present" do
+ before(:each) do
+ Draper::HelperProxy.any_instance.stub(:has_feature?){false}
+ end
+
+ it "should not return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 0
+ end
+ end
+
+ context "when the feature is present" do
+ before(:each) do
+ Draper::HelperProxy.any_instance.stub(:has_feature?){true}
+ end
+
+ it "should not return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 1
+ end
+ end
+ end
+
+ context "with a condition" do
+ context "set with 'with_condition'" do
+ context "as a value" do
+ context "when the condition is true" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.with_condition true do
+ action_link href: "foo", content: "foo"
+ end
+ end
+ klass
+ end
+
+ it "should return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 1
+ end
+ end
+
+ context "when the condition is false" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.with_condition false do
+ action_link href: "foo", content: "foo"
+ end
+ end
+ klass
+ end
+
+ it "should not return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 0
+ end
+ end
+ end
+
+ context "as a Proc" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.with_condition ->{context[:show_link]} do
+ action_link href: "foo", content: "foo"
+ end
+ end
+ klass
+ end
+
+ context "when the condition is true" do
+ let(:decorated) do
+ obj = create :line
+ decorator.decorate(obj, context: {show_link: true})
+ end
+
+ it "should return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 1
+ end
+ end
+
+ context "when the condition is false" do
+ let(:decorated) do
+ obj = create :line
+ decorator.decorate(obj, context: {show_link: false})
+ end
+
+ it "should not return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 0
+ end
+ end
+ end
+ end
+
+ context "set inline" do
+ context "as a value" do
+ context "when the condition is true" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options_1.update(if: true)
+ end
+ klass
+ end
+
+ it "should return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 1
+ end
+ end
+
+ context "when the condition is false" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options_1.update(if: false)
+ end
+ klass
+ end
+
+ it "should not return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 0
+ end
+ end
+ end
+
+ context "as a Proc" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options_1.update(if: ->{context[:show_link]})
+ end
+ klass
+ end
+
+ context "when the condition is true" do
+ let(:decorated) do
+ obj = create :line
+ decorator.decorate(obj, context: {show_link: true})
+ end
+
+ it "should return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 1
+ end
+ end
+
+ context "when the condition is false" do
+ let(:decorated) do
+ obj = create :line
+ decorator.decorate(obj, context: {show_link: false})
+ end
+
+ it "should not return the link" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 0
+ end
+ end
+ end
+ end
+ end
+
+ context "scoped by action" do
+ context "with a single action" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options_1.update(action: :index)
+ instance_decorator.action_link link_options_2
+ end
+ klass
+ end
+
+ it "should only return links defined for the given action" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 1
+ instance_exec links.first, link_options_2, &link_should_match_options
+ end
+ end
+
+ context "with several actions" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options_1.update(actions: %i(index edit))
+ instance_decorator.action_link link_options_2.update(actions: %i(show edit))
+ end
+ klass
+ end
+
+ it "should only return links defined for the given action" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 1
+ instance_exec links.first, link_options_2, &link_should_match_options
+ end
+ end
+
+ context "with the keyword 'on'" do
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options_1.update(on: %i(index edit))
+ instance_decorator.action_link link_options_2.update(on: :show)
+ end
+ klass
+ end
+
+ it "should only return links defined for the given action" do
+ links = decorated.action_links(:show)
+ expect(links.size).to eq 1
+ instance_exec links.first, link_options_2, &link_should_match_options
+ end
+ end
+ end
+ end
+ end
+
+ describe '#primary' do
+ let(:decorator) do
+ Class.new(AF83::Decorator)
+ end
+
+ let(:decorated) do
+ obj = create :line
+ decorator.decorate(obj)
+ end
+
+ it "should return a new object everytime" do
+ actions = decorated.action_links
+ primary = actions.primary
+ expect(actions.options[:groups]).to be_nil
+ expect(primary.options[:groups]).to_not be_nil
+ end
+ end
+
+ describe(:primary_links) do
+ let(:decorated) do
+ obj = create :line
+ decorator.decorate(obj)
+ end
+
+ context "without links" do
+ let(:decorator) do
+ Class.new(AF83::Decorator)
+ end
+
+ it "should return no link" do
+ links = decorated.action_links
+ expect(links.size).to eq 0
+ end
+ end
+
+ context "with a single link" do
+ let(:link_options) do
+ {
+ href: "/foo/bar/baz",
+ content: "Blublu",
+ primary: primary
+ }
+ end
+
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options
+ end
+ klass
+ end
+
+ context "always primary" do
+ let(:primary){ true }
+
+ it "should return the link" do
+ links = decorated.primary_links(:show)
+ expect(links.size).to eq 1
+ end
+ end
+
+ context "primary on this action" do
+ let(:primary){ :show }
+
+ it "should return the link" do
+ links = decorated.primary_links(:show)
+ expect(links.size).to eq 1
+ end
+ end
+
+ context "primary on this action among others" do
+ let(:primary){ %i(show edit) }
+
+ it "should return the link" do
+ links = decorated.action_links(:show, group: :primary)
+ expect(links.size).to eq 1
+ end
+ end
+
+ context "primary on other actions" do
+ let(:primary){ %i(index edit) }
+
+ it "should not return the link" do
+ links = decorated.action_links(:show, group: :primary)
+ expect(links.size).to eq 0
+ end
+ end
+
+ context "primary on another action" do
+ let(:primary){ :index }
+
+ it "should not return the link" do
+ links = decorated.primary_links(:show)
+ expect(links.size).to eq 0
+ end
+ end
+
+ context "never primary" do
+ let(:primary){ nil }
+
+ it "should not return the link" do
+ links = decorated.primary_links(:show)
+ expect(links.size).to eq 0
+ end
+ end
+ end
+ end
+
+ describe("in a group") do
+ let(:decorated) do
+ obj = create :line
+ decorator.decorate(obj)
+ end
+
+ context "without links" do
+ let(:decorator) do
+ Class.new(AF83::Decorator)
+ end
+
+ it "should return no link" do
+ links = decorated.action_links
+ expect(links.size).to eq 0
+ end
+ end
+
+
+ context "with a single link" do
+ let(:link_options) do
+ {
+ href: "/foo/bar/baz",
+ content: "Blublu",
+ groups: {foo: group}
+ }
+ end
+
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options
+ end
+ klass
+ end
+
+ context "always in" do
+ let(:group){ true }
+
+ it "should return the link" do
+ links = decorated.action_links(:show, group: :foo)
+ expect(links.size).to eq 1
+ end
+
+ context "define with group" do
+ let(:link_options) do
+ {
+ href: "/foo/bar/baz",
+ content: "Blublu",
+ group: :foo
+ }
+ end
+
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options
+ end
+ klass
+ end
+
+ it "should return the link" do
+ links = decorated.action_links(:show, group: :foo)
+ expect(links.size).to eq 1
+ end
+
+ it "should not return the link" do
+ links = decorated.action_links(:show, group: :bar)
+ expect(links.size).to eq 0
+ end
+ end
+ end
+
+ context "primary on this action" do
+ let(:group){ :show }
+
+ it "should return the link" do
+ links = decorated.action_links(:show, group: :foo)
+ expect(links.size).to eq 1
+ end
+ end
+
+ context "in this action among others" do
+ let(:group){ %i(show edit) }
+
+ it "should return the link" do
+ links = decorated.action_links(:show, group: :foo)
+ expect(links.size).to eq 1
+ end
+ end
+
+ context "in other actions" do
+ let(:group){ %i(index edit) }
+
+ it "should not return the link" do
+ links = decorated.action_links(:show, group: :foo)
+ expect(links.size).to eq 0
+ end
+ end
+
+ context "in another action" do
+ let(:group){ :index }
+
+ it "should not return the link" do
+ links = decorated.action_links(:show, group: :foo)
+ expect(links.size).to eq 0
+ end
+ end
+
+ context "never" do
+ let(:group){ nil }
+
+ it "should not return the link" do
+ links = decorated.action_links(:show, group: :foo)
+ expect(links.size).to eq 0
+ end
+ end
+ end
+
+ describe(:grouped_by) do
+ let(:link_options_1) do
+ {
+ href: "/foo/bar",
+ content: "Blublu",
+ primary: true
+ }
+ end
+
+ let(:link_options_2) do
+ {
+ href: "/foo/bar/baz",
+ content: "Foo",
+ groups: {secondary: :show}
+ }
+ end
+
+ let(:link_options_3) do
+ {
+ href: "/foo/bar/baz/bat",
+ content: "Foo",
+ groups: {foo: :show}
+ }
+ end
+
+ let(:link_options_4) do
+ {
+ href: "/footer",
+ content: "Foo",
+ footer: true
+ }
+ end
+
+ let(:decorator) do
+ klass = Class.new(AF83::Decorator)
+ klass.with_instance_decorator do |instance_decorator|
+ instance_decorator.action_link link_options_1
+ instance_decorator.action_link link_options_2
+ instance_decorator.action_link link_options_3
+ instance_decorator.action_link link_options_4
+ end
+ klass
+ end
+
+ it "should return links in their groups" do
+ links = decorated.action_links(:show).grouped_by(:primary, :secondary, :blu, :footer)
+ expect(links.size).to eq 5
+ instance_exec links[:primary].first, link_options_1, &link_should_match_options
+ instance_exec links[:secondary].first, link_options_2, &link_should_match_options
+ expect(links[:blu].size).to eq 0
+ instance_exec links[:other].first, link_options_3, &link_should_match_options
+ instance_exec links[:footer].first, link_options_4, &link_should_match_options
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/range_ext_spec.rb b/spec/lib/range_ext_spec.rb
index 9c44608b9..eee488c91 100644
--- a/spec/lib/range_ext_spec.rb
+++ b/spec/lib/range_ext_spec.rb
@@ -1,6 +1,6 @@
require 'range_ext'
RSpec.describe Range do
- context "intersection" do
+ describe "#intersection" do
it "is nil (sic) for two distinct ranges" do
expect( (1..2).intersection(3..4) ).to be_nil
end
@@ -15,4 +15,53 @@ RSpec.describe Range do
expect( (2..4) & (1..3) ).to eq 2..3
end
end
+
+ describe "intersect?" do
+ it 'is true when the given range includes begin' do
+ expect( (2..4).intersect? (1..3) ).to be_truthy
+ end
+
+ it 'is true when the given range includes end' do
+ expect( (2..4).intersect? (3..5) ).to be_truthy
+ end
+
+ it 'is true when the given range includes both begin and end' do
+ expect( (2..4).intersect? (1..5) ).to be_truthy
+ end
+
+ it 'is true when the given range is the same' do
+ expect( (2..4).intersect? (2..4) ).to be_truthy
+ end
+
+ it 'is false when the given range is after' do
+ expect( (2..4).intersect? (5..7) ).to be_falsey
+ end
+
+ it 'is false when the given range is before' do
+ expect( (2..4).intersect? (0..2) ).to be_falsey
+ end
+ end
+
+ context "remove" do
+ it "is unchanged when the given range has no intersection" do
+ expect( (1..2).remove(3..4) ).to eq 1..2
+ expect( (3..4).remove(1..2) ).to eq 3..4
+ end
+
+ it "is nil for two equal ranges" do
+ expect( (1..2).remove(1..2) ).to be_empty
+ end
+
+ it "is the begin of the range when given range intersect the end" do
+ expect( (5..10).remove(8..15) ).to eq [5..7]
+ end
+
+ it "is the end of the range when given range intersect the begin" do
+ expect( (5..10).remove(1..6) ).to eq [7..10]
+ end
+
+ it "is the two remaing ranges when given range is the middle" do
+ expect( (1..10).remove(4..6) ).to eq [1..3, 7..10]
+ end
+ end
end
diff --git a/spec/lib/stif/netex_file/frame_spec.rb b/spec/lib/stif/netex_file/frame_spec.rb
new file mode 100644
index 000000000..506da2148
--- /dev/null
+++ b/spec/lib/stif/netex_file/frame_spec.rb
@@ -0,0 +1,13 @@
+require 'stif/netex_file'
+RSpec.describe STIF::NetexFile::Frame do
+
+ context "line object id extraction" do
+ it "gets the line object id if frame describes a line" do
+ expect( described_class.get_short_id('offre_C00109_10.xml') ).to eq('C00109')
+ end
+
+ it "gets nil if the frame does not describe a line" do
+ expect( described_class.get_short_id('commun.xml') ).to be_nil
+ end
+ end
+end
diff --git a/spec/lib/stif/netex_file_spec.rb b/spec/lib/stif/netex_file_spec.rb
index ef69b994c..850d0d3de 100644
--- a/spec/lib/stif/netex_file_spec.rb
+++ b/spec/lib/stif/netex_file_spec.rb
@@ -1,8 +1,9 @@
+require 'stif/netex_file'
RSpec.describe STIF::NetexFile do
let( :zip_file ){ fixtures_path 'OFFRE_TRANSDEV_2017030112251.zip' }
- let(:frames) { STIF::NetexFile.new(zip_file).frames }
+ let(:frames) { described_class.new(zip_file).frames }
it "should return a frame for each sub directory" do
expect(frames.size).to eq(2)
@@ -22,4 +23,5 @@ RSpec.describe STIF::NetexFile do
end
end
+
end
diff --git a/spec/lib/stif/permission_translator_spec.rb b/spec/lib/stif/permission_translator_spec.rb
index ae1a2d1d5..9771af187 100644
--- a/spec/lib/stif/permission_translator_spec.rb
+++ b/spec/lib/stif/permission_translator_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
RSpec.describe Stif::PermissionTranslator do
context "No SSO Permissions" do
@@ -42,4 +43,19 @@ RSpec.describe Stif::PermissionTranslator do
).to match_array(Support::Permissions.all_permissions)
end
end
+
+ context "For the STIF organisation" do
+ let(:organisation){ build_stubbed :organisation, name: "STIF" }
+ let(:permissions){ %w{calendars.share stop_area_referentials.synchronize line_referentials.synchronize}.sort }
+ it "adds the STIF permission" do
+ expect(described_class.translate([], organisation).sort).to eq permissions
+ end
+
+ context "with the case changed" do
+ let(:organisation){ build_stubbed :organisation, name: "StiF" }
+ it "adds the STIF permission" do
+ expect(described_class.translate([], organisation).sort).to eq permissions
+ end
+ end
+ end
end