-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
flaggable.rb
111 lines (84 loc) · 2.82 KB
/
flaggable.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
shared_examples "flaggable" do |factory_name, admin: false|
include ActionView::RecordIdentifier
let(:flaggable) { create(factory_name) }
let(:user) do
if admin
create(:administrator).user
else
create(:user, :level_two)
end
end
let(:path) do
if flaggable.is_a?(Comment)
polymorphic_path(flaggable.commentable)
elsif admin
admin_polymorphic_path(flaggable)
else
polymorphic_path(flaggable)
end
end
scenario "Flagging as inappropriate" do
login_as(user)
visit path
within "##{dom_id(flaggable)} .flag-content" do
click_button "Flag as inappropriate"
click_link "Flag as inappropriate"
expect(page).to have_button "Unflag"
expect(page).to have_link "Unflag", visible: :hidden
expect(page).not_to have_link "Flag as inappropriate", visible: :all
end
visit path
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_link "Unflag", visible: :hidden
expect(page).not_to have_link "Flag as inappropriate", visible: :all
end
end
scenario "Unflagging" do
Flag.flag(user, flaggable)
login_as(user)
visit path
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_button "Unflag"
click_button "Unflag"
click_link "Unflag"
expect(page).not_to have_button "Unflag"
expect(page).to have_link "Flag as inappropriate", visible: :hidden
expect(page).not_to have_link "Unflag", visible: :all
end
visit path
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_link "Flag as inappropriate", visible: :hidden
expect(page).not_to have_link "Unflag", visible: :all
end
end
scenario "Flagging and unflagging" do
login_as(user)
visit path
within "##{dom_id(flaggable)} .flag-content" do
click_button "Flag as inappropriate"
click_link "Flag as inappropriate"
expect(page).to have_button "Unflag"
click_button "Unflag"
click_link "Unflag"
expect(page).not_to have_button "Unflag"
end
visit path
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_link "Flag as inappropriate", visible: :hidden
expect(page).not_to have_link "Unflag", visible: :all
end
end
scenario "Flagging a comment with a child does not update its children", if: factory_name =~ /comment/ do
child_comment = create(:comment, commentable: flaggable.commentable, parent: flaggable)
login_as(user)
visit path
within "##{dom_id(flaggable)} > .comment-body .flag-content" do
click_button "Flag as inappropriate"
click_link "Flag as inappropriate"
expect(page).to have_button "Unflag"
end
within "##{dom_id(child_comment)} .flag-content" do
expect(page).not_to have_button "Unflag"
end
end
end