-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
resources_spec.rb
148 lines (114 loc) · 4.5 KB
/
resources_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Encoding: UTF-8
require "spec_helper"
module Refinery
module Admin
describe "Resources", :type => :feature do
refinery_login_with :refinery_user
context "when no files" do
it "invites to upload file" do
visit refinery.admin_resources_path
expect(page).to have_content(%q{There are no files yet. Click "Upload new file" to add your first file.})
end
end
it "shows upload file link" do
visit refinery.admin_resources_path
expect(page).to have_content("Upload new file")
expect(page).to have_selector("a[href*='/refinery/resources/new']")
end
context "new/create" do
it "uploads file", :js => true do
visit refinery.admin_resources_path
find('a', text: 'Upload new file').trigger(:click)
expect(page).to have_selector 'iframe#dialog_iframe'
page.within_frame('dialog_iframe') do
attach_file "resource_file", Refinery.roots('refinery/resources').
join("spec/fixtures/refinery_is_awesome.txt")
click_button ::I18n.t('save', :scope => 'refinery.admin.form_actions')
end
expect(page).to have_content("Refinery Is Awesome")
expect(Refinery::Resource.count).to eq(1)
end
describe "max file size" do
before do
allow(Refinery::Resources).to receive(:max_file_size).and_return('1224')
end
context "in english" do
before do
allow(Refinery::I18n).to receive(:current_locale).and_return(:en)
end
it "is shown" do
visit refinery.admin_resources_path
click_link "Upload new file"
within('#maximum_file_size') do
expect(page).to have_content "1.2 KB"
end
end
end
context "in danish" do
before do
allow(Refinery::I18n).to receive(:current_locale).and_return(:da)
end
it "is shown" do
visit refinery.admin_resources_path
click_link "Tilføj en ny fil"
within "#maximum_file_size" do
expect(page).to have_content "1,2 KB"
end
end
end
end
end
context "edit/update" do
let!(:resource) { FactoryGirl.create(:resource) }
it "updates file" do
visit refinery.admin_resources_path
expect(page).to have_content("Refinery Is Awesome")
expect(page).to have_selector("a[href='/refinery/resources/#{resource.id}/edit']")
click_link "Edit this file"
expect(page).to have_content("Download current file or replace it with this one...")
expect(page).to have_selector("a[href*='/refinery/resources']")
attach_file "resource_file", Refinery.roots('refinery/resources').join("spec/fixtures/refinery_is_awesome2.txt")
click_button "Save"
expect(page).to have_content("Refinery Is Awesome2")
expect(Refinery::Resource.count).to eq(1)
end
end
context "destroy" do
let!(:resource) { FactoryGirl.create(:resource) }
it "removes file" do
visit refinery.admin_resources_path
expect(page).to have_selector("a[href='/refinery/resources/#{resource.id}']")
click_link "Remove this file forever"
expect(page).to have_content("'Refinery Is Awesome' was successfully removed.")
expect(Refinery::Resource.count).to eq(0)
end
end
context "download" do
let!(:resource) { FactoryGirl.create(:resource) }
it "succeeds" do
visit refinery.admin_resources_path
click_link "Download this file"
expect(page).to have_content("http://www.refineryhq.com/")
end
context 'when the extension is mounted with a named space' do
before do
Rails.application.routes.draw do
mount Refinery::Core::Engine, :at => "/about"
end
Rails.application.routes_reloader.reload!
end
after do
Rails.application.routes.draw do
mount Refinery::Core::Engine, :at => "/"
end
end
it "succeeds" do
visit refinery.admin_resources_path
click_link "Download this file"
expect(page).to have_content("http://www.refineryhq.com/")
end
end
end
end
end
end