-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'circular_subcollections' of github.com:innoq/iqvoc into…
… circular_subcollections
- Loading branch information
Showing
9 changed files
with
153 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,37 @@ | ||
require 'test_helper' | ||
require 'integration_test_helper' | ||
|
||
class CollectionCircularityTest < ActionDispatch::IntegrationTest | ||
@@klass = Iqvoc::Collection.base_class | ||
|
||
setup do | ||
# create a user | ||
password = "FooBar" | ||
user = User.new(:forename => "John", :surname => "Doe", | ||
:email => "foo@example.org", | ||
:password => password, :password_confirmation => password, | ||
:active => true, :role => "administrator") | ||
user.save | ||
|
||
auth = Base64::encode64("%s:%s" % [user.email, user.password]) | ||
@env = { "HTTP_AUTHORIZATION" => "Basic " + auth } | ||
end | ||
|
||
test "circular sub-collection references are rejected during update" do | ||
coll1 = @@klass.new | ||
coll1.save | ||
coll2 = @@klass.new | ||
coll2.save | ||
coll1 = Factory.create(:collection) | ||
coll2 = Factory.create(:collection) | ||
|
||
login("administrator") | ||
|
||
# add coll2 as subcollection of coll1 | ||
uri = collection_path(:id => coll1.origin, :lang => "de", :format => "html") | ||
params = { "concept[inline_member_collection_origins]" => "%s," % coll2.origin } | ||
put_via_redirect uri, params, @env | ||
visit edit_collection_path(coll1, :lang => "de", :format => "html") | ||
fill_in "concept_inline_member_collection_origins", | ||
:with => "%s," % coll2.origin | ||
click_button "Speichern" | ||
|
||
assert_response :success | ||
assert_equal 1, @@klass.by_origin(coll1.origin).first.subcollections.count | ||
assert page.has_no_css?(".flash_error") | ||
assert page.has_content?(I18n.t("txt.controllers.collections.save.success")) | ||
assert page.has_link?(coll2.label.to_s, | ||
:href => collection_path(coll2, :lang => "de", :format => "html")) | ||
|
||
# add coll1 as subcollection of coll2 | ||
uri = collection_path(:id => coll2.origin, :lang => "de", :format => "html") | ||
params = { "concept[inline_member_collection_origins]" => coll1.origin } | ||
put_via_redirect uri, params, @env | ||
|
||
assert_response :success | ||
assert_equal 0, @@klass.by_origin(coll2.origin).first.subcollections.count | ||
assert_equal flash[:error], I18n.t("txt.controllers.collections.circular_error") % coll1.label | ||
visit edit_collection_path(coll2, :lang => "de", :format => "html") | ||
fill_in "concept_inline_member_collection_origins", | ||
:with => "%s," % coll1.origin | ||
click_button "Speichern" | ||
|
||
assert page.has_css?(".flash_error") | ||
assert page.has_css?("#concept_edit") | ||
assert page.source.include?( # XXX: page.has_content? didn't work | ||
I18n.t("txt.controllers.collections.circular_error") % coll1.label) | ||
|
||
# ensure coll1 is not a subcollection of coll2 | ||
visit collection_path(coll2, :lang => "de", :format => "html") | ||
assert page.has_no_link?(coll1.label.to_s) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require 'test_helper' | ||
require 'integration_test_helper' | ||
|
||
|
||
class SearchTest < ActionDispatch::IntegrationTest | ||
|
||
setup do | ||
# create a few XL labels | ||
labels = {} | ||
{ | ||
"terra" => "la", | ||
"earth" => "en", | ||
"Erde" => "de", | ||
"sol" => "la", | ||
"sun" => "en", | ||
"Sonne" => "de", | ||
"inhabited" => "en", | ||
"bewohnt" => "de", | ||
"uninhabited" => "en", | ||
"unbewohnt" => "de" | ||
}.map { |name, lang| | ||
label = Factory.create(:xllabel, :origin => "_%s" % name, | ||
:language => lang, :value => name, :published_at => Time.now) | ||
labels[name] = label | ||
} | ||
|
||
# create a few concepts | ||
[ | ||
["Erde", "earth"], | ||
["Sonne", "sun"] | ||
].each { |pref, alt| | ||
concept = Factory.create(:concept, :origin => "_%s" % pref, | ||
:labelings => [], :narrower_relations => [], # avoid creating additional concepts/label[ing]s | ||
:published_at => Time.now) | ||
Factory.create(:pref_labeling, :owner => concept, :target => labels[pref]) | ||
Factory.create(:alt_labeling, :owner => concept, :target => labels[alt]) | ||
} | ||
|
||
# create a few collections | ||
[ | ||
["bewohnt", "inhabited"], | ||
["unbewohnt", "uninhabited"] | ||
].each { |pref, alt| | ||
collection = Factory.create(:collection) | ||
Factory.create(:pref_labeling, :owner => collection, :target => labels[pref]) | ||
Factory.create(:alt_labeling, :owner => collection, :target => labels[alt]) | ||
} | ||
|
||
# confirm environment, just to be safe (i.e. ensure that factories, | ||
# for example, don't introduce unexpected side-effects) | ||
assert_equal 10, Label::Base.all.count | ||
assert_equal 8, Labeling::Base.all.count | ||
assert_equal 2, Iqvoc::Concept.base_class.all.count | ||
assert_equal 2, Iqvoc::Collection.base_class.all.count | ||
assert_equal 4, Concept::Base.all.count | ||
end | ||
|
||
test "HTML search returns matches" do | ||
uri = search_path(:lang => "de", :format => "html") | ||
uri += "?l[]=de&l[]=en" # doesn't fit into params hash | ||
params = { | ||
"q" => "Erde", | ||
"qt" => "exact", # match type | ||
"t" => "all", # search type | ||
"c" => "" # collection | ||
} | ||
params.each { |key, value| | ||
uri += "&%s=%s" % [key, value] # XXX: hacky and brittle (e.g. lack of URL-encoding) | ||
} | ||
|
||
visit uri | ||
|
||
assert page.has_css?("#search_results dt", :count => 1) | ||
end | ||
|
||
test "RDF search returns matches" do | ||
uri = search_path(:lang => "de", :format => "rdf") | ||
uri += "?l[]=de&l[]=en" # doesn't fit into params hash | ||
params = { | ||
"q" => "Erde", | ||
"qt" => "exact", # match type | ||
"t" => "all", # search type | ||
"c" => "" # collection | ||
} | ||
get uri, params | ||
|
||
assert_match /<sdc:result rdf:resource.*#result1"\/>/, @response.body | ||
assert_no_match /#result2"\/>/, @response.body | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters