1 module ShareObjectHelper
2 def show_object_using(auth_key, type, key, expect)
3 obj_uuid = api_fixture(type)[key]['uuid']
4 visit(page_with_token(auth_key, "/#{type}/#{obj_uuid}"))
5 assert(page.has_text?(expect), "expected string not found: #{expect}")
9 find('#object_sharing').all('tr')
12 def add_share_and_check(share_type, name, obj=nil)
13 assert(page.has_no_text?(name), "project is already shared with #{name}")
14 start_share_count = share_rows.size
15 click_on("Share with #{share_type}")
16 within(".modal-container") do
17 # Order is important here: we should find something that appears in the
18 # modal before we make any assertions about what's not in the modal.
19 # Otherwise, the not-included assertions might falsely pass because
20 # the modal hasn't loaded yet.
21 find(".selectable", text: name).click
22 assert_text "Only #{share_type} you are allowed to access are shown"
23 assert(has_no_selector?(".modal-dialog-preview-pane"),
24 "preview pane available in sharing dialog")
25 if share_type == 'users' and obj and obj['email']
26 assert(page.has_text?(obj['email']), "Did not find user's email")
28 assert_raises(Capybara::ElementNotFound,
29 "Projects pulldown available from sharing dialog") do
30 click_on "All projects"
34 using_wait_time(Capybara.default_max_wait_time * 3) do
35 assert(page.has_link?(name),
36 "new share was not added to sharing table")
37 assert_equal(start_share_count + 1, share_rows.size,
38 "new share did not add row to sharing table")
42 def modify_share_and_check(name)
43 start_rows = share_rows
44 link_row = start_rows.select { |row| row.has_text?(name) }
45 assert_equal(1, link_row.size, "row with new permission not found")
46 within(link_row.first) do
48 select("Write", from: "share_change_level")
49 click_on("editable-submit")
50 assert(has_link?("Write"),
51 "failed to change access level on new share")
53 if Capybara.current_driver == :selenium
54 page.driver.browser.switch_to.alert.accept
56 # poltergeist returns true for confirm(), so we don't need to accept.
59 # Ensure revoked permission disappears from page.
60 using_wait_time(Capybara.default_max_wait_time * 3) do
62 assert_equal(start_rows.size - 1, share_rows.size,
63 "revoking share did not remove row from sharing table")
67 def user_can_manage(user_sym, fixture)
68 get(:show, {id: fixture["uuid"]}, session_for(user_sym))
69 is_manager = assigns(:user_is_manager)
70 assert_not_nil(is_manager, "user_is_manager flag not set")
72 assert_empty(assigns(:share_links),
73 "non-manager has share links set")