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(has_no_selector?(".modal-dialog-preview-pane"),
23 "preview pane available in sharing dialog")
24 if share_type == 'users' and obj and obj['email']
25 assert(page.has_text?(obj['email']), "Did not find user's email")
27 assert_raises(Capybara::ElementNotFound,
28 "Projects pulldown available from sharing dialog") do
29 click_on "All projects"
33 using_wait_time(Capybara.default_wait_time * 3) do
34 assert(page.has_link?(name),
35 "new share was not added to sharing table")
36 assert_equal(start_share_count + 1, share_rows.size,
37 "new share did not add row to sharing table")
41 def modify_share_and_check(name)
42 start_rows = share_rows
43 link_row = start_rows.select { |row| row.has_text?(name) }
44 assert_equal(1, link_row.size, "row with new permission not found")
45 within(link_row.first) do
47 select("Write", from: "share_change_level")
48 click_on("editable-submit")
49 assert(has_link?("Write"),
50 "failed to change access level on new share")
52 if Capybara.current_driver == :selenium
53 page.driver.browser.switch_to.alert.accept
55 # poltergeist returns true for confirm(), so we don't need to accept.
58 # Ensure revoked permission disappears from page.
59 using_wait_time(Capybara.default_wait_time * 3) do
61 assert_equal(start_rows.size - 1, share_rows.size,
62 "revoking share did not remove row from sharing table")
66 def user_can_manage(user_sym, fixture)
67 get(:show, {id: fixture["uuid"]}, session_for(user_sym))
68 is_manager = assigns(:user_is_manager)
69 assert_not_nil(is_manager, "user_is_manager flag not set")
71 assert_empty(assigns(:share_links),
72 "non-manager has share links set")