From 073ac0eb3330787532f551d20abe4600a0615446 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Wed, 7 Jun 2017 13:12:56 +0200
Subject: factories/workbenches: Add a new `:with_referential` trait
This new trait allows us to create a referential association along with
the workbench.
Works like this:
create(:workbench, :with_referential)
We do this to allow us to reuse the `organisation`, `line_referential`,
and `stop_area_referential` associations to ensure that the values of
those fields are consistent in both the resulting workbench and
referential objects.
If we need to create multiple referentials, we could add an `amount`
later.
Left in some commented code describing my earlier attempts at this.
Fortunately, found this Stack Overflow post that pointed me in the right
direction:
https://stackoverflow.com/questions/20685322/how-to-create-an-association-in-factorygirl-with-a-value-lazy-evaluated-from-ano
I need this for a new `spec/helpers/table_builder_helper_spec.rb` spec,
wherein I'm trying to test building a table of workspaces, but having
trouble with code I copied from the app that tries to get
`#validity_period` from workbenches. Thought at first that adding a
referential (which does have this field) could help get past that, but
it didn't quite work. Needs more investigation.
Refs #3479
---
spec/factories/workbenches.rb | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
(limited to 'spec')
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index f51e7d94c..154482213 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -5,5 +5,24 @@ FactoryGirl.define do
association :organisation, :factory => :organisation
association :line_referential
association :stop_area_referential
+
+ trait :with_referential do
+ # TODO: change all => to :
+ # association :referential,
+ # organisation: { organisation }
+
+ # after(:stub) do |workbench, evaluator|
+ #
+ # end
+
+ referentials do |workbench|
+ [association(
+ :referential,
+ organisation: workbench.organisation,
+ line_referential: workbench.line_referential,
+ stop_area_referential: workbench.stop_area_referential
+ )]
+ end
+ end
end
end
--
cgit v1.2.3
From 212d1f740b17ae89b69603a3f1964351a38b86f6 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 8 Jun 2017 11:03:20 +0200
Subject: Add a few TODOs related to the table builder work
Just a few notes to myself for things to work on in this story.
Refs #3479
---
spec/factories/chouette_2_factories.rb | 1 +
1 file changed, 1 insertion(+)
(limited to 'spec')
diff --git a/spec/factories/chouette_2_factories.rb b/spec/factories/chouette_2_factories.rb
index e8eba13e6..a8e80702d 100644
--- a/spec/factories/chouette_2_factories.rb
+++ b/spec/factories/chouette_2_factories.rb
@@ -1,3 +1,4 @@
+# TODO: Move these factories into their own files so all factory definitions are consistent
FactoryGirl.define do
factory :organisation do
--
cgit v1.2.3
From c3d752af1ed040f64cd7cbfb964c2c5d5d8f7cde Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 8 Jun 2017 11:36:03 +0200
Subject: Add in-progress `TableBuilderHelper` (WIP)
Porting `table_builder` code over from `NewapplicationHelper`. The code
is very much in progress and incomplete. Only decided to commit it now
because I keep making changes and want to have those tracked so I don't
lose anything.
A lot of the original is commented out and the initial test I wrote
doesn't pass. The test also doesn't use the proper data, I just copied
it from the website's output.
Anyway, this is sort of the starting point.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 120 ++++++++++++++++++++++++++++++
1 file changed, 120 insertions(+)
create mode 100644 spec/helpers/table_builder_helper_spec.rb
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
new file mode 100644
index 000000000..e9d1afed3
--- /dev/null
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -0,0 +1,120 @@
+require 'spec_helper'
+
+describe TableBuilderHelper, type: :helper do
+ describe "#table_builder_2" do
+ it "builds a table" do
+ workbenches = [
+ build_stubbed(:referential)
+ ]
+
+ expected = <<-HTML
+
").html_safe},
+ :organisation => Proc.new {|w| w.organisation.name},
+ :validity_period => Proc.new {|w| w.validity_period.nil? ? '-' : t('validity_range', debut: l(w.try(:validity_period).try(:begin), format: :short), end: l(w.try(:validity_period).try(:end), format: :short))},
+ :lines => Proc.new {|w| w.lines.count},
+ :created_at => Proc.new {|w| l(w.created_at, format: :short)},
+ :updated_at => Proc.new {|w| l(w.updated_at, format: :short)},
+ :published_at => ''},
+ links: [:show, :edit, :archive, :unarchive, :delete],
+ cls: 'table has-filter has-search'
+ )).to eq(minified_expected)
+ end
+ end
+end
+
+
+# Replace table builder on workspaces#show page
+# Make the builder work without a `current_referential` so we can actually test it
+# Make a way to define a column as non-sortable. By default, columns will be sortable. Unless sortable==false and no columns should be sortable.
+#
+#
+# TODO:
+# - Finish writing workbench test
+# - Port some code over to the new table builder
+# - Ask Jean-Paul if there's anything he wishes could be changed or improved about the existing table builder
+# - Thing that Jean-Paul didn't like was the link generation
--
cgit v1.2.3
From ebd01ff27d3a4b2a57566632ce37873de4acf810 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 8 Jun 2017 14:37:44 +0200
Subject: TableBuilder spec: Stub a `params` global
Since the `TableBuilder` depends on the controller's `params` hash (the
link builder needs the controller, action, etc. in order to build a
link), we need to stub `params` in order for the helper call to work in
our test.
Still not a fan of this implicit dependency, but we'll see. I might keep
it in because maybe it makes more sense and would require less change to
keep it the way it is. The link builder is highly dynamic and seems like
it would be tricky to make non-dynamic. Needs more thought.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index e9d1afed3..085ed5a81 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -7,6 +7,12 @@ describe TableBuilderHelper, type: :helper do
build_stubbed(:referential)
]
+ allow(helper).to receive(:params).and_return({
+ :controller => 'workbenches',
+ :action => 'show',
+ :id => workbenches[0].workbench.id
+ })
+
expected = <<-HTML
--
cgit v1.2.3
From fa04c7ecc9dff0a06ad5a9c793a7b17defcf4300 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 8 Jun 2017 14:40:26 +0200
Subject: TableBuilder spec: Add a couple TODOs
It's not actually a collection of `workbenches` as we originally
thought, it's a collection of referentials. The name of the variable
should be changed to reflect that.
Also, in the real code, this value is not an array, but an
`ActiveRecord::Relation`, thus the `sortable_columns` method is able to
call `.model` on it. Since the test uses an array, that breaks. Need to
figure out what we want to do there. I don't like the dynamic-ness of
the way this is done now, but we need to figure out if it's possible to
factor that out in a pleasant way.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 2 ++
1 file changed, 2 insertions(+)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 085ed5a81..f936e9303 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -3,6 +3,8 @@ require 'spec_helper'
describe TableBuilderHelper, type: :helper do
describe "#table_builder_2" do
it "builds a table" do
+ # TODO: Rename to `referentials`
+ # TODO: `sortable_columns` calls `#model` on this collection
workbenches = [
build_stubbed(:referential)
]
--
cgit v1.2.3
From c4a5af98e48a51ebbca4e1eaad96da44887e8757 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 8 Jun 2017 15:01:27 +0200
Subject: TableBuilder spec: Rename `workbenches` to `referentials`
Because the collection contains referentials, not workbenches.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index f936e9303..5ca23ad09 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -3,16 +3,15 @@ require 'spec_helper'
describe TableBuilderHelper, type: :helper do
describe "#table_builder_2" do
it "builds a table" do
- # TODO: Rename to `referentials`
# TODO: `sortable_columns` calls `#model` on this collection
- workbenches = [
+ referentials = [
build_stubbed(:referential)
]
allow(helper).to receive(:params).and_return({
:controller => 'workbenches',
:action => 'show',
- :id => workbenches[0].workbench.id
+ :id => referentials[0].workbench.id
})
expected = <<-HTML
@@ -98,7 +97,7 @@ describe TableBuilderHelper, type: :helper do
minified_expected = expected.gsub(/^\s+/, '').gsub("\n", '')
expect(helper.table_builder_2(
- workbenches,
+ referentials,
{ :name => 'name',
:status => Proc.new {|w| w.archived? ? ("
Conservé
").html_safe : ("
En préparation
").html_safe},
:status => Proc.new {|w| ("
En préparation
").html_safe},
--
cgit v1.2.3
From 5166f0b6030b79d47b02743656eff835b523cae1 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 8 Jun 2017 15:05:59 +0200
Subject: TableBuilder spec: Stub `#model` on collection
`referentials` (known as `collection` in the `TableBuilder`) is supposed
to be an `ActiveRecord::Relation` instance. The `#sortable_columns`
method calls `collection.model` in order to dynamically build a table
column header. In order to get the test to the next stage, stub the
`#model` method. Not a huge fan. Ideally, the code wouldn't be so
dynamic, but maybe I'm wrong about that. Still need to think about this
for the refactoring.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 5ca23ad09..f3db493ce 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -3,11 +3,12 @@ require 'spec_helper'
describe TableBuilderHelper, type: :helper do
describe "#table_builder_2" do
it "builds a table" do
- # TODO: `sortable_columns` calls `#model` on this collection
referentials = [
build_stubbed(:referential)
]
+ allow(referentials).to receive(:model).and_return(Referential)
+
allow(helper).to receive(:params).and_return({
:controller => 'workbenches',
:action => 'show',
--
cgit v1.2.3
From 5d9ed9d90ada31f9ee895111613d970473981096 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 8 Jun 2017 18:00:01 +0200
Subject: TableBuilder spec: Get past Pundit errors
Add a bunch of mocks etc. to get past errors related to using Pundit
inside the helper. These errors included:
* No method `policy` (included `Pundit` in `TableBuilderHelper`)
* No method `authenticate` (mocked a `current_user` method on the
helper)
* Need to return a `user_context` from `current_user` to make policy's
`#new` happy (no method `user` on `User`)
At first tried to use the `create_user_context` method from
spec/support/pundit, but it wasn't in scope so I just did it directly to
get it working.
Don't like all the mocks at all. A lot of pre-work to do just to get the
helper to execute without exceptions.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index f3db493ce..b1c2b9a3f 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -1,11 +1,25 @@
require 'spec_helper'
+module TableBuilderHelper
+ include Pundit
+end
+
describe TableBuilderHelper, type: :helper do
describe "#table_builder_2" do
it "builds a table" do
- referentials = [
- build_stubbed(:referential)
- ]
+ referential = build_stubbed(:referential)
+
+ # user_context = create_user_context(
+ # user: build_stubbed(:user),
+ # referential: referential
+ # )
+ user_context = OpenStruct.new(
+ user: build_stubbed(:user),
+ context: { referential: referential }
+ )
+ allow(helper).to receive(:current_user).and_return(user_context)
+
+ referentials = [referential]
allow(referentials).to receive(:model).and_return(Referential)
--
cgit v1.2.3
From 7319d9d1324db3da7da4ed441594aa5d05c1feec Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 8 Jun 2017 18:13:12 +0200
Subject: TableBuilder spec: Beautify actual HTML result
In order to allow us to easily compare the HTML result with the expected
value, beautify the HTML that comes out of the helper call.
Otherwise, all the HTML is on a single line, and it can't be compared
with RSpec's diff output (even if RSpec outputted the entire contents of
the single line, we wouldn't really be able to compare it).
Thanks to this post for describing an easy way to get HTML
beautification:
https://stackoverflow.com/questions/5622269/how-to-beautify-xml-code-in-rails-application
We need to run the expected HTML string through the beautifier so we can
get the formatting right, but otherwise this gives us a better base for
test diffing.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index b1c2b9a3f..5945b0f82 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -109,9 +109,7 @@ describe TableBuilderHelper, type: :helper do
# 0 élément(s) sélectionné(s)
#
- minified_expected = expected.gsub(/^\s+/, '').gsub("\n", '')
-
- expect(helper.table_builder_2(
+ html_str = helper.table_builder_2(
referentials,
{ :name => 'name',
:status => Proc.new {|w| w.archived? ? ("
Conservé
").html_safe : ("
En préparation
").html_safe},
@@ -124,7 +122,11 @@ describe TableBuilderHelper, type: :helper do
:published_at => ''},
links: [:show, :edit, :archive, :unarchive, :delete],
cls: 'table has-filter has-search'
- )).to eq(minified_expected)
+ )
+ beautified_html = ''
+ REXML::Document.new(html_str).write(beautified_html, 4)
+
+ expect(beautified_html).to eq(expected)
end
end
end
--
cgit v1.2.3
From 89a81c459b60391603f38cb1a477e883d3bb2403 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 8 Jun 2017 18:33:03 +0200
Subject: TableBuilder spec: Use 'htmlbeautifier' gem for beautifying
Instead of `REXML::Document`, use `htmlbeautifier` to beautify our
actual HTML result. The trouble with `REXML` was that it forced single
quotes around attribute values. With 'htmlbeautifier', we get a good
result that we can realistically use for line-by-line diffs between
expected and actual. Much easier see what went wrong this way. And, in
my current case, see what I need to update update in the expected string
based on the factory-generated objects that I'm using.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 5945b0f82..c94df36a5 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
+require 'htmlbeautifier'
module TableBuilderHelper
include Pundit
@@ -123,8 +124,8 @@ describe TableBuilderHelper, type: :helper do
links: [:show, :edit, :archive, :unarchive, :delete],
cls: 'table has-filter has-search'
)
- beautified_html = ''
- REXML::Document.new(html_str).write(beautified_html, 4)
+
+ beautified_html = HtmlBeautifier.beautify(html_str, indent: ' ')
expect(beautified_html).to eq(expected)
end
--
cgit v1.2.3
From 9dab28fef1ac66b02a1ef62fdfb86cfc5ff13b96 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 9 Jun 2017 11:26:51 +0200
Subject: TableBuilder spec: Change params hash to new Ruby hash syntax
I had copied this from a debug session outputting a controller's
`params` hash. The original was:
{"controller"=>"workbenches", "action"=>"show", "id"=>"1", "q"=>{"archived_at_not_null"=>"1", "archived_at_null"=>"1"}}
which I just copy-pasted into my test. Since new code should be using
the new syntax, change this to use colons instead of arrows.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index c94df36a5..1049bf996 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -25,9 +25,9 @@ describe TableBuilderHelper, type: :helper do
allow(referentials).to receive(:model).and_return(Referential)
allow(helper).to receive(:params).and_return({
- :controller => 'workbenches',
- :action => 'show',
- :id => referentials[0].workbench.id
+ controller: 'workbenches',
+ action: 'show',
+ id: referentials[0].workbench.id
})
expected = <<-HTML
--
cgit v1.2.3
From 5d3cab81d61e5fb809a07f0e5fdaf00aa2f3210a Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 9 Jun 2017 11:31:35 +0200
Subject: TableBuilder spec: Correct expected column header hrefs
Use the correct workbench ID in the expected links for column sorting.
Previously I had copied this from rendered HTML on my local dev server.
We should actually use the ID of the factory-generated workbench object.
Now this part of our tests passes, correctly matching the URLs.
Needed to copy over the `q` params that are created by the
`WorkbenchesController` in order for this to actually work with the
right query string parameters tacked on to the hrefs. Makes the test a
bit more complicated, but more closely matches the real page's
behaviour.
Hrm, I wonder if we should get rid of that param entirely and
modify the expected hrefs to removed them since that doesn't really
appear to be related to what we're actually testing. I'll consider it.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 1049bf996..6f3ca7ee3 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -9,6 +9,7 @@ describe TableBuilderHelper, type: :helper do
describe "#table_builder_2" do
it "builds a table" do
referential = build_stubbed(:referential)
+ workbench = referential.workbench
# user_context = create_user_context(
# user: build_stubbed(:user),
@@ -27,7 +28,13 @@ describe TableBuilderHelper, type: :helper do
allow(helper).to receive(:params).and_return({
controller: 'workbenches',
action: 'show',
- id: referentials[0].workbench.id
+ id: referentials[0].workbench.id,
+
+ # These are added by WorkbenchesController#query_params
+ q: {
+ archived_at_not_null: 1,
+ archived_at_null: 1
+ }
})
expected = <<-HTML
@@ -37,14 +44,14 @@ describe TableBuilderHelper, type: :helper do
--
cgit v1.2.3
From bba80d09a1b429092114dff81a229e24a6720d87 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 9 Jun 2017 11:55:21 +0200
Subject: TableBuilder spec: Remove second table row from expected
Since we only have one referential in our collection, remove the second
row because it shouldn't be in the actual output.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 26 --------------------------
1 file changed, 26 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 6f3ca7ee3..4f4cffe61 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -82,32 +82,6 @@ describe TableBuilderHelper, type: :helper do
-
--
cgit v1.2.3
From 652c63e3d5e9f842d88ea9bc3ae027712922f69a Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 9 Jun 2017 12:24:03 +0200
Subject: TableBuilder spec: Give test user all referential permissions
Our expected output renders edit and destroy links in the cog menu:
@@ -35,9 +35,7 @@
It does this because I copied it from HTML rendered from my local dev
server, where my normal login user has admin permissions.
The actual HTML output doesn't render those links because the
factory-generated user for the test doesn't have permissions to those
links.
To get the actual to match the expected string, give our test user the
proper permissions and ensure their organisation is the same as the test
referential's organisation (as defined by the permissions in
`ReferentialPolicy`).
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index a58905244..f3a6001d0 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -16,7 +16,15 @@ describe TableBuilderHelper, type: :helper do
# referential: referential
# )
user_context = OpenStruct.new(
- user: build_stubbed(:user),
+ user: build_stubbed(
+ :user,
+ organisation: referential.organisation,
+ permissions: [
+ 'referentials.create',
+ 'referentials.edit',
+ 'referentials.destroy'
+ ]
+ ),
context: { referential: referential }
)
allow(helper).to receive(:current_user).and_return(user_context)
--
cgit v1.2.3
From 913cdad28b20ade05cccf262b096b02db2e0ab93 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 9 Jun 2017 12:33:32 +0200
Subject: TableBuilder spec: Remove newline from expected HTMl output
The actual HTML output doesn't have a newline at the end. This isn't
important for the test, so just remove the extra newline from the
expected output that's caused by the heredoc terminator.
Our test is finally green!
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index f3a6001d0..165e9c3f4 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -116,7 +116,7 @@ describe TableBuilderHelper, type: :helper do
beautified_html = HtmlBeautifier.beautify(html_str, indent: ' ')
- expect(beautified_html).to eq(expected)
+ expect(beautified_html).to eq(expected.chomp)
end
end
end
--
cgit v1.2.3
From 0fb0bd13e4e09c910bc4159985b714f43f6d0fe0 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 9 Jun 2017 15:13:44 +0200
Subject: TableBuilderHelper: Correct `selectable` behaviour
I had coded this the opposite of what it should have been. Instead, if
`selectable` is true, we should show the selection checkboxes.
Invert the conditions and add `selectable: true` to the
`table_builder_2` calls that expect a checkbox column.
Also remove the TODO because this argument is necessary.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 1 +
1 file changed, 1 insertion(+)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 165e9c3f4..dd4db0840 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -110,6 +110,7 @@ describe TableBuilderHelper, type: :helper do
:created_at => Proc.new {|w| l(w.created_at, format: :short)},
:updated_at => Proc.new {|w| l(w.updated_at, format: :short)},
:published_at => ''},
+ selectable: true,
links: [:show, :edit, :archive, :unarchive, :delete],
cls: 'table has-filter has-search'
)
--
cgit v1.2.3
From f2129a26cdf9cf986832c8a780f1e35c225a1df9 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 12 Jun 2017 14:13:09 +0200
Subject: TableBuilder spec: Add a test for sortable & non-sortable columns
Uses the table on the `/referentials/:id/companies` page. In that table,
all columns are sortable except for the "ID Codif" column.
The setup for the test is quite verbose and I don't like it.
I'll be using the test to change the sortable logic, removing the
hard-coded column header names checked inside the table builder in
favour of a flag that gets passed as part of the arguments to
`table_builder`.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 83 +++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index dd4db0840..ab41a0936 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -119,6 +119,89 @@ describe TableBuilderHelper, type: :helper do
expect(beautified_html).to eq(expected.chomp)
end
+
+ it "can set a column as non-sortable" do
+ company = build_stubbed(:company)
+ line_referential = build_stubbed(
+ :line_referential,
+ companies: [company]
+ )
+ referential = build_stubbed(
+ :referential,
+ line_referential: line_referential
+ )
+
+ user_context = OpenStruct.new(
+ user: build_stubbed(
+ :user,
+ organisation: referential.organisation,
+ permissions: [
+ 'referentials.create',
+ 'referentials.edit',
+ 'referentials.destroy'
+ ]
+ ),
+ context: { referential: referential }
+ )
+ allow(helper).to receive(:current_user).and_return(user_context)
+ allow(helper).to receive(:current_referential).and_return(referential)
+
+ companies = [company]
+
+ allow(companies).to receive(:model).and_return(Chouette::Company)
+
+ allow(helper).to receive(:params).and_return({
+ controller: 'referential_companies',
+ action: 'index',
+ referential_id: referential.id
+ })
+
+ expected = <<-HTML
+
+ HTML
+
+ html_str = helper.table_builder_2(
+ companies,
+ {
+ 'Oid' => Proc.new { |n| n.try(:objectid).try(:local_id) },
+ :name => 'name'
+ },
+ links: [:show, :edit, :delete],
+ cls: 'table has-search'
+ )
+
+ beautified_html = HtmlBeautifier.beautify(html_str, indent: ' ')
+
+ expect(beautified_html).to eq(expected.chomp)
+ end
end
end
--
cgit v1.2.3
From 91f6bc0b56d4b51645470c9f470d874f92d38b50 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 12 Jun 2017 14:23:58 +0200
Subject: TableBuilder spec: Fix columns in sortable test
I had mistakenly copied the code from
`app/views/companies/index.html.slim`. Instead, the code from the page I
wanted was actually supposed to come from
`app/views/referential_companies/index.html.slim`.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index ab41a0936..e29112653 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -191,8 +191,11 @@ describe TableBuilderHelper, type: :helper do
html_str = helper.table_builder_2(
companies,
{
- 'Oid' => Proc.new { |n| n.try(:objectid).try(:local_id) },
- :name => 'name'
+ 'ID Codif' => Proc.new { |n| n.try(:objectid).try(:local_id) },
+ :name => 'name',
+ :phone => 'phone',
+ :email => 'email',
+ :url => 'url'
},
links: [:show, :edit, :delete],
cls: 'table has-search'
--
cgit v1.2.3
From e89aead78b6182a0789d53e46b230df54aee82f3 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 12 Jun 2017 14:34:46 +0200
Subject: TableBuilder: Support a column-level sortable flag
Provides an option to set a column as non-sortable when defining the
column in the `table_builder` call.
Not written well, but it gets the idea across.
We allow column hash values to be hashes themselves (while continuing to
allow them to be `Proc`s and strings, this mixing of types is what I
really don't like). In that column-level hash, we can pass
`sortable: false` to disable sorting on that column. By default, sorting
is turned on for all columns.
Change the method signature of `sortable_columns`. Rename it to
`build_column_header`, as it will now generate a correct column header
regardless of whether the column is supposed to be sortable or not. I
moved some dependencies outside of the method, like `collection` (since
we only need the model from the collection), and the sort fields on
`params`. Unfortunately wasn't able to completely extricate `params` for
this method. Left the `params.merge` call that builds a link in this
method. Ideally I'd like that removed so that the method no longer
depends on global variables.
In `build_column_header`, if the column is not sortable, we return the
label defined by the key in the columns hash defined by the
`table_builder` caller. Otherwise, we build some HTML that includes
links on a couple of arrow buttons to enable sorting.
In `#thead`, we check to see if the columns hash value has a `sortable`
defined, in which case that flag gets used to determine what the column
header will be. I renamed the block variables here to be more
descriptive. Still not a huge fan of `attribute` as a name, though,
because it can now also be a Hash. Another aspect of this change that I
don't like.
In `#tbody`, needed to add a few extra lines to check whether
`attribute` is a Hash and get the real attribute if so. Really don't
like that either because it doesn't look good.
Update the sortable spec to pass a hash as the value of the column that
should not be sorted. It defines a `:sortable` key that tells the
builder not to allow this column to be sorted.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index e29112653..029748dd2 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -191,7 +191,10 @@ describe TableBuilderHelper, type: :helper do
html_str = helper.table_builder_2(
companies,
{
- 'ID Codif' => Proc.new { |n| n.try(:objectid).try(:local_id) },
+ 'ID Codif' => {
+ attribute: Proc.new { |n| n.try(:objectid).try(:local_id) },
+ sortable: false
+ },
:name => 'name',
:phone => 'phone',
:email => 'email',
--
cgit v1.2.3
From 6fb1431b3a2d3649bbd56ebc527fb45803248c94 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 12 Jun 2017 15:25:58 +0200
Subject: TableBuilder: Make a new type for columns
Instead of making the columns a hash where the types get all confused
and mussed and we have to type check wherever we use the column value,
make the columns into their own real type.
Adds a new `Column` class to the helper module which lets us interact
with table column data in a much more natural way. Here, when mapping
over the column list, instead of getting a key and value which could be
whatever, we get a real `Column` object that we can call methods on to
get the appropriate data.
It's still not perfect, as evidenced by the `#tbody` method, which has
remained largely the same, but at least we're not checking
`attribute.is_a?(Hash)` like I had tried before.
Update the tests to use the new `TableBuilderHelper::Column` syntax for
defining columns.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 72 +++++++++++++++++++++++--------
1 file changed, 55 insertions(+), 17 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 029748dd2..10cd6772b 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -101,15 +101,40 @@ describe TableBuilderHelper, type: :helper do
html_str = helper.table_builder_2(
referentials,
- { :name => 'name',
- :status => Proc.new {|w| w.archived? ? ("
").html_safe}
+ attribute: Proc.new do |w|
+ if w.archived?
+ ("
Conservé
").html_safe
+ else
+ ("
En préparation
").html_safe
+ end
+ end
),
TableBuilderHelper::Column.new(
key: :organisation,
@@ -116,7 +122,17 @@ describe TableBuilderHelper, type: :helper do
),
TableBuilderHelper::Column.new(
key: :validity_period,
- attribute: Proc.new {|w| w.validity_period.nil? ? '-' : t('validity_range', debut: l(w.try(:validity_period).try(:begin), format: :short), end: l(w.try(:validity_period).try(:end), format: :short))}
+ attribute: Proc.new do |w|
+ if w.validity_period.nil?
+ '-'
+ else
+ t(
+ 'validity_range',
+ debut: l(w.try(:validity_period).try(:begin), format: :short),
+ end: l(w.try(:validity_period).try(:end), format: :short)
+ )
+ end
+ end
),
TableBuilderHelper::Column.new(
key: :lines,
--
cgit v1.2.3
From d488e4e7251d3e0cc5b8ffe8ddbe6960fa99d14c Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 12 Jun 2017 16:13:34 +0200
Subject: TableBuilder: Add a couple TODOs
I had added these last week uncommitted, but still haven't gotten to
them. Figure I should just commit them to save them and remove them when
I get to them.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 1 +
1 file changed, 1 insertion(+)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index c685df4e4..b90053015 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -39,6 +39,7 @@ describe TableBuilderHelper, type: :helper do
id: referentials[0].workbench.id,
# These are added by WorkbenchesController#query_params
+ # TODO: Remove these params from here and the expected HTML as they don't relate to the test at hand
q: {
archived_at_not_null: 1,
archived_at_null: 1
--
cgit v1.2.3
From 416ac094aa3ae1a8e0ea4c088da8976815c63a2e Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 12 Jun 2017 16:20:34 +0200
Subject: TableBuilder spec: Remove `q` params from test
These params are not relevant to this test, they just clutter things up.
I had originally added them because the `/workbenches/:id` page used
them and I wanted to mimic the table builder result as closely as
possible.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index b90053015..756fac861 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -36,14 +36,7 @@ describe TableBuilderHelper, type: :helper do
allow(helper).to receive(:params).and_return({
controller: 'workbenches',
action: 'show',
- id: referentials[0].workbench.id,
-
- # These are added by WorkbenchesController#query_params
- # TODO: Remove these params from here and the expected HTML as they don't relate to the test at hand
- q: {
- archived_at_not_null: 1,
- archived_at_null: 1
- }
+ id: referentials[0].workbench.id
})
expected = <<-HTML
@@ -53,14 +46,14 @@ describe TableBuilderHelper, type: :helper do
--
cgit v1.2.3
From d2b1ab114348ee0895703cd650734f585b11e781 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Wed, 14 Jun 2017 18:24:17 +0200
Subject: TableBuilderHelper::CustomLinks: Fix policy check for unhandled
actions
In `#actions_after_policy_check`, we weren't correctly including actions
that weren't handled by the prior policy checks. Thus actions that
weren't [:delete, :edit, :archive, :unarchive] wouldn't get included in
the resulting list of actions.
Fix my logic error.
Refs #3479
---
.../table_builder_helper/custom_links_spec.rb | 27 ++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 spec/helpers/table_builder_helper/custom_links_spec.rb
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper/custom_links_spec.rb b/spec/helpers/table_builder_helper/custom_links_spec.rb
new file mode 100644
index 000000000..b64e97527
--- /dev/null
+++ b/spec/helpers/table_builder_helper/custom_links_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe TableBuilderHelper::CustomLinks do
+ describe "#actions_after_policy_check" do
+ it "includes :show" do
+ referential = build_stubbed(:referential)
+ user_context = UserContext.new(
+ build_stubbed(
+ :user,
+ organisation: referential.organisation,
+ permissions: [
+ 'boiv:read-offer'
+ ]
+ ),
+ referential: referential
+ )
+
+ expect(
+ TableBuilderHelper::CustomLinks.new(
+ referential,
+ user_context,
+ [:show]
+ ).actions_after_policy_check
+ ).to eq([:show])
+ end
+ end
+end
--
cgit v1.2.3
From 37ad0d2f30f8e16207b6123d9084b8f2cec3b592 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Wed, 14 Jun 2017 19:08:58 +0200
Subject: TableBuilderHelper: Add a couple TODOs
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 1 +
1 file changed, 1 insertion(+)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 756fac861..7e2d617a3 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -87,6 +87,7 @@ describe TableBuilderHelper, type: :helper do
HTML
+# TODO: Create a module for the selection box
#
#
#
--
cgit v1.2.3
From 0f013cdbb198956d095df5b0bb15a7ac9dac98d0 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 15 Jun 2017 11:13:02 +0200
Subject: TableBuilder spec: Decorate referential in "builds a table" spec
In order to properly build the table, the objects in the collection
passed to the table builder need to be decorated to add the
`#action_links` method.
Need to fix the other test too, but we don't have a `CompanyDecorator`
yet.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 2 ++
1 file changed, 2 insertions(+)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 7e2d617a3..c855e54c3 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -39,6 +39,8 @@ describe TableBuilderHelper, type: :helper do
id: referentials[0].workbench.id
})
+ referentials.map! { |referential| referential.decorate }
+
expected = <<-HTML
--
cgit v1.2.3
From 2a7b858f9bd5a8b2a8bd8b9913ab39e24201e89f Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 15 Jun 2017 11:17:00 +0200
Subject: TableBuilder spec: Change decoration to use `ModelDecorator`
Instead of mapping over the objects and decorating them manually, use
the `ModelDecorator` collection decorator to do it. This is what the
actual code does, so we should be doing the same in our test.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index c855e54c3..86bc02093 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -39,7 +39,10 @@ describe TableBuilderHelper, type: :helper do
id: referentials[0].workbench.id
})
- referentials.map! { |referential| referential.decorate }
+ referentials = ModelDecorator.decorate(
+ referentials,
+ with: ReferentialDecorator
+ )
expected = <<-HTML
--
cgit v1.2.3
From 68e87d50bee6789a1a2377d05c9a9656569b99b6 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 15 Jun 2017 11:18:16 +0200
Subject: TableBuilder spec: Remove table actions duplicated by decorator
The `ReferentialDecorator` duplicates the [:archive, :unarchive,
:delete] actions, so we should remove these from our test like we did
previously in the "workbenches/show.html.slim" template.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 86bc02093..c1fe71fb4 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -152,7 +152,7 @@ describe TableBuilderHelper, type: :helper do
)
],
selectable: true,
- links: [:show, :edit, :archive, :unarchive, :delete],
+ links: [:show, :edit],
cls: 'table has-filter has-search'
)
--
cgit v1.2.3
From 77228f4b959ff316b5f138c50f2c3b54c75ef115 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 15 Jun 2017 11:37:38 +0200
Subject: TableBuilder spec: Add extra links from `ReferentialDecorator`
A couple more links should appear in the gear menu thanks to the
inclusion of the `ReferentialDecorator#action_links`'s links in the
menu.
The test still fails, though, because the destroy link that comes out of
the decorator isn't formatted correctly (it looks like all the other
links instead of having a special icon).
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 2 ++
1 file changed, 2 insertions(+)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index c1fe71fb4..7d7a81908 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -83,6 +83,8 @@ describe TableBuilderHelper, type: :helper do
--
cgit v1.2.3
From 670b3b9a4be43bd6aea1d198cfe39f158ec1187f Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 15 Jun 2017 12:07:51 +0200
Subject: TableBuilder spec: Update `current_referential` mock
We're now using the `current_referential` method in
`TableBuilderHelper::URL` instead of in `TableBuilderHelper`. Thus it
couldn't get `current_referential` and caused an error. Move the mock to
`TableBuilderHelper::URL` to give it access to the method.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 7d7a81908..c5cbd972d 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -187,7 +187,8 @@ describe TableBuilderHelper, type: :helper do
context: { referential: referential }
)
allow(helper).to receive(:current_user).and_return(user_context)
- allow(helper).to receive(:current_referential).and_return(referential)
+ allow(TableBuilderHelper::URL).to receive(:current_referential)
+ .and_return(referential)
companies = [company]
--
cgit v1.2.3
From 34ee3f25dd9e903e27bbbbcdf85ae2803a869c76 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 15 Jun 2017 12:11:55 +0200
Subject: TableBuilder spec: Decorate companies collection
In order to enable access to `CompanyDecorator#action_links`, wrap the
companies collection passed to the table builder in the test in the
decorator.
Specify the class that `CompanyDecorator` decorates explicitly. Since
`Chouette::Company` is namespaced, Draper can't infer the model from the
decorator class name.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index c5cbd972d..89660dd56 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -200,6 +200,11 @@ describe TableBuilderHelper, type: :helper do
referential_id: referential.id
})
+ companies = ModelDecorator.decorate(
+ companies,
+ with: CompanyDecorator
+ )
+
expected = <<-HTML
--
cgit v1.2.3
From d79a0db0301d14e0ab4e5ecb2d8b60560f4490a9 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 15 Jun 2017 12:33:57 +0200
Subject: TableBuilder: Make table-level `sortable` work
We need the ability to say that an entire table is not sortable. By
default, all tables are sortable, and individual columns can have
sorting deactivated. This blanket deactivates sorting for all columns.
Take our `sortable` argument and pass it to `#thead`. Then
`#build_column_header` takes that value into account when creating a
header column value.
The actual label used in the column header is determined by the old
`#column_header_label` method. We've now moved it into the
`TableBuilderHelper::Column` class because it makes more sense there.
The method will now return the column's `:name` property if it was
defined, and otherwise gets the translation for `:key` as before.
Add a test on `TableBuilderHelper` that verifies that a table with
`sortable: false` returns the correct HTML without sorting links.
Refs #3479
---
spec/helpers/table_builder_helper/column_spec.rb | 23 +++++
spec/helpers/table_builder_helper_spec.rb | 108 +++++++++++++++++++++++
2 files changed, 131 insertions(+)
create mode 100644 spec/helpers/table_builder_helper/column_spec.rb
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper/column_spec.rb b/spec/helpers/table_builder_helper/column_spec.rb
new file mode 100644
index 000000000..0f27703b2
--- /dev/null
+++ b/spec/helpers/table_builder_helper/column_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe TableBuilderHelper::Column do
+ describe "#header_label" do
+ it "returns the column @name if present" do
+ expect(
+ TableBuilderHelper::Column.new(
+ name: 'ID Codif',
+ attribute: nil
+ ).header_label
+ ).to eq('ID Codif')
+ end
+
+ it "returns the I18n translation of @key if @name not present" do
+ expect(
+ TableBuilderHelper::Column.new(
+ key: :phone,
+ attribute: 'phone'
+ ).header_label(Chouette::Company)
+ ).to eq('Numéro de téléphone')
+ end
+ end
+end
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 89660dd56..c006e33c0 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -270,6 +270,114 @@ describe TableBuilderHelper, type: :helper do
expect(beautified_html).to eq(expected.chomp)
end
+
+ it "can set all columns as non-sortable" do
+ company = build_stubbed(:company)
+ line_referential = build_stubbed(
+ :line_referential,
+ companies: [company]
+ )
+ referential = build_stubbed(
+ :referential,
+ line_referential: line_referential
+ )
+
+ user_context = OpenStruct.new(
+ user: build_stubbed(
+ :user,
+ organisation: referential.organisation,
+ permissions: [
+ 'referentials.create',
+ 'referentials.edit',
+ 'referentials.destroy'
+ ]
+ ),
+ context: { referential: referential }
+ )
+ allow(helper).to receive(:current_user).and_return(user_context)
+ allow(TableBuilderHelper::URL).to receive(:current_referential)
+ .and_return(referential)
+
+ companies = [company]
+
+ allow(companies).to receive(:model).and_return(Chouette::Company)
+
+ allow(helper).to receive(:params).and_return({
+ controller: 'referential_companies',
+ action: 'index',
+ referential_id: referential.id
+ })
+
+ companies = ModelDecorator.decorate(
+ companies,
+ with: CompanyDecorator
+ )
+
+ expected = <<-HTML
+
--
cgit v1.2.3
From 690428d470440c604dcac52549baca8887fcd4c3 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 15 Jun 2017 16:31:22 +0200
Subject: TableBuilder spec: Use `UserContext`
Instead of building our context with an `OpenStruct`, use the
`UserContext` class that actually exists and represents the thing that
we want to represent.
I had copied the `OpenStruct` way of doing from
"spec/support/pundit/policies.rb" this before I found out that
`UserContext` existed.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 764e102fb..186f47413 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -11,12 +11,8 @@ describe TableBuilderHelper, type: :helper do
referential = build_stubbed(:referential)
workbench = referential.workbench
- # user_context = create_user_context(
- # user: build_stubbed(:user),
- # referential: referential
- # )
- user_context = OpenStruct.new(
- user: build_stubbed(
+ user_context = UserContext.new(
+ build_stubbed(
:user,
organisation: referential.organisation,
permissions: [
@@ -25,7 +21,7 @@ describe TableBuilderHelper, type: :helper do
'referentials.destroy'
]
),
- context: { referential: referential }
+ referential: referential
)
allow(helper).to receive(:current_user).and_return(user_context)
@@ -174,8 +170,8 @@ describe TableBuilderHelper, type: :helper do
line_referential: line_referential
)
- user_context = OpenStruct.new(
- user: build_stubbed(
+ user_context = UserContext.new(
+ build_stubbed(
:user,
organisation: referential.organisation,
permissions: [
@@ -184,7 +180,7 @@ describe TableBuilderHelper, type: :helper do
'referentials.destroy'
]
),
- context: { referential: referential }
+ referential: referential
)
allow(helper).to receive(:current_user).and_return(user_context)
allow(TableBuilderHelper::URL).to receive(:current_referential)
@@ -282,8 +278,8 @@ describe TableBuilderHelper, type: :helper do
line_referential: line_referential
)
- user_context = OpenStruct.new(
- user: build_stubbed(
+ user_context = UserContext.new(
+ build_stubbed(
:user,
organisation: referential.organisation,
permissions: [
@@ -292,7 +288,7 @@ describe TableBuilderHelper, type: :helper do
'referentials.destroy'
]
),
- context: { referential: referential }
+ referential: referential
)
allow(helper).to receive(:current_user).and_return(user_context)
allow(TableBuilderHelper::URL).to receive(:current_referential)
--
cgit v1.2.3
From b011960b67c7cadecb8d948934f13071d9ae4df1 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 15 Jun 2017 16:37:33 +0200
Subject: spec/Support::Pundit::Policies: Use UserContext instead of OpenStruct
There's a `UserContext` class that allows us to build user contexts. We
should use the full type for this instead of creating an anonymous one
for the context.
---
spec/support/pundit/policies.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/support/pundit/policies.rb b/spec/support/pundit/policies.rb
index e18309226..56433b2ee 100644
--- a/spec/support/pundit/policies.rb
+++ b/spec/support/pundit/policies.rb
@@ -9,7 +9,7 @@ module Support
end
def create_user_context(user:, referential:)
- OpenStruct.new(user: user, context: {referential: referential})
+ UserContext.new(user, referential: referential)
end
def add_permissions(*permissions, for_user:)
--
cgit v1.2.3
From 3aea68a27af7a96db470fba2ad9c1f6000a681b9 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Thu, 15 Jun 2017 16:48:26 +0200
Subject: TableBuilder spec: Remove TODOs
These are all finished.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 12 ------------
1 file changed, 12 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 186f47413..199373e24 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -376,15 +376,3 @@ describe TableBuilderHelper, type: :helper do
end
end
end
-
-
-# Replace table builder on workspaces#show page
-# Make the builder work without a `current_referential` so we can actually test it
-# Make a way to define a column as non-sortable. By default, columns will be sortable. Unless sortable==false and no columns should be sortable.
-#
-#
-# TODO:
-# - Finish writing workbench test
-# - Port some code over to the new table builder
-# - Ask Jean-Paul if there's anything he wishes could be changed or improved about the existing table builder
-# - Thing that Jean-Paul didn't like was the link generation
--
cgit v1.2.3
From a417f0a2f2813fbec7e3c925334433f6a724405d Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 11:27:52 +0200
Subject: TableBuilder spec: Fix hard-coded IDs in expected string
Remove the hard-coded IDs and replace them with the test referential's
ID. I guess I had copied the output from the spec output, because the
test then passed when I ran it individually, causing me to not catch the
error. Only saw it when I ran the full test suite.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 199373e24..a61fd2343 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -79,8 +79,8 @@ describe TableBuilderHelper, type: :helper do
--
cgit v1.2.3
From 7b11f89ca24ceb4949c27baf279564034f0a5106 Mon Sep 17 00:00:00 2001
From: Xinhui
Date: Mon, 19 Jun 2017 17:25:23 +0200
Subject: JourneyPattern validate minimum stop_points size on update
Refs #3775
---
spec/models/chouette/journey_pattern_spec.rb | 82 +++++++++++++++++++++++++++-
1 file changed, 80 insertions(+), 2 deletions(-)
(limited to 'spec')
diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb
index 19b5060d2..f7006efc7 100644
--- a/spec/models/chouette/journey_pattern_spec.rb
+++ b/spec/models/chouette/journey_pattern_spec.rb
@@ -2,6 +2,25 @@ require 'spec_helper'
describe Chouette::JourneyPattern, :type => :model do
+ context 'validate minimum stop_points size' do
+ let(:journey_pattern) { create :journey_pattern }
+ let(:stop_points) { journey_pattern.stop_points }
+
+ it 'should be valid if it has at least two sp' do
+ journey_pattern.stop_points.first(stop_points.size - 2).each do |sp|
+ journey_pattern.stop_points.delete(sp)
+ end
+ expect(journey_pattern).to be_valid
+ end
+
+ it 'should not be valid if it has less then two sp' do
+ journey_pattern.stop_points.first(stop_points.size - 1).each do |sp|
+ journey_pattern.stop_points.delete(sp)
+ end
+ expect(journey_pattern).to_not be_valid
+ end
+ end
+
describe "state_update" do
def journey_pattern_to_state jp
jp.attributes.slice('name', 'published_name', 'registration_number').tap do |item|
@@ -24,12 +43,14 @@ describe Chouette::JourneyPattern, :type => :model do
end
it 'should attach checked stop_points' do
- state['stop_points'].each{|sp| sp['checked'] = true}
# Make sure journey_pattern has no stop_points
- journey_pattern.stop_points.delete_all
+ state['stop_points'].each{|sp| sp['checked'] = false}
+ journey_pattern.state_stop_points_update(state)
expect(journey_pattern.reload.stop_points).to be_empty
+ state['stop_points'].each{|sp| sp['checked'] = true}
journey_pattern.state_stop_points_update(state)
+
expect(journey_pattern.reload.stop_points.count).to eq(5)
end
@@ -89,6 +110,63 @@ describe Chouette::JourneyPattern, :type => :model do
expect(collection.first).to_not have_key('object_id')
end
+
+ it 'should create journey_pattern' do
+ new_state = journey_pattern_to_state(build(:journey_pattern, objectid: nil, route: route))
+ Chouette::JourneyPattern.state_create_instance route, new_state
+ expect(new_state['object_id']).to be_truthy
+ expect(new_state['new_record']).to be_truthy
+ end
+
+ it 'should delete journey_pattern' do
+ state['deletable'] = true
+ collection = [state]
+ expect {
+ Chouette::JourneyPattern.state_update route, collection
+ }.to change{Chouette::JourneyPattern.count}.from(1).to(0)
+
+ expect(collection).to be_empty
+ end
+
+ it 'should delete multiple journey_pattern' do
+ collection = 5.times.collect{journey_pattern_to_state(create(:journey_pattern, route: route))}
+ collection.map{|i| i['deletable'] = true}
+
+ expect {
+ Chouette::JourneyPattern.state_update route, collection
+ }.to change{Chouette::JourneyPattern.count}.from(5).to(0)
+ end
+
+ it 'should validate journey_pattern on update' do
+ journey_pattern.name = ''
+ collection = [state]
+ Chouette::JourneyPattern.state_update route, collection
+ expect(collection.first['errors']).to have_key(:name)
+ end
+
+ it 'should validate journey_pattern on create' do
+ new_state = journey_pattern_to_state(build(:journey_pattern, name: '', objectid: nil, route: route))
+ collection = [new_state]
+ expect {
+ Chouette::JourneyPattern.state_update route, collection
+ }.to_not change{Chouette::JourneyPattern.count}
+
+ expect(collection.first['errors']).to have_key(:name)
+ expect(collection.first).to_not have_key('object_id')
+ end
+
+ it 'should not save any journey_pattern of collection if one is invalid' do
+ journey_pattern.name = ''
+ valid_state = journey_pattern_to_state(build(:journey_pattern, objectid: nil, route: route))
+ invalid_state = journey_pattern_to_state(journey_pattern)
+ collection = [valid_state, invalid_state]
+
+ expect {
+ Chouette::JourneyPattern.state_update route, collection
+ }.to_not change{Chouette::JourneyPattern.count}
+
+ expect(collection.first).to_not have_key('object_id')
+ end
end
describe "#stop_point_ids" do
--
cgit v1.2.3
From f483c2db410f78287e77ac968a7229b0d5e5b835 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 17:47:40 +0200
Subject: TableBuilder spec: Remove TODO
We're how have a separate module for the box containing links to perform
actions on selections of multiple objects in the table. I had put this
in `MultipleSelectionToolboxHelper`.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 6 ------
1 file changed, 6 deletions(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index a61fd2343..32a6a3bfd 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -90,12 +90,6 @@ describe TableBuilderHelper, type: :helper do
HTML
-# TODO: Create a module for the selection box
-#
-#
-#
-#
0 élément(s) sélectionné(s)
-#
html_str = helper.table_builder_2(
referentials,
--
cgit v1.2.3
From 533c1a55df630080cd0ff449e229717ba7ace212 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 18:08:28 +0200
Subject: Revert "factories/workbenches: Add a new `:with_referential` trait"
This reverts commit 073ac0eb3330787532f551d20abe4600a0615446.
I no longer need this factory. Originally added it for a test where I
thought I needed a collection of `Workbench`es. Turns out I instead
needed a collection of `Referential`s. Thus we don't have a need of
creating a workbench with a referential together.
---
spec/factories/workbenches.rb | 19 -------------------
1 file changed, 19 deletions(-)
(limited to 'spec')
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index 154482213..f51e7d94c 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -5,24 +5,5 @@ FactoryGirl.define do
association :organisation, :factory => :organisation
association :line_referential
association :stop_area_referential
-
- trait :with_referential do
- # TODO: change all => to :
- # association :referential,
- # organisation: { organisation }
-
- # after(:stub) do |workbench, evaluator|
- #
- # end
-
- referentials do |workbench|
- [association(
- :referential,
- organisation: workbench.organisation,
- line_referential: workbench.line_referential,
- stop_area_referential: workbench.stop_area_referential
- )]
- end
- end
end
end
--
cgit v1.2.3
From 140270297b1db064b78472ccd7e59b8279d21be7 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 18:35:26 +0200
Subject: lines/show.html.erb_spec.rb: Fix specs resulting from `LineDecorator`
The tests failed because we weren't using a decorated `Chouette::Line`
object, but the views now expect decorated lines in order to be able to
call the `#action_links` method.
Here are our failures:
5) /lines/show should render h1 with the line name
Failure/Error: - @line.action_links.each do |link|
ActionView::Template::Error:
undefined method `action_links' for #
# ./app/views/lines/show.html.slim:10:in `block in _app_views_lines_show_html_slim___3813514632397395671_70250211127360'
# ./app/helpers/newapplication_helper.rb:246:in `block (2 levels) in pageheader'
# ./app/helpers/newapplication_helper.rb:244:in `block in pageheader'
# ./app/helpers/newapplication_helper.rb:243:in `pageheader'
# ./app/views/lines/show.html.slim:2:in `_app_views_lines_show_html_slim___3813514632397395671_70250211127360'
# ./spec/views/lines/show.html.erb_spec.rb:16:in `block (2 levels) in '
# -e:1:in `'
# ------------------
# --- Caused by: ---
# NoMethodError:
# undefined method `action_links' for #
# ./app/views/lines/show.html.slim:10:in `block in _app_views_lines_show_html_slim___3813514632397395671_70250211127360'
6) /lines/show should render a link to remove the line
Failure/Error: - @line.action_links.each do |link|
ActionView::Template::Error:
undefined method `action_links' for #
# ./app/views/lines/show.html.slim:10:in `block in _app_views_lines_show_html_slim___3813514632397395671_70250211127360'
# ./app/helpers/newapplication_helper.rb:246:in `block (2 levels) in pageheader'
# ./app/helpers/newapplication_helper.rb:244:in `block in pageheader'
# ./app/helpers/newapplication_helper.rb:243:in `pageheader'
# ./app/views/lines/show.html.slim:2:in `_app_views_lines_show_html_slim___3813514632397395671_70250211127360'
# ./spec/views/lines/show.html.erb_spec.rb:31:in `block (2 levels) in '
# -e:1:in `'
# ------------------
# --- Caused by: ---
# NoMethodError:
# undefined method `action_links' for #
# ./app/views/lines/show.html.slim:10:in `block in _app_views_lines_show_html_slim___3813514632397395671_70250211127360'
Update the test to decorate the lines used in them.
Turn `current_organisation` into a `context` field on `LineDecorator`
because otherwise it's a global variable that comes from wherever that's
required in `LineDecorator`. And we'd have to mock
`current_organisation` on `line` in the test, which I wasn't keen on.
Refs #3479
---
spec/views/lines/show.html.erb_spec.rb | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb
index 3a9efa0ce..7bc120f1a 100644
--- a/spec/views/lines/show.html.erb_spec.rb
+++ b/spec/views/lines/show.html.erb_spec.rb
@@ -3,7 +3,13 @@ require 'spec_helper'
describe "/lines/show", :type => :view do
assign_referential
- let!(:line) { assign :line, create(:line) }
+ let!(:line) do
+ line = create(:line)
+ assign :line, line.decorate(context: {
+ line_referential: line.line_referential,
+ current_organisation: referential.organisation
+ })
+ end
let!(:line_referential) { assign :line_referential, line.line_referential }
let!(:routes) { assign :routes, Array.new(2) { create(:route, :line => line) }.paginate }
let!(:map) { assign(:map, double(:to_html => ''.html_safe)) }
--
cgit v1.2.3
From 3343920fe8df5378f7bced238b03860e249ac1cf Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 18:43:16 +0200
Subject: time_tables/show.html.erb_spec.rb: Fix specs from
`TimeTableDecorator`
Was getting these failures after switching the controller over to use a
decorated `@time_table`:
Failures:
1) /time_tables/show should render h2 with the time_table comment
Failure/Error: - @time_table.action_links.each do |link|
ActionView::Template::Error:
undefined method `action_links' for #
# ./app/views/time_tables/show.html.slim:13:in `block in _app_views_time_tables_show_html_slim__2702796193816469913_70250218141540'
# ./app/helpers/newapplication_helper.rb:246:in `block (2 levels) in pageheader'
# ./app/helpers/newapplication_helper.rb:244:in `block in pageheader'
# ./app/helpers/newapplication_helper.rb:243:in `pageheader'
# ./app/views/time_tables/show.html.slim:4:in `_app_views_time_tables_show_html_slim__2702796193816469913_70250218141540'
# ./spec/views/time_tables/show.html.erb_spec.rb:15:in `block (2 levels) in '
# -e:1:in `'
# ------------------
# --- Caused by: ---
# NoMethodError:
# undefined method `action_links' for #
# ./app/views/time_tables/show.html.slim:13:in `block in _app_views_time_tables_show_html_slim__2702796193816469913_70250218141540'
2) /time_tables/show should render a link to edit the time_table
Failure/Error: - @time_table.action_links.each do |link|
ActionView::Template::Error:
undefined method `action_links' for #
# ./app/views/time_tables/show.html.slim:13:in `block in _app_views_time_tables_show_html_slim__2702796193816469913_70250218141540'
# ./app/helpers/newapplication_helper.rb:246:in `block (2 levels) in pageheader'
# ./app/helpers/newapplication_helper.rb:244:in `block in pageheader'
# ./app/helpers/newapplication_helper.rb:243:in `pageheader'
# ./app/views/time_tables/show.html.slim:4:in `_app_views_time_tables_show_html_slim__2702796193816469913_70250218141540'
# ./spec/views/time_tables/show.html.erb_spec.rb:20:in `block (2 levels) in '
# -e:1:in `'
# ------------------
# --- Caused by: ---
# NoMethodError:
# undefined method `action_links' for #
# ./app/views/time_tables/show.html.slim:13:in `block in _app_views_time_tables_show_html_slim__2702796193816469913_70250218141540'
3) /time_tables/show should render a link to remove the time_table
Failure/Error: - @time_table.action_links.each do |link|
ActionView::Template::Error:
undefined method `action_links' for #
# ./app/views/time_tables/show.html.slim:13:in `block in _app_views_time_tables_show_html_slim__2702796193816469913_70250218141540'
# ./app/helpers/newapplication_helper.rb:246:in `block (2 levels) in pageheader'
# ./app/helpers/newapplication_helper.rb:244:in `block in pageheader'
# ./app/helpers/newapplication_helper.rb:243:in `pageheader'
# ./app/views/time_tables/show.html.slim:4:in `_app_views_time_tables_show_html_slim__2702796193816469913_70250218141540'
# ./spec/views/time_tables/show.html.erb_spec.rb:25:in `block (2 levels) in '
# -e:1:in `'
# ------------------
# --- Caused by: ---
# NoMethodError:
# undefined method `action_links' for #
# ./app/views/time_tables/show.html.slim:13:in `block in _app_views_time_tables_show_html_slim__2702796193816469913_70250218141540'
Finished in 2.44 seconds (files took 0.82818 seconds to load)
3 examples, 3 failures
Failed examples:
rspec ./spec/views/time_tables/show.html.erb_spec.rb:14 # /time_tables/show should render h2 with the time_table comment
rspec ./spec/views/time_tables/show.html.erb_spec.rb:19 # /time_tables/show should render a link to edit the time_table
rspec ./spec/views/time_tables/show.html.erb_spec.rb:24 # /time_tables/show should render a link to remove the time_table
To match the controller, we need to decorate the `time_table` objects
used in these tests as well, because the view code has changed.
Decoration is necessary to give us the `#action_links` method that we
use to render the header links on the page.
Refs #3479
---
spec/views/time_tables/show.html.erb_spec.rb | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/views/time_tables/show.html.erb_spec.rb b/spec/views/time_tables/show.html.erb_spec.rb
index f429f9dec..edfb3f3cc 100644
--- a/spec/views/time_tables/show.html.erb_spec.rb
+++ b/spec/views/time_tables/show.html.erb_spec.rb
@@ -3,7 +3,14 @@ require 'spec_helper'
describe "/time_tables/show", :type => :view do
assign_referential
- let!(:time_table) { assign(:time_table, create(:time_table)) }
+ let!(:time_table) do
+ assign(
+ :time_table,
+ create(:time_table).decorate(context: {
+ referential: referential
+ })
+ )
+ end
let!(:year) { assign(:year, Date.today.cwyear) }
let!(:time_table_combination) {assign(:time_table_combination, TimeTableCombination.new)}
--
cgit v1.2.3
From 150e71e3110292c0c27fe35a63e8a2d0e26c5259 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 18:47:32 +0200
Subject: referentials_permissions_spec.rb: Fix failure from
`#destroy_link_content`
Now, destroy ("Supprimer") buttons in the header get rendered without a
`` tag surrounding the text inside the button. This is because I
consolidated the HTML structure of the delete buttons inside table gear
menus and the header.
The ones in the gear menus had no span, and these in the header do.
In both places, we're now using `LinksHelper#destroy_link_content` to
generate the contents of the button, making the contents uniform in both
contexts.
This means, however, that the markup is not the same for header buttons,
which now have their inner `` tag removed. Update the test to
reflect this.
Also, the styling breaks when I updated the markup, but Jean-Paul
offered to fix that.
Refs #3479
---
spec/features/referentials_permissions_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/features/referentials_permissions_spec.rb b/spec/features/referentials_permissions_spec.rb
index 0216eeeb0..c37dff5b9 100644
--- a/spec/features/referentials_permissions_spec.rb
+++ b/spec/features/referentials_permissions_spec.rb
@@ -31,7 +31,7 @@ describe "Referentials", :type => :feature do
end
it 'shows the delete button' do
expected_href = referential_path(referential)
- expect( page ).to have_css(%{a[href=#{expected_href.inspect}] span}, text: destroy_link_text)
+ expect( page ).to have_css(%{a[href=#{expected_href.inspect}]}, text: destroy_link_text)
end
end
--
cgit v1.2.3
From 041c6d8b732825dc8f84f3795e1fd63f0a30f483 Mon Sep 17 00:00:00 2001
From: Xinhui
Date: Tue, 20 Jun 2017 11:38:27 +0200
Subject: I18n journey_pattern stop_points too_short validation
Refs #3775
---
spec/models/chouette/journey_pattern_spec.rb | 1 +
1 file changed, 1 insertion(+)
(limited to 'spec')
diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb
index f7006efc7..aaf9a694f 100644
--- a/spec/models/chouette/journey_pattern_spec.rb
+++ b/spec/models/chouette/journey_pattern_spec.rb
@@ -18,6 +18,7 @@ describe Chouette::JourneyPattern, :type => :model do
journey_pattern.stop_points.delete(sp)
end
expect(journey_pattern).to_not be_valid
+ expect(journey_pattern.errors).to have_key(:stop_points)
end
end
--
cgit v1.2.3
From f42ea52d0f7f6fd6cab7f9179f93e189dd90bdca Mon Sep 17 00:00:00 2001
From: Robert
Date: Tue, 20 Jun 2017 17:03:56 +0200
Subject: Refs: #3595@3h; calendars/new Date validation
---
.../autocomplete_calendars_controller_spec.rb | 2 --
spec/controllers/calendars_controller_spec.rb | 31 ++++++++++++++++++++++
spec/features/calendars_spec.rb | 18 ++++++++++---
3 files changed, 45 insertions(+), 6 deletions(-)
create mode 100644 spec/controllers/calendars_controller_spec.rb
(limited to 'spec')
diff --git a/spec/controllers/autocomplete_calendars_controller_spec.rb b/spec/controllers/autocomplete_calendars_controller_spec.rb
index 3ff75fadf..812cd92f9 100644
--- a/spec/controllers/autocomplete_calendars_controller_spec.rb
+++ b/spec/controllers/autocomplete_calendars_controller_spec.rb
@@ -1,5 +1,3 @@
-require 'rails_helper'
-
RSpec.describe AutocompleteCalendarsController, type: :controller do
end
diff --git a/spec/controllers/calendars_controller_spec.rb b/spec/controllers/calendars_controller_spec.rb
new file mode 100644
index 000000000..ab3123192
--- /dev/null
+++ b/spec/controllers/calendars_controller_spec.rb
@@ -0,0 +1,31 @@
+RSpec.describe CalendarsController, type: :controller do
+ login_user
+ describe 'POST /create' do
+
+ context 'legal date' do
+ let( :params ){ {
+ "calendar"=>{"name"=>"cal", "short_name"=>"cal", "shared"=>"false",
+ "date_values_attributes"=>{"1497892917360"=>{"value(3i)"=>"19", "value(2i)"=>"6", "value(1i)"=>"2017", "_destroy"=>""}}}
+ } }
+
+ it 'creates the calendar and redirects to show' do
+ expect{ post :create, params }.to change{Calendar.count}.by 1
+ expect( response ).to redirect_to( calendar_path( Calendar.last ) )
+ end
+ end
+
+ context 'illegal date' do
+ let( :params ){ {
+ "calendar"=>{"name"=>"cal", "short_name"=>"cal", "shared"=>"false",
+ "date_values_attributes"=>{"1497892917360"=>{"value(3i)"=>"31", "value(2i)"=>"6", "value(1i)"=>"2017", "_destroy"=>""}}}
+ } }
+
+ it 'does not create the calendar and redircets to new' do
+ post :create, params
+ expect{ post :create, params }.not_to change{Calendar.count}
+ expect( response ).to redirect_to( new_calendar_path )
+ end
+ end
+
+ end
+end
diff --git a/spec/features/calendars_spec.rb b/spec/features/calendars_spec.rb
index e15624295..8c38e7820 100644
--- a/spec/features/calendars_spec.rb
+++ b/spec/features/calendars_spec.rb
@@ -1,7 +1,4 @@
-# -*- coding: utf-8 -*-
-require 'spec_helper'
-
-describe 'Calendars', type: :feature do
+RSpec.describe 'Calendars', type: :feature do
login_user
let!(:calendars) { Array.new(2) { create :calendar, organisation_id: 1 } }
@@ -69,4 +66,17 @@ describe 'Calendars', type: :feature do
expect(page).to have_content(calendars.first.name)
end
end
+
+ describe 'create', :wip do
+ before do
+ visit new_calendar_path
+
+ end
+ it 'with correct date' do
+ require 'pry'
+ binding.pry
+
+ end
+
+ end
end
--
cgit v1.2.3
From 400898d14514aaf6df991dd2cb73e10b991ae34b Mon Sep 17 00:00:00 2001
From: Robert
Date: Wed, 21 Jun 2017 11:57:46 +0200
Subject: Refs: #3595@2h; calendars#new/edit covered
---
spec/models/calendar/calendar_date_spec.rb | 38 ++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 spec/models/calendar/calendar_date_spec.rb
(limited to 'spec')
diff --git a/spec/models/calendar/calendar_date_spec.rb b/spec/models/calendar/calendar_date_spec.rb
new file mode 100644
index 000000000..25fe8ba8d
--- /dev/null
+++ b/spec/models/calendar/calendar_date_spec.rb
@@ -0,0 +1,38 @@
+RSpec.describe Calendar::CalendarDate do
+
+ subject { described_class.new(year, month, day) }
+ let( :year ){ 2000 }
+ let( :month ){ 2 }
+
+ let( :str_repr ){ %r{#{year}-0?#{month}-0?#{day}} }
+
+
+
+ shared_examples_for "date accessors" do
+ it "accesses year" do
+ expect( subject.year ).to eq(year)
+ end
+ it "accesses month" do
+ expect( subject.month ).to eq(month)
+ end
+ it "accesses day" do
+ expect( subject.day ).to eq(day)
+ end
+ it "converts to a string" do
+ expect( subject.to_s ).to match(str_repr)
+ end
+ end
+
+ context 'legal' do
+ let( :day ){ 29 }
+ it { expect_it.to be_legal }
+ it_should_behave_like "date accessors"
+ end
+
+ context 'illegal' do
+ let( :day ){ 30 }
+ it { expect_it.not_to be_legal }
+ it_should_behave_like "date accessors"
+ end
+
+end
--
cgit v1.2.3
From dc80c8b8a8bc3123973c471346c69445238d998e Mon Sep 17 00:00:00 2001
From: Thomas Haddad
Date: Wed, 21 Jun 2017 17:23:42 +0200
Subject: Refs #3338: Fix duplicate vj not multiplying departureDelta
Signed-off-by: Thomas Shawarma Haddad
---
spec/javascripts/vehicle_journeys/actions_spec.js | 6 ++++--
.../vehicle_journeys/reducers/vehicle_journeys_spec.js | 8 +++++---
2 files changed, 9 insertions(+), 5 deletions(-)
(limited to 'spec')
diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js
index 19f65046f..d96baf8ef 100644
--- a/spec/javascripts/vehicle_journeys/actions_spec.js
+++ b/spec/javascripts/vehicle_journeys/actions_spec.js
@@ -188,11 +188,13 @@ describe('when clicking on validate button inside editing modal', () => {
describe('when clicking on validate button inside duplicating modal', () => {
it('should create an action to duplicate a vehiclejourney schedule', () => {
const data = {}
+ const departureDelta = 0
const expectedAction = {
type: 'DUPLICATE_VEHICLEJOURNEY',
- data
+ data,
+ departureDelta
}
- expect(actions.duplicateVehicleJourney(data)).toEqual(expectedAction)
+ expect(actions.duplicateVehicleJourney(data, departureDelta)).toEqual(expectedAction)
})
})
describe('when clicking on edit notes modal', () => {
diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js
index 23ebc3d9f..620e2ffdd 100644
--- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js
+++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js
@@ -216,14 +216,15 @@ describe('vehicleJourneys reducer', () => {
delta: 627,
arrival_time : {
hour: '12',
- minute: '00'
+ minute: '01'
},
departure_time : {
hour: '22',
- minute: '27'
+ minute: '28'
},
stop_area_object_id : "FR:92024:ZDE:420553:STIF"
}]
+ let departureDelta = 1
let fakeData = {
duplicate_number: {value : 1},
additional_time: {value: '5'}
@@ -234,7 +235,8 @@ describe('vehicleJourneys reducer', () => {
expect(
vjReducer(state, {
type: 'DUPLICATE_VEHICLEJOURNEY',
- data: fakeData
+ data: fakeData,
+ departureDelta
})
).toEqual([state[0], newVJ, state[1]])
})
--
cgit v1.2.3
From d51985fc2a7c2138fd12cb9116ebf05d8b0e7dac Mon Sep 17 00:00:00 2001
From: Robert
Date: Wed, 21 Jun 2017 14:52:46 +0200
Subject: Refs: #3595@3h; fixing tests, evaluating timeliness gem :(
---
spec/controllers/calendars_controller_spec.rb | 31 ----------
spec/features/calendars_spec.rb | 82 ---------------------------
spec/models/calendar_spec.rb | 18 +++---
3 files changed, 10 insertions(+), 121 deletions(-)
delete mode 100644 spec/controllers/calendars_controller_spec.rb
delete mode 100644 spec/features/calendars_spec.rb
(limited to 'spec')
diff --git a/spec/controllers/calendars_controller_spec.rb b/spec/controllers/calendars_controller_spec.rb
deleted file mode 100644
index ab3123192..000000000
--- a/spec/controllers/calendars_controller_spec.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-RSpec.describe CalendarsController, type: :controller do
- login_user
- describe 'POST /create' do
-
- context 'legal date' do
- let( :params ){ {
- "calendar"=>{"name"=>"cal", "short_name"=>"cal", "shared"=>"false",
- "date_values_attributes"=>{"1497892917360"=>{"value(3i)"=>"19", "value(2i)"=>"6", "value(1i)"=>"2017", "_destroy"=>""}}}
- } }
-
- it 'creates the calendar and redirects to show' do
- expect{ post :create, params }.to change{Calendar.count}.by 1
- expect( response ).to redirect_to( calendar_path( Calendar.last ) )
- end
- end
-
- context 'illegal date' do
- let( :params ){ {
- "calendar"=>{"name"=>"cal", "short_name"=>"cal", "shared"=>"false",
- "date_values_attributes"=>{"1497892917360"=>{"value(3i)"=>"31", "value(2i)"=>"6", "value(1i)"=>"2017", "_destroy"=>""}}}
- } }
-
- it 'does not create the calendar and redircets to new' do
- post :create, params
- expect{ post :create, params }.not_to change{Calendar.count}
- expect( response ).to redirect_to( new_calendar_path )
- end
- end
-
- end
-end
diff --git a/spec/features/calendars_spec.rb b/spec/features/calendars_spec.rb
deleted file mode 100644
index 8c38e7820..000000000
--- a/spec/features/calendars_spec.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-RSpec.describe 'Calendars', type: :feature do
- login_user
-
- let!(:calendars) { Array.new(2) { create :calendar, organisation_id: 1 } }
- let!(:shared_calendar_other_org) { create :calendar, shared: true }
- let!(:unshared_calendar_other_org) { create :calendar }
-
- describe 'index' do
- before(:each) { visit calendars_path }
-
- it 'displays calendars of the current organisation' do
- expect(page).to have_content(calendars.first.short_name)
- # expect(page).to have_content(shared_calendar_other_org.short_name)
- # expect(page).not_to have_content(unshared_calendar_other_org.short_name)
- end
-
- context 'filtering' do
- it 'supports filtering by short name' do
- fill_in 'q[name_or_short_name_cont]', with: calendars.first.short_name
- click_button 'search_btn'
- expect(page).to have_content(calendars.first.short_name)
- expect(page).not_to have_content(calendars.last.short_name)
- end
-
- it 'supports filtering by name' do
- fill_in 'q[name_or_short_name_cont]', with: calendars.first.name
- click_button 'search_btn'
- expect(page).to have_content(calendars.first.name)
- expect(page).not_to have_content(calendars.last.name)
- end
-
-
- it 'supports filtering by shared' do
- shared_calendar = create :calendar, organisation_id: 1, shared: true
- visit calendars_path
- # select I18n.t('true'), from: 'q[shared]'
- find(:css, '#q_shared_true').set(true)
- click_button 'filter_btn'
- expect(page).to have_content(shared_calendar.short_name)
- expect(page).not_to have_content(calendars.first.short_name)
- end
-
- # wip
- # it 'supports filtering by date' do
- # july_calendar = create :calendar, dates: [Date.new(2017, 7, 7)], date_ranges: [Date.new(2017, 7, 15)..Date.new(2017, 7, 30)], organisation_id: 1
- # visit calendars_path
- # select '7', from: 'q_contains_date_3i'
- # select 'juillet', from: 'q_contains_date_2i'
- # select '2017', from: 'q_contains_date_1i'
- # click_button 'filter_btn'
- # expect(page).to have_content(july_calendar.short_name)
- # expect(page).not_to have_content(calendars.first.short_name)
- # select '18', from: 'q_contains_date_3i'
- # select 'juillet', from: 'q_contains_date_2i'
- # select '2017', from: 'q_contains_date_1i'
- # click_button 'filter_btn'
- # expect(page).to have_content(july_calendar.short_name)
- # expect(page).not_to have_content(calendars.first.short_name)
- # end
- end
- end
-
- describe 'show' do
- it 'displays calendar' do
- visit calendar_path(calendars.first)
- expect(page).to have_content(calendars.first.name)
- end
- end
-
- describe 'create', :wip do
- before do
- visit new_calendar_path
-
- end
- it 'with correct date' do
- require 'pry'
- binding.pry
-
- end
-
- end
-end
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 33d9676cd..6a2b24011 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -42,10 +42,10 @@ RSpec.describe Calendar, :type => :model do
subject { period }
def period(attributes = {})
- return @period if attributes.empty? and @period
- Calendar::Period.new(attributes).tap do |period|
- @period = period if attributes.empty?
- end
+ @__period__ ||= {}
+ @__period__.fetch(attributes){
+ @__period__[attributes] = Calendar::Period.new(attributes)
+ }
end
it 'should support mark_for_destruction (required by cocoon)' do
@@ -125,9 +125,9 @@ RSpec.describe Calendar, :type => :model do
subject { date_value }
def date_value(attributes = {})
- return @date_value if attributes.empty? and @date_value
- Calendar::DateValue.new(attributes).tap do |date_value|
- @date_value = date_value if attributes.empty?
+ @__date_values__ ||= Hash.new
+ @__date_values__.fetch(attributes) do
+ @__date_values__[attributes] = Calendar::DateValue.new(attributes)
end
end
@@ -150,7 +150,9 @@ RSpec.describe Calendar, :type => :model do
expect(date_value(value: '2017-01-03').value).to eq(Date.new(2017,01,03))
end
- it { is_expected.to validate_presence_of(:value) }
+ it 'validates presence' do
+ is_expected.to validate_presence_of(:value)
+ end
end
end
--
cgit v1.2.3
From a96c4bc40b11baf04d95c125aeb53930f64438a3 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 23 Jun 2017 11:14:43 +0200
Subject: VehicleJourney spec: Update .departure_time_between name
I renamed `.departure_time_between` to `.where_departure_time_between`
in 7bf94bc6e6ce6558252252e68419e89a23213573 but didn't update this spec.
Do that now.
---
spec/models/chouette/vehicle_journey_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 8f9080b99..5a142d65d 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -351,7 +351,7 @@ describe Chouette::VehicleJourney, :type => :model do
end
end
- describe ".departure_time_between" do
+ describe ".where_departure_time_between" do
it "selects vehicle journeys whose departure times are between the
specified range" do
journey_early = create(
--
cgit v1.2.3
From 0b40fcc1328fc8ed242ebad436fede48447e87aa Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 23 Jun 2017 11:27:20 +0200
Subject: VehicleJourney.where_departure_time_between: Make end time inclusive
When filtering vehicle journeys by departure time range, include
journeys whose departure times are equal to the end time of the range.
Turns out I made a mistake when copying the range from
`VehicleJourneysController#ransack_periode_filter`. (Here's what it
looked like: 83f143174002ea8d2758d3a3f79fa1b16be9e9eb
between = [:departure_time_gteq, :departure_time_lteq].map do |filter|
)
Add back in the `<=` to the filter.
Refs #3846
---
spec/models/chouette/vehicle_journey_spec.rb | 29 ++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
(limited to 'spec')
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 5a142d65d..599efe683 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -404,6 +404,35 @@ describe Chouette::VehicleJourney, :type => :model do
.to_a
).to eq([journey])
end
+
+ it "uses an inclusive range" do
+ journey_early = create(
+ :vehicle_journey,
+ stop_departure_time: '03:00:00'
+ )
+
+ route = journey_early.route
+ journey_pattern = journey_early.journey_pattern
+
+ journey_late = create(
+ :vehicle_journey,
+ route: route,
+ journey_pattern: journey_pattern,
+ stop_departure_time: '04:00:00'
+ )
+
+ expect(route
+ .vehicle_journeys
+ .select('DISTINCT "vehicle_journeys".*')
+ .joins('
+ LEFT JOIN "vehicle_journey_at_stops"
+ ON "vehicle_journey_at_stops"."vehicle_journey_id" =
+ "vehicle_journeys"."id"
+ ')
+ .where_departure_time_between('03:00', '04:00', allow_empty: true)
+ .to_a
+ ).to eq([journey_early, journey_late])
+ end
end
describe ".without_time_tables" do
--
cgit v1.2.3
From 970954938043d8d73c4457ee2d91e22c0e422e65 Mon Sep 17 00:00:00 2001
From: Robert
Date: Fri, 23 Jun 2017 11:43:56 +0200
Subject: JS for date validation
---
spec/javascripts/calendars/index_spec.coffee | 0
spec/javascripts/spec_helper.coffee | 32 ++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
create mode 100644 spec/javascripts/calendars/index_spec.coffee
create mode 100644 spec/javascripts/spec_helper.coffee
(limited to 'spec')
diff --git a/spec/javascripts/calendars/index_spec.coffee b/spec/javascripts/calendars/index_spec.coffee
new file mode 100644
index 000000000..e69de29bb
diff --git a/spec/javascripts/spec_helper.coffee b/spec/javascripts/spec_helper.coffee
new file mode 100644
index 000000000..9ff516885
--- /dev/null
+++ b/spec/javascripts/spec_helper.coffee
@@ -0,0 +1,32 @@
+# Teaspoon includes some support files, but you can use anything from your own support path too.
+# require support/jasmine-jquery-1.7.0
+# require support/jasmine-jquery-2.0.0
+# require support/jasmine-jquery-2.1.0
+# require support/sinon
+# require support/your-support-file
+#
+# PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
+# Use this polyfill to avoid the confusion.
+#= require support/phantomjs-shims
+#
+# You can require your own javascript files here. By default this will include everything in application, however you
+# may get better load performance if you require the specific files that are being used in the spec that tests them.
+#= require application
+#
+# Deferring execution
+# If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call
+# Teaspoon.execute() after everything has been loaded. Simple example of a timeout:
+#
+# Teaspoon.defer = true
+# setTimeout(Teaspoon.execute, 1000)
+#
+# Matching files
+# By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your
+# spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the
+# configuration in teaspoon_env.rb
+#
+# Manifest
+# If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in
+# the configuration and use this file as a manifest.
+#
+# For more information: http://github.com/modeset/teaspoon
--
cgit v1.2.3
From b7077970a244d00f59ce797ef5b36be774ca3802 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 23 Jun 2017 12:00:50 +0200
Subject: Split factories from chouette_2_factories.rb
Split out all the factories defined in this file into their own separate
files. This helps to make our factories more consistent, so we don't
have a bunch of newer factories in their own files and another bunch of
factories from the early days (presumably) of the application, which are
defined in a single file.
This came about because I was looking for a Referential factory, and was
surprised to not see one defined. Then Xin showed me this grouped
factory file, and I saw that it actually does exist. With this change,
the factories will better match expectations.
---
spec/factories/chouette_2_factories.rb | 80 ------------------------------
spec/factories/compliance_check_results.rb | 8 +++
spec/factories/compliance_check_tasks.rb | 8 +++
spec/factories/export_log_messages.rb | 6 +++
spec/factories/exports.rb | 5 ++
spec/factories/import_tasks.rb | 10 ++++
spec/factories/kml_exports.rb | 5 ++
spec/factories/organisations.rb | 6 +++
spec/factories/referentials.rb | 12 +++++
spec/factories/rule_parameter_sets.rb | 9 ++++
spec/factories/time_table_combinations.rb | 3 ++
spec/factories/users.rb | 10 ++++
spec/factories/vehicle_translations.rb | 6 +++
13 files changed, 88 insertions(+), 80 deletions(-)
delete mode 100644 spec/factories/chouette_2_factories.rb
create mode 100644 spec/factories/compliance_check_results.rb
create mode 100644 spec/factories/compliance_check_tasks.rb
create mode 100644 spec/factories/export_log_messages.rb
create mode 100644 spec/factories/exports.rb
create mode 100644 spec/factories/import_tasks.rb
create mode 100644 spec/factories/kml_exports.rb
create mode 100644 spec/factories/organisations.rb
create mode 100644 spec/factories/referentials.rb
create mode 100644 spec/factories/rule_parameter_sets.rb
create mode 100644 spec/factories/time_table_combinations.rb
create mode 100644 spec/factories/users.rb
create mode 100644 spec/factories/vehicle_translations.rb
(limited to 'spec')
diff --git a/spec/factories/chouette_2_factories.rb b/spec/factories/chouette_2_factories.rb
deleted file mode 100644
index a8e80702d..000000000
--- a/spec/factories/chouette_2_factories.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-# TODO: Move these factories into their own files so all factory definitions are consistent
-FactoryGirl.define do
-
- factory :organisation do
- sequence(:name) { |n| "Organisation #{n}" }
- sequence(:code) { |n| "000#{n}" }
- end
-
- factory :referential do
- sequence(:name) { |n| "Test #{n}" }
- sequence(:slug) { |n| "test_#{n}" }
- sequence(:prefix) { |n| "test_#{n}" }
- association :organisation
- association :workbench
- association :line_referential
- association :stop_area_referential
- time_zone "Europe/Paris"
- end
-
- factory :rule_parameter_set do
- sequence(:name) { |n| "Test #{n}" }
- association :organisation
- after(:create) do |rsp|
- rsp.parameters = RuleParameterSet.default_for_all_modes( rsp.organisation).parameters
- end
- end
-
- factory :user do
- association :organisation
- sequence(:name) { |n| "chouette#{n}" }
- sequence(:username) { |n| "chouette#{n}" }
- sequence(:email) { |n| "chouette#{n}@dryade.priv" }
- password "secret"
- password_confirmation "secret"
- end
-
- factory :import_task do |f|
- user_name "dummy"
- user_id 123
- no_save false
- format "Neptune"
- resources { Rack::Test::UploadedFile.new 'spec/fixtures/neptune.zip', 'application/zip', false }
- referential { Referential.find_by_slug("first") }
- end
-
- factory :kml_export do
- referential { Referential.find_by_slug("first") }
- end
-
- factory :export do
- referential { Referential.find_by_slug("first") }
- end
-
- factory :export_log_message do
- association :export
- sequence(:key) { |n| "key_#{n}" }
- end
-
- factory :vehicle_translation do
- count 1
- duration 1
- end
-
- factory :compliance_check_result do
- association :compliance_check_task
- rule_code "2-NEPTUNE-StopArea-6"
- severity "warning"
- status "nok"
- end
-
- factory :compliance_check_task do
- user_id 1
- user_name "Dummy"
- status "pending"
- referential { Referential.find_by_slug("first") }
- end
-
- factory :time_table_combination
-
-end
diff --git a/spec/factories/compliance_check_results.rb b/spec/factories/compliance_check_results.rb
new file mode 100644
index 000000000..7a3a3e956
--- /dev/null
+++ b/spec/factories/compliance_check_results.rb
@@ -0,0 +1,8 @@
+FactoryGirl.define do
+ factory :compliance_check_result do
+ association :compliance_check_task
+ rule_code "2-NEPTUNE-StopArea-6"
+ severity "warning"
+ status "nok"
+ end
+end
diff --git a/spec/factories/compliance_check_tasks.rb b/spec/factories/compliance_check_tasks.rb
new file mode 100644
index 000000000..e9fdeb5ef
--- /dev/null
+++ b/spec/factories/compliance_check_tasks.rb
@@ -0,0 +1,8 @@
+FactoryGirl.define do
+ factory :compliance_check_task do
+ user_id 1
+ user_name "Dummy"
+ status "pending"
+ referential { Referential.find_by_slug("first") }
+ end
+end
diff --git a/spec/factories/export_log_messages.rb b/spec/factories/export_log_messages.rb
new file mode 100644
index 000000000..849efd7b1
--- /dev/null
+++ b/spec/factories/export_log_messages.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :export_log_message do
+ association :export
+ sequence(:key) { |n| "key_#{n}" }
+ end
+end
diff --git a/spec/factories/exports.rb b/spec/factories/exports.rb
new file mode 100644
index 000000000..34427edb8
--- /dev/null
+++ b/spec/factories/exports.rb
@@ -0,0 +1,5 @@
+FactoryGirl.define do
+ factory :export do
+ referential { Referential.find_by_slug("first") }
+ end
+end
diff --git a/spec/factories/import_tasks.rb b/spec/factories/import_tasks.rb
new file mode 100644
index 000000000..9ca6db899
--- /dev/null
+++ b/spec/factories/import_tasks.rb
@@ -0,0 +1,10 @@
+FactoryGirl.define do
+ factory :import_task do |f|
+ user_name "dummy"
+ user_id 123
+ no_save false
+ format "Neptune"
+ resources { Rack::Test::UploadedFile.new 'spec/fixtures/neptune.zip', 'application/zip', false }
+ referential { Referential.find_by_slug("first") }
+ end
+end
diff --git a/spec/factories/kml_exports.rb b/spec/factories/kml_exports.rb
new file mode 100644
index 000000000..feb86c5b6
--- /dev/null
+++ b/spec/factories/kml_exports.rb
@@ -0,0 +1,5 @@
+FactoryGirl.define do
+ factory :kml_export do
+ referential { Referential.find_by_slug("first") }
+ end
+end
diff --git a/spec/factories/organisations.rb b/spec/factories/organisations.rb
new file mode 100644
index 000000000..239557a0e
--- /dev/null
+++ b/spec/factories/organisations.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :organisation do
+ sequence(:name) { |n| "Organisation #{n}" }
+ sequence(:code) { |n| "000#{n}" }
+ end
+end
diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb
new file mode 100644
index 000000000..dd5bf1c2e
--- /dev/null
+++ b/spec/factories/referentials.rb
@@ -0,0 +1,12 @@
+FactoryGirl.define do
+ factory :referential do
+ sequence(:name) { |n| "Test #{n}" }
+ sequence(:slug) { |n| "test_#{n}" }
+ sequence(:prefix) { |n| "test_#{n}" }
+ association :organisation
+ association :workbench
+ association :line_referential
+ association :stop_area_referential
+ time_zone "Europe/Paris"
+ end
+end
diff --git a/spec/factories/rule_parameter_sets.rb b/spec/factories/rule_parameter_sets.rb
new file mode 100644
index 000000000..e20fff8ce
--- /dev/null
+++ b/spec/factories/rule_parameter_sets.rb
@@ -0,0 +1,9 @@
+FactoryGirl.define do
+ factory :rule_parameter_set do
+ sequence(:name) { |n| "Test #{n}" }
+ association :organisation
+ after(:create) do |rsp|
+ rsp.parameters = RuleParameterSet.default_for_all_modes( rsp.organisation).parameters
+ end
+ end
+end
diff --git a/spec/factories/time_table_combinations.rb b/spec/factories/time_table_combinations.rb
new file mode 100644
index 000000000..364d6460e
--- /dev/null
+++ b/spec/factories/time_table_combinations.rb
@@ -0,0 +1,3 @@
+FactoryGirl.define do
+ factory :time_table_combination
+end
diff --git a/spec/factories/users.rb b/spec/factories/users.rb
new file mode 100644
index 000000000..8f0ec38c0
--- /dev/null
+++ b/spec/factories/users.rb
@@ -0,0 +1,10 @@
+FactoryGirl.define do
+ factory :user do
+ association :organisation
+ sequence(:name) { |n| "chouette#{n}" }
+ sequence(:username) { |n| "chouette#{n}" }
+ sequence(:email) { |n| "chouette#{n}@dryade.priv" }
+ password "secret"
+ password_confirmation "secret"
+ end
+end
diff --git a/spec/factories/vehicle_translations.rb b/spec/factories/vehicle_translations.rb
new file mode 100644
index 000000000..1f0175222
--- /dev/null
+++ b/spec/factories/vehicle_translations.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :vehicle_translation do
+ count 1
+ duration 1
+ end
+end
--
cgit v1.2.3
From 1ba9e1439ec0fce45676aa6eff04d5f9ce12a524 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 23 Jun 2017 16:57:49 +0200
Subject: VehicleJourney spec: Fix "uses an inclusive range" array matcher
I had used `eq` because I was copying the other tests in
`.where_departure_time_between`, but those matched only a single element
inside the array. Here, since we're maching more than one, we need to
use `match_array` in order to disregard the element order.
Didn't notice this at first because it worked on my local machine. In
fact, it continued to work even after several tries. Needed to manually
reverse the element order in order to get the test to fail. Cédric
pointed out that my test was failing on CI.
Refs #3846
---
spec/models/chouette/vehicle_journey_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 599efe683..c78ef5b33 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -431,7 +431,7 @@ describe Chouette::VehicleJourney, :type => :model do
')
.where_departure_time_between('03:00', '04:00', allow_empty: true)
.to_a
- ).to eq([journey_early, journey_late])
+ ).to match_array([journey_early, journey_late])
end
end
--
cgit v1.2.3
From d245c7bc9abab607c6d6e139057dba8ab47a0cec Mon Sep 17 00:00:00 2001
From: Robert
Date: Fri, 23 Jun 2017 17:01:00 +0200
Subject: Fixes: #3605@2h, also refact of models/calendar
---
spec/models/calendar_spec.rb | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
(limited to 'spec')
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 33d9676cd..222e6283f 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -109,15 +109,11 @@ RSpec.describe Calendar, :type => :model do
let(:calendar) { create(:calendar, date_ranges: []) }
it 'shoud fill date_ranges with date ranges' do
- expected_ranges = [
- Range.new(Date.today, Date.tomorrow)
- ]
- expected_ranges.each_with_index do |range, index|
- calendar.date_ranges << Calendar::Period.from_range(index, range)
- end
+ expected_range = Date.today..Date.tomorrow
+ calendar.date_ranges << expected_range
calendar.valid?
- expect(calendar.date_ranges.map { |period| period.begin..period.end }).to eq(expected_ranges)
+ expect(calendar.date_ranges.map { |period| period.begin..period.end }).to eq([expected_range])
end
end
--
cgit v1.2.3
From 6c10034434d5855dfb1e6c5165880b4df0bcf1b4 Mon Sep 17 00:00:00 2001
From: Robert
Date: Mon, 26 Jun 2017 12:41:57 +0200
Subject: spring stubs created (spring stop needed); Fixes: #3874@1h
---
spec/helpers/table_builder_helper_spec.rb | 1 -
1 file changed, 1 deletion(-)
(limited to 'spec')
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 32a6a3bfd..8f4d98c88 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -1,4 +1,3 @@
-require 'spec_helper'
require 'htmlbeautifier'
module TableBuilderHelper
--
cgit v1.2.3
From 083d23585935139b5e87b99bf5cc2a79f4a53cca Mon Sep 17 00:00:00 2001
From: Robert
Date: Tue, 27 Jun 2017 19:58:48 +0200
Subject: Refs: #3595@0.5h live event subscription & smart_date class added to
all date input elements
---
spec/models/calendar/calendar_date_spec.rb | 38 ------------------------------
1 file changed, 38 deletions(-)
delete mode 100644 spec/models/calendar/calendar_date_spec.rb
(limited to 'spec')
diff --git a/spec/models/calendar/calendar_date_spec.rb b/spec/models/calendar/calendar_date_spec.rb
deleted file mode 100644
index 25fe8ba8d..000000000
--- a/spec/models/calendar/calendar_date_spec.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-RSpec.describe Calendar::CalendarDate do
-
- subject { described_class.new(year, month, day) }
- let( :year ){ 2000 }
- let( :month ){ 2 }
-
- let( :str_repr ){ %r{#{year}-0?#{month}-0?#{day}} }
-
-
-
- shared_examples_for "date accessors" do
- it "accesses year" do
- expect( subject.year ).to eq(year)
- end
- it "accesses month" do
- expect( subject.month ).to eq(month)
- end
- it "accesses day" do
- expect( subject.day ).to eq(day)
- end
- it "converts to a string" do
- expect( subject.to_s ).to match(str_repr)
- end
- end
-
- context 'legal' do
- let( :day ){ 29 }
- it { expect_it.to be_legal }
- it_should_behave_like "date accessors"
- end
-
- context 'illegal' do
- let( :day ){ 30 }
- it { expect_it.not_to be_legal }
- it_should_behave_like "date accessors"
- end
-
-end
--
cgit v1.2.3
From d12f72f7fd3853e2cbe49c4a3f9569ba319b3918 Mon Sep 17 00:00:00 2001
From: Robert
Date: Wed, 28 Jun 2017 11:30:43 +0200
Subject: Refs: #3709@0.25h; adapting test to new behavior
---
spec/models/calendar_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'spec')
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index a3da95aca..1dd3bf81d 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -76,7 +76,7 @@ RSpec.describe Calendar, :type => :model do
it 'should validate that end is greather than or equlals to begin' do
expect(period(begin: '2016-11-21', end: '2016-11-22')).to be_valid
- expect(period(begin: '2016-11-21', end: '2016-11-21')).to be_valid
+ expect(period(begin: '2016-11-21', end: '2016-11-21')).to_not be_valid
expect(period(begin: '2016-11-22', end: '2016-11-21')).to_not be_valid
end
--
cgit v1.2.3
From e954f7994d692919492c40b7bce4cce1e0293755 Mon Sep 17 00:00:00 2001
From: Xinhui
Date: Wed, 28 Jun 2017 12:28:41 +0200
Subject: Refactoring time_table#merge Refs #3788
---
spec/models/chouette/time_table_spec.rb | 103 ++++++++++++++++++--------------
1 file changed, 59 insertions(+), 44 deletions(-)
(limited to 'spec')
diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb
index 7a8863cb3..76c5def5c 100644
--- a/spec/models/chouette/time_table_spec.rb
+++ b/spec/models/chouette/time_table_spec.rb
@@ -2,18 +2,74 @@ require 'spec_helper'
describe Chouette::TimeTable, :type => :model do
subject { create(:time_table) }
+ let(:subject_periods_to_range) { subject.periods.map{|p| p.period_start..p.period_end } }
it { is_expected.to validate_presence_of :comment }
it { is_expected.to validate_uniqueness_of :objectid }
- context "merge with calendar" do
- let(:calendar) { create(:calendar) }
+ describe "#merge! with time_table" do
+ let(:another_tt) { create(:time_table) }
+ let(:another_tt_periods_to_range) { another_tt.periods.map{|p| p.period_start..p.period_end } }
+
+ # Make sur we don't have overlapping periods or dates
+ before do
+ another_tt.periods.each do |p|
+ p.period_start = p.period_start + 1.year
+ p.period_end = p.period_end + 1.year
+ end
+ another_tt.dates.each{| d| d.date = d.date + 1.year }
+ end
+
+ it 'should merge dates' do
+ subject.dates.clear
+ subject.merge!(another_tt)
+ expect(subject.dates.map(&:date)).to include(*another_tt.dates.map(&:date))
+ end
+
+ it 'should merge periods' do
+ subject.periods.clear
+ subject.merge!(another_tt)
+
+ expect(subject_periods_to_range).to include(*another_tt_periods_to_range)
+ end
+
+ it 'should not modify int_day_types' do
+ int_day_types = subject.int_day_types
+ subject.merge!(another_tt)
+ expect(subject.int_day_types).to eq int_day_types
+ end
+
+ it 'should merge date in_out false' do
+ another_tt.dates.last.in_out = false
+ another_tt.save
+
+ subject.merge!(another_tt)
+ expect(subject.dates.map(&:date)).to include(another_tt.dates.last.date)
+ end
+ end
+
+ context "#merge! with calendar" do
+ let(:calendar) { create(:calendar, date_ranges: [Date.today + 1.year..Date.tomorrow + 1.year]) }
- it 'should add calendar dates to time_table' do
+ it 'should merge calendar dates' do
subject.dates.clear
subject.merge!(calendar.convert_to_time_table)
expect(subject.dates.map(&:date)).to include(*calendar.dates)
end
+
+ it 'should merge calendar periods with no periods in source' do
+ subject.periods.clear
+ another_tt = calendar.convert_to_time_table
+ subject.merge!(another_tt)
+ expect(subject_periods_to_range).to include(*calendar.date_ranges)
+ end
+
+ it 'should add calendar periods with existing periods in source' do
+ another_tt = calendar.convert_to_time_table
+ subject.merge!(another_tt)
+
+ expect(subject_periods_to_range).to include(*calendar.date_ranges)
+ end
end
describe "actualize" do
@@ -981,47 +1037,6 @@ end
end
end
-
- describe "#merge!" do
- context "timetables have periods with common day_types " do
- before do
- subject.periods.clear
- subject.dates.clear
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,5))
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,6,30), :period_end => Date.new(2014,7,6))
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,16), :in_out => true)
- subject.int_day_types = 4|16|32|128
- another_tt = create(:time_table , :int_day_types => (4|16|64|128) )
- another_tt.periods.clear
- another_tt.dates.clear
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,5), :period_end => Date.new(2014,8,12))
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,7,15), :period_end => Date.new(2014,7,25))
- subject.merge! another_tt
- subject.reload
- end
- it "should have merged periods" do
- expect(subject.periods.size).to eq(3)
- expect(subject.periods[0].period_start).to eq(Date.new(2014, 6, 30))
- expect(subject.periods[0].period_end).to eq(Date.new(2014, 7, 6))
- expect(subject.periods[1].period_start).to eq(Date.new(2014, 7, 15))
- expect(subject.periods[1].period_end).to eq(Date.new(2014, 7, 25))
- expect(subject.periods[2].period_start).to eq(Date.new(2014, 8, 1))
- expect(subject.periods[2].period_end).to eq(Date.new(2014, 8, 12))
- end
- it "should not modify day_types" do
- expect(subject.int_day_types).to eq(4|16|128)
- end
- it "should have dates for thursdays and fridays" do
- expect(subject.dates.size).to eq(4)
- expect(subject.dates[0].date).to eq(Date.new(2014,7,3))
- expect(subject.dates[1].date).to eq(Date.new(2014,7,18))
- expect(subject.dates[2].date).to eq(Date.new(2014,7,25))
- expect(subject.dates[3].date).to eq(Date.new(2014,8,8))
- end
- end
-
- end
-
describe "#intersect!" do
context "timetables have periods with common day_types " do
before do
--
cgit v1.2.3
From 6d3d5d2da94b8c68a0d4930ed2f72c6a016260cb Mon Sep 17 00:00:00 2001
From: jpl
Date: Wed, 28 Jun 2017 14:15:47 +0200
Subject: Refs #3902: fix clearFilter on VJ
---
spec/javascripts/vehicle_journeys/reducers/filters_spec.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'spec')
diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js
index 2ab88386a..0a6729c8b 100644
--- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js
+++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js
@@ -31,7 +31,7 @@ describe('filters reducer', () => {
vehicleJourney: {},
timetable: {},
withoutSchedule: true,
- withoutTimeTable: false
+ withoutTimeTable: true
},
queryString: ''
}
@@ -153,7 +153,7 @@ describe('filters reducer', () => {
"&q%5Bvehicle_journey_at_stops_departure_time_gteq%5D=11%3A11",
"&q%5Bvehicle_journey_at_stops_departure_time_lteq%5D=22%3A22",
"&q%5Bvehicle_journey_without_departure_time%5D=true",
- "&q%5Bvehicle_journey_without_time_table%5D=false"
+ "&q%5Bvehicle_journey_without_time_table%5D=true"
].join('')
expect(
--
cgit v1.2.3
From 74f5fb8bfb960df1bf670324566dc315b91c5291 Mon Sep 17 00:00:00 2001
From: Robert
Date: Wed, 28 Jun 2017 14:57:36 +0200
Subject: Dead Spec Elimination
---
spec/javascripts/calendars/index_spec.coffee | 0
spec/models/calendar_spec.rb | 2 --
2 files changed, 2 deletions(-)
delete mode 100644 spec/javascripts/calendars/index_spec.coffee
(limited to 'spec')
diff --git a/spec/javascripts/calendars/index_spec.coffee b/spec/javascripts/calendars/index_spec.coffee
deleted file mode 100644
index e69de29bb..000000000
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 1dd3bf81d..5d4ae1ed9 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -1,5 +1,3 @@
-require 'rails_helper'
-
RSpec.describe Calendar, :type => :model do
it { should belong_to(:organisation) }
--
cgit v1.2.3
From d704f6433672dbdddc1bdad9ed9bb48a61aaa00b Mon Sep 17 00:00:00 2001
From: Xinhui
Date: Wed, 28 Jun 2017 15:28:35 +0200
Subject: Fix cleanup should only destroy vj without any time_table
Refs #3917
---
spec/factories/clean_ups.rb | 1 +
spec/models/clean_up_spec.rb | 27 +++++++++++++++++++++------
2 files changed, 22 insertions(+), 6 deletions(-)
(limited to 'spec')
diff --git a/spec/factories/clean_ups.rb b/spec/factories/clean_ups.rb
index d3746c3b2..7107769ff 100644
--- a/spec/factories/clean_ups.rb
+++ b/spec/factories/clean_ups.rb
@@ -2,5 +2,6 @@ FactoryGirl.define do
factory :clean_up do
begin_date { Date.today}
end_date { Date.today + 1.month }
+ date_type { :before }
end
end
diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb
index 4b1bf4da9..ee88ca773 100644
--- a/spec/models/clean_up_spec.rb
+++ b/spec/models/clean_up_spec.rb
@@ -191,7 +191,7 @@ RSpec.describe CleanUp, :type => :model do
context '#destroy_time_tables' do
let!(:time_table) { create(:time_table) }
- let(:cleaner) { create(:clean_up, date_type: :before) }
+ let(:cleaner) { create(:clean_up) }
it 'should destroy all time_tables' do
expect{cleaner.destroy_time_tables(Chouette::TimeTable.all)}.to change {
@@ -199,11 +199,26 @@ RSpec.describe CleanUp, :type => :model do
}.by(-1)
end
- it 'should destroy associated vehicle_journeys' do
- create(:vehicle_journey, time_tables: [time_table])
- expect{cleaner.destroy_time_tables(Chouette::TimeTable.all)}.to change {
- Chouette::VehicleJourney.count
- }.by(-1)
+ it 'should destroy time_table vehicle_journey association' do
+ vj = create(:vehicle_journey, time_tables: [time_table])
+ cleaner.destroy_time_tables(Chouette::TimeTable.all)
+ expect(vj.reload.time_tables).to be_empty
+ end
+ end
+
+ context '#destroy_vehicle_journey_without_time_table' do
+ let(:cleaner) { create(:clean_up) }
+
+ it 'should destroy vehicle_journey' do
+ vj = create(:vehicle_journey)
+ expect{cleaner.destroy_vehicle_journey_without_time_table
+ }.to change { Chouette::VehicleJourney.count }.by(-1)
+ end
+
+ it 'should not destroy vehicle_journey with time_table' do
+ create(:vehicle_journey, time_tables: [create(:time_table)])
+ expect{cleaner.destroy_vehicle_journey_without_time_table
+ }.to_not change { Chouette::VehicleJourney.count }
end
end
--
cgit v1.2.3
From ead1b30f0c38c247e6d80a32a894bfd9af4c2566 Mon Sep 17 00:00:00 2001
From: Robert
Date: Wed, 28 Jun 2017 15:35:37 +0200
Subject: Small refact and simplification of calendar model spex
---
spec/models/calendar/date_value_spec.rb | 35 +++++++++++++++++
spec/models/calendar/period_spec.rb | 68 +++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+)
create mode 100644 spec/models/calendar/date_value_spec.rb
create mode 100644 spec/models/calendar/period_spec.rb
(limited to 'spec')
diff --git a/spec/models/calendar/date_value_spec.rb b/spec/models/calendar/date_value_spec.rb
new file mode 100644
index 000000000..70dca3cc6
--- /dev/null
+++ b/spec/models/calendar/date_value_spec.rb
@@ -0,0 +1,35 @@
+RSpec.describe Calendar::DateValue, type: :model do
+ describe 'DateValue' do
+ subject { date_value }
+
+ def date_value(attributes = {})
+ @__date_values__ ||= Hash.new
+ @__date_values__.fetch(attributes) do
+ @__date_values__[attributes] = Calendar::DateValue.new(attributes)
+ end
+ end
+
+ it 'should support mark_for_destruction (required by cocoon)' do
+ date_value.mark_for_destruction
+ expect(date_value).to be_marked_for_destruction
+ end
+
+ it 'should support _destroy attribute (required by coocon)' do
+ date_value._destroy = true
+ expect(date_value).to be_marked_for_destruction
+ end
+
+ it 'should support new_record? (required by cocoon)' do
+ expect(Calendar::DateValue.new).to be_new_record
+ expect(date_value(id: 42)).not_to be_new_record
+ end
+
+ it 'should cast value as date attribute' do
+ expect(date_value(value: '2017-01-03').value).to eq(Date.new(2017,01,03))
+ end
+
+ it 'validates presence' do
+ is_expected.to validate_presence_of(:value)
+ end
+ end
+end
diff --git a/spec/models/calendar/period_spec.rb b/spec/models/calendar/period_spec.rb
new file mode 100644
index 000000000..233733cbf
--- /dev/null
+++ b/spec/models/calendar/period_spec.rb
@@ -0,0 +1,68 @@
+RSpec.describe Calendar::Period, type: :model do
+
+
+ subject { period }
+
+ def period(attributes = {})
+ @__period__ ||= {}
+ @__period__.fetch(attributes){
+ @__period__[attributes] = Calendar::Period.new(attributes)
+ }
+ end
+
+ it 'should support mark_for_destruction (required by cocoon)' do
+ period.mark_for_destruction
+ expect(period).to be_marked_for_destruction
+ end
+
+ it 'should support _destroy attribute (required by coocon)' do
+ period._destroy = true
+ expect(period).to be_marked_for_destruction
+ end
+
+ it 'should support new_record? (required by cocoon)' do
+ expect(Calendar::Period.new).to be_new_record
+ expect(period(id: 42)).not_to be_new_record
+ end
+
+ it 'should cast begin as date attribute' do
+ expect(period(begin: '2016-11-22').begin).to eq(Date.new(2016,11,22))
+ end
+
+ it 'should cast end as date attribute' do
+ expect(period(end: '2016-11-22').end).to eq(Date.new(2016,11,22))
+ end
+
+ it { is_expected.to validate_presence_of(:begin) }
+ it { is_expected.to validate_presence_of(:end) }
+
+ it 'should validate that end is greather than or equlals to begin' do
+ expect(period(begin: '2016-11-21', end: '2016-11-22')).to be_valid
+ expect(period(begin: '2016-11-21', end: '2016-11-21')).to_not be_valid
+ expect(period(begin: '2016-11-22', end: '2016-11-21')).to_not be_valid
+ end
+
+ describe 'intersect?' do
+ it 'should detect date in common with other date_ranges' do
+ november = period(begin: '2016-11-01', end: '2016-11-30')
+ mid_november_mid_december = period(begin: '2016-11-15', end: '2016-12-15')
+ expect(november.intersect?(mid_november_mid_december)).to be(true)
+ end
+
+ it 'should not intersect when no date is in common' do
+ november = period(begin: '2016-11-01', end: '2016-11-30')
+ december = period(begin: '2016-12-01', end: '2016-12-31')
+
+ expect(november.intersect?(december)).to be(false)
+
+ january = period(begin: '2017-01-01', end: '2017-01-31')
+ expect(november.intersect?(december, january)).to be(false)
+ end
+
+ it 'should not intersect itself' do
+ period = period(id: 42, begin: '2016-11-01', end: '2016-11-30')
+ expect(period.intersect?(period)).to be(false)
+ end
+
+ end
+end
--
cgit v1.2.3
From fa5bf7d280662be42531c4f1ea2f458e9981f8fa Mon Sep 17 00:00:00 2001
From: Robert
Date: Wed, 28 Jun 2017 15:35:40 +0200
Subject: Small refact and simplification of calendar model spex
---
spec/models/calendar_spec.rb | 111 +------------------------------------------
1 file changed, 2 insertions(+), 109 deletions(-)
(limited to 'spec')
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 5d4ae1ed9..cf7e4aa27 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -21,87 +21,14 @@ RSpec.describe Calendar, :type => :model do
describe 'validations' do
it 'validates that dates and date_ranges do not overlap' do
- calendar = build(:calendar, dates: [Date.today], date_ranges: [Date.today..Date.tomorrow])
- expect {
- calendar.save!
- }.to raise_error(ActiveRecord::RecordInvalid)
+ expect(build(:calendar, dates: [Date.today], date_ranges: [Date.today..Date.tomorrow])).to_not be_valid
end
it 'validates that there are no duplicates in dates' do
- calendar = build(:calendar, dates: [Date.yesterday, Date.yesterday], date_ranges: [Date.today..Date.tomorrow])
- expect {
- calendar.save!
- }.to raise_error(ActiveRecord::RecordInvalid)
+ expect(build(:calendar, dates: [Date.yesterday, Date.yesterday], date_ranges: [Date.today..Date.tomorrow])).to_not be_valid
end
end
- describe 'Period' do
-
- subject { period }
-
- def period(attributes = {})
- @__period__ ||= {}
- @__period__.fetch(attributes){
- @__period__[attributes] = Calendar::Period.new(attributes)
- }
- end
-
- it 'should support mark_for_destruction (required by cocoon)' do
- period.mark_for_destruction
- expect(period).to be_marked_for_destruction
- end
-
- it 'should support _destroy attribute (required by coocon)' do
- period._destroy = true
- expect(period).to be_marked_for_destruction
- end
-
- it 'should support new_record? (required by cocoon)' do
- expect(Calendar::Period.new).to be_new_record
- expect(period(id: 42)).not_to be_new_record
- end
-
- it 'should cast begin as date attribute' do
- expect(period(begin: '2016-11-22').begin).to eq(Date.new(2016,11,22))
- end
-
- it 'should cast end as date attribute' do
- expect(period(end: '2016-11-22').end).to eq(Date.new(2016,11,22))
- end
-
- it { is_expected.to validate_presence_of(:begin) }
- it { is_expected.to validate_presence_of(:end) }
-
- it 'should validate that end is greather than or equlals to begin' do
- expect(period(begin: '2016-11-21', end: '2016-11-22')).to be_valid
- expect(period(begin: '2016-11-21', end: '2016-11-21')).to_not be_valid
- expect(period(begin: '2016-11-22', end: '2016-11-21')).to_not be_valid
- end
-
- describe 'intersect?' do
- it 'should detect date in common with other date_ranges' do
- november = period(begin: '2016-11-01', end: '2016-11-30')
- mid_november_mid_december = period(begin: '2016-11-15', end: '2016-12-15')
- expect(november.intersect?(mid_november_mid_december)).to be(true)
- end
-
- it 'should not intersect when no date is in common' do
- november = period(begin: '2016-11-01', end: '2016-11-30')
- december = period(begin: '2016-12-01', end: '2016-12-31')
-
- expect(november.intersect?(december)).to be(false)
-
- january = period(begin: '2017-01-01', end: '2017-01-31')
- expect(november.intersect?(december, january)).to be(false)
- end
-
- it 'should not intersect itself' do
- period = period(id: 42, begin: '2016-11-01', end: '2016-11-30')
- expect(period.intersect?(period)).to be(false)
- end
-
- end
- end
describe 'before_validation' do
let(:calendar) { create(:calendar, date_ranges: []) }
@@ -115,38 +42,4 @@ RSpec.describe Calendar, :type => :model do
end
end
- describe 'DateValue' do
- subject { date_value }
-
- def date_value(attributes = {})
- @__date_values__ ||= Hash.new
- @__date_values__.fetch(attributes) do
- @__date_values__[attributes] = Calendar::DateValue.new(attributes)
- end
- end
-
- it 'should support mark_for_destruction (required by cocoon)' do
- date_value.mark_for_destruction
- expect(date_value).to be_marked_for_destruction
- end
-
- it 'should support _destroy attribute (required by coocon)' do
- date_value._destroy = true
- expect(date_value).to be_marked_for_destruction
- end
-
- it 'should support new_record? (required by cocoon)' do
- expect(Calendar::DateValue.new).to be_new_record
- expect(date_value(id: 42)).not_to be_new_record
- end
-
- it 'should cast value as date attribute' do
- expect(date_value(value: '2017-01-03').value).to eq(Date.new(2017,01,03))
- end
-
- it 'validates presence' do
- is_expected.to validate_presence_of(:value)
- end
- end
end
-
--
cgit v1.2.3