From 221eeaa299abe3551ae3443d56e0436ece903569 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 16 Dec 2015 19:05:42 +0100 Subject: [PATCH 1/5] tests for annotation text instead of id --- spec/features/legislation_spec.rb | 32 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/spec/features/legislation_spec.rb b/spec/features/legislation_spec.rb index 13a4b76b9..d555d0bb3 100644 --- a/spec/features/legislation_spec.rb +++ b/spec/features/legislation_spec.rb @@ -27,32 +27,36 @@ feature 'Legislation' do fill_in 'annotator-field-0', with: 'this is my annotation' page.find(:css, ".annotator-controls a[href='#save']").click - expect(page).to have_css ".annotator-hl[data-annotation-id]" + expect(page).to have_css ".annotator-hl" + first(:css, ".annotator-hl").click + expect(page).to have_content "this is my annotation" visit legislation_path(legislation) - expect(page).to have_css ".annotator-hl[data-annotation-id]" + expect(page).to have_css ".annotator-hl" + first(:css, ".annotator-hl").click + expect(page).to have_content "this is my annotation" end scenario 'Update' do legislation = create(:legislation, body: "In order to achieve...") - create(:annotation, user: user, legislation: legislation, text: "this one" , quote: "In order to achieve...", ranges: [{"start"=>"/div[2]", "startOffset"=>12, "end"=>"/div[2]", "endOffset"=>19}]) + annotation = create(:annotation, legislation: legislation, text: "my annotation" , quote: "In order to achieve...", ranges: [{"start"=>"/div[2]", "startOffset"=>12, "end"=>"/div[2]", "endOffset"=>19}]) visit legislation_path(legislation) page.find(:css, ".annotator-hl").click page.find(:css, ".annotator-edit").click - fill_in 'annotator-field-0', with: 'editing my annotation' + fill_in 'annotator-field-0', with: 'edited annotation' page.find(:css, ".annotator-controls a[href='#save']").click page.find(:css, ".annotator-hl").click - expect(page).to have_css ".annotator-item", text: 'editing my annotation' + expect(page).to have_content "edited annotation" visit legislation_path(legislation) page.find(:css, ".annotator-hl").click - expect(page).to have_css ".annotator-item", text: 'editing my annotation' + expect(page).to have_content "edited annotation" end scenario 'Destroy' do @@ -61,23 +65,27 @@ feature 'Legislation' do visit legislation_path(legislation) - expect(page).to have_css ".annotator-hl[data-annotation-id='#{annotation.id}']" + expect(page).to have_css ".annotator-hl" page.find(:css, ".annotator-hl").click page.find(:css, ".annotator-delete").click - expect(page).to_not have_css ".annotator-hl[data-annotation-id='#{annotation.id}']" + expect(page).to_not have_css ".annotator-hl" end scenario 'Search' do legislation = create(:legislation, body: "In order to achieve...") - annotation1 = create(:annotation, legislation: legislation, text: "this one" , quote: "achieve", ranges: [{"start"=>"/div[2]", "startOffset"=>12, "end"=>"/div[2]", "endOffset"=>19}]) - annotation2 = create(:annotation, legislation: legislation, text: "this one" , quote: "achieve", ranges: [{"start"=>"/div[2]", "startOffset"=>5, "end"=>"/div[2]", "endOffset"=>10}]) + annotation1 = create(:annotation, legislation: legislation, text: "my annotation" , quote: "achieve", ranges: [{"start"=>"/div[2]", "startOffset"=>5, "end"=>"/div[2]", "endOffset"=>10}]) + annotation2 = create(:annotation, legislation: legislation, text: "my other annotation" , quote: "achieve", ranges: [{"start"=>"/div[2]", "startOffset"=>12, "end"=>"/div[2]", "endOffset"=>19}]) visit legislation_path(legislation) - expect(page).to have_css ".annotator-hl[data-annotation-id='#{annotation1.id}']" - expect(page).to have_css ".annotator-hl[data-annotation-id='#{annotation2.id}']" + expect(page).to have_css ".annotator-hl" + first(:css, ".annotator-hl").click + expect(page).to have_content "my annotation" + + all(".annotator-hl")[1].click + expect(page).to have_content "my other annotation" end end From 89896a94ee1605182c43de759403ca175d37144d Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 16 Dec 2015 19:10:59 +0100 Subject: [PATCH 2/5] renames legislation body id --- app/views/legislations/show.html.erb | 2 +- spec/features/legislation_spec.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/legislations/show.html.erb b/app/views/legislations/show.html.erb index 6c4c75be0..54c91fbf9 100644 --- a/app/views/legislations/show.html.erb +++ b/app/views/legislations/show.html.erb @@ -2,6 +2,6 @@ data-annotatable-id="<%= @legislation.id %>">
<%= @legislation.title %>
-
<%= @legislation.body %>
+
<%= @legislation.body %>
diff --git a/spec/features/legislation_spec.rb b/spec/features/legislation_spec.rb index d555d0bb3..b3704260d 100644 --- a/spec/features/legislation_spec.rb +++ b/spec/features/legislation_spec.rb @@ -21,9 +21,8 @@ feature 'Legislation' do visit legislation_path(legislation) - page.find(:css, "#test").double_click + page.find(:css, "#legislation_body").double_click page.find(:css, ".annotator-adder button").click - fill_in 'annotator-field-0', with: 'this is my annotation' page.find(:css, ".annotator-controls a[href='#save']").click From ba8742d1b50570241035e65a24132e8500ae355e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 16 Dec 2015 19:18:41 +0100 Subject: [PATCH 3/5] moves default annotation range to factory --- spec/factories.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/factories.rb b/spec/factories.rb index 61c09373e..862fa4e84 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -230,6 +230,7 @@ FactoryGirl.define do factory :annotation do quote "ipsum" text "Loremp ipsum dolor" + ranges [{"start"=>"/div[2]", "startOffset"=>5, "end"=>"/div[2]", "endOffset"=>10}] legislation user end From 5a6a915a1b2aa99c3069fc29abf4f85513056c00 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 16 Dec 2015 19:19:04 +0100 Subject: [PATCH 4/5] removes unused test code --- spec/features/legislation_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/features/legislation_spec.rb b/spec/features/legislation_spec.rb index b3704260d..db38f14a6 100644 --- a/spec/features/legislation_spec.rb +++ b/spec/features/legislation_spec.rb @@ -17,7 +17,7 @@ feature 'Legislation' do background { login_as user } scenario 'Create' do - legislation = create(:legislation, body: "In order to achieve...") + legislation = create(:legislation) visit legislation_path(legislation) @@ -38,8 +38,8 @@ feature 'Legislation' do end scenario 'Update' do - legislation = create(:legislation, body: "In order to achieve...") - annotation = create(:annotation, legislation: legislation, text: "my annotation" , quote: "In order to achieve...", ranges: [{"start"=>"/div[2]", "startOffset"=>12, "end"=>"/div[2]", "endOffset"=>19}]) + legislation = create(:legislation) + annotation = create(:annotation, legislation: legislation, text: "my annotation") visit legislation_path(legislation) @@ -59,8 +59,8 @@ feature 'Legislation' do end scenario 'Destroy' do - legislation = create(:legislation, body: "In order to achieve...") - annotation = create(:annotation, user: user, legislation: legislation, text: "this one" , quote: "achieve", ranges: [{"start"=>"/div[2]", "startOffset"=>12, "end"=>"/div[2]", "endOffset"=>19}]) + legislation = create(:legislation) + annotation = create(:annotation, legislation: legislation) visit legislation_path(legislation) @@ -73,9 +73,9 @@ feature 'Legislation' do end scenario 'Search' do - legislation = create(:legislation, body: "In order to achieve...") - annotation1 = create(:annotation, legislation: legislation, text: "my annotation" , quote: "achieve", ranges: [{"start"=>"/div[2]", "startOffset"=>5, "end"=>"/div[2]", "endOffset"=>10}]) - annotation2 = create(:annotation, legislation: legislation, text: "my other annotation" , quote: "achieve", ranges: [{"start"=>"/div[2]", "startOffset"=>12, "end"=>"/div[2]", "endOffset"=>19}]) + legislation = create(:legislation) + annotation1 = create(:annotation, legislation: legislation, text: "my annotation", ranges: [{"start"=>"/div[2]", "startOffset"=>5, "end"=>"/div[2]", "endOffset"=>10}]) + annotation2 = create(:annotation, legislation: legislation, text: "my other annotation", ranges: [{"start"=>"/div[2]", "startOffset"=>12, "end"=>"/div[2]", "endOffset"=>19}]) visit legislation_path(legislation) @@ -91,4 +91,4 @@ feature 'Legislation' do end -## Notes logged in and not logged in users +## Notes logged in and not logged in users \ No newline at end of file From c2eadd47ad6ad93b97493d3b01194bcdf9614aa2 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 16 Dec 2015 19:46:17 +0100 Subject: [PATCH 5/5] fixes specs --- spec/features/legislation_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/legislation_spec.rb b/spec/features/legislation_spec.rb index db38f14a6..1bafb974e 100644 --- a/spec/features/legislation_spec.rb +++ b/spec/features/legislation_spec.rb @@ -39,7 +39,7 @@ feature 'Legislation' do scenario 'Update' do legislation = create(:legislation) - annotation = create(:annotation, legislation: legislation, text: "my annotation") + annotation = create(:annotation, legislation: legislation, user: user, text: "my annotation") visit legislation_path(legislation) @@ -60,7 +60,7 @@ feature 'Legislation' do scenario 'Destroy' do legislation = create(:legislation) - annotation = create(:annotation, legislation: legislation) + annotation = create(:annotation, legislation: legislation, user: user) visit legislation_path(legislation)