-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
actions_spec.rb
114 lines (88 loc) · 2.97 KB
/
actions_spec.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
112
113
114
require "rails_helper"
describe "Admin dashboard actions", :admin do
it_behaves_like "nested documentable",
"administrator",
"dashboard_action",
"new_admin_dashboard_action_path",
{},
"documentable_fill_new_valid_dashboard_action",
"Save",
"Action created successfully"
context "when visiting index" do
context "and no actions defined" do
before do
visit admin_dashboard_actions_path
end
scenario "shows only default actions" do
expect(page).to have_content("Polls")
expect(page).to have_content("Email")
expect(page).to have_content("Poster")
expect(page).to have_link "Edit", count: 3
end
end
context "and actions defined" do
let!(:action) { create :dashboard_action }
before do
visit admin_dashboard_actions_path
end
scenario "shows the action data" do
expect(page).to have_content(action.title)
end
end
end
context "when creating an action" do
let(:action) { build :dashboard_action }
before do
visit admin_dashboard_actions_path
click_link "Create resource or action"
end
scenario "Creates a new action", :js do
fill_in "Title", with: action.title
fill_in_ckeditor "Description", with: action.description
click_button "Save"
expect(page).to have_content(action.title)
end
scenario "Renders create form in case data is invalid" do
click_button "Save"
expect(page).to have_content("error prevented this Dashboard/Action from being saved.")
end
end
context "when editing an action" do
let!(:action) { create :dashboard_action }
before do
visit admin_dashboard_actions_path
within "#dashboard_action_#{action.id}" do
click_link "Edit"
end
end
scenario "Updates the action" do
fill_in "dashboard_action_title", with: "Great action!"
click_button "Save"
expect(page).to have_content "Great action!"
end
scenario "Renders edit form in case data is invalid" do
fill_in "dashboard_action_title", with: "x"
click_button "Save"
expect(page).to have_content("error prevented this Dashboard/Action from being saved.")
end
end
context "when destroying an action" do
let!(:action) { create :dashboard_action }
before do
visit admin_dashboard_actions_path
end
scenario "deletes the action", js: true do
page.accept_confirm do
click_link "Delete"
end
expect(page).not_to have_content(action.title)
end
scenario "can not delete actions that have been executed", js: true do
_executed_action = create(:dashboard_executed_action, action: action)
page.accept_confirm do
click_link "Delete"
end
expect(page).to have_content("Cannot delete record because dependent executed actions exist")
end
end
end