days 0.2.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +21 -4
- data/app/javascripts/admin/bootstrap.min.js +7 -0
- data/app/javascripts/jquery-2.1.3.min.js +4 -0
- data/app/stylesheets/admin/bootstrap-theme.min.css +5 -0
- data/app/stylesheets/admin/bootstrap.min.css +5 -0
- data/app/stylesheets/admin/login.scss +3 -5
- data/app/stylesheets/admin.scss +4 -0
- data/app/views/admin/categories.haml +3 -3
- data/app/views/admin/entries/form.haml +22 -17
- data/app/views/admin/entries/index.haml +46 -28
- data/app/views/admin/login.haml +11 -8
- data/app/views/admin/setup.haml +16 -9
- data/app/views/admin.haml +31 -21
- data/days.gemspec +14 -11
- data/lib/days/app/admin/entries.rb +11 -5
- data/lib/days/app/entries.rb +24 -13
- data/lib/days/app.rb +2 -3
- data/lib/days/command.rb +1 -1
- data/lib/days/config.rb +18 -5
- data/lib/days/helpers.rb +13 -11
- data/lib/days/models/base.rb +11 -0
- data/lib/days/models/category.rb +2 -2
- data/lib/days/models/entry.rb +41 -8
- data/lib/days/models/user.rb +2 -2
- data/lib/days/version.rb +1 -1
- data/scripts/tumblr_export.rb +1 -1
- data/spec/controllers/admin/categories_spec.rb +22 -22
- data/spec/controllers/admin/entries_spec.rb +155 -44
- data/spec/controllers/admin/session_spec.rb +16 -25
- data/spec/controllers/admin/setup_spec.rb +22 -25
- data/spec/controllers/admin/users_spec.rb +39 -40
- data/spec/controllers/entries_spec.rb +71 -42
- data/spec/helpers_spec.rb +18 -29
- data/spec/models/entry_spec.rb +117 -47
- data/spec/shared/admin.rb +2 -2
- data/spec/spec_helper.rb +25 -25
- metadata +111 -86
- data/app/javascripts/bootstrap.js +0 -2159
- data/app/javascripts/bootstrap.min.js +0 -6
- data/app/javascripts/jquery-1.8.3.min.js +0 -2
- data/app/stylesheets/bootstrap-responsive.css +0 -1092
- data/app/stylesheets/bootstrap-responsive.min.css +0 -9
- data/app/stylesheets/bootstrap.css +0 -6039
- data/app/stylesheets/bootstrap.min.css +0 -9
@@ -2,24 +2,76 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Days::App, type: :controller do
|
4
4
|
describe "admin: entries" do
|
5
|
-
|
6
|
-
let(:
|
7
|
-
let(:
|
5
|
+
let!(:entry) { Days::Entry.create!(title: 'foo', body: 'foo') }
|
6
|
+
let!(:draft) { Days::Entry.create!(title: 'draft', body: 'foo', draft: true) }
|
7
|
+
let!(:scheduled) { Days::Entry.create!(title: 'scheduled', body: 'foo', published_at: Time.now + (86400 * 365)) }
|
8
|
+
let(:user) { Days::User.create!(login_name: 'blogger', name: 'blogger', password: 'x', password_confirmation: 'x') }
|
8
9
|
|
9
10
|
before { login(user) }
|
10
11
|
|
11
12
|
describe "GET /admin/entries" do
|
13
|
+
let(:now) { Time.now }
|
14
|
+
|
15
|
+
before do
|
16
|
+
# fix the time to fix time in SQL statement (might have difference in microsec)
|
17
|
+
allow(Time).to receive(:now).and_return(now)
|
18
|
+
end
|
19
|
+
|
12
20
|
subject { get '/admin/entries', {}, env }
|
13
21
|
|
14
22
|
it_behaves_like 'an admin page'
|
15
23
|
|
16
|
-
it {
|
24
|
+
it { is_expected.to be_ok }
|
17
25
|
|
18
26
|
it "lists up entries" do
|
19
|
-
render[:data].
|
27
|
+
expect(render[:data]).to eq(:'admin/entries/index')
|
20
28
|
|
21
29
|
entries = render[:ivars][:@entries]
|
22
|
-
entries.
|
30
|
+
expect(entries).to eq(Days::Entry.order(id: :desc).page(nil))
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "with page" do
|
34
|
+
subject { get '/admin/entries?page=2', {}, env }
|
35
|
+
|
36
|
+
it "lists up entries for specified page" do
|
37
|
+
expect(render[:data]).to eq(:'admin/entries/index')
|
38
|
+
|
39
|
+
entries = render[:ivars][:@entries]
|
40
|
+
expect(entries).to eq(Days::Entry.order(id: :desc).page(2))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "with draft=1" do
|
45
|
+
subject { get '/admin/entries?draft=1', {}, env }
|
46
|
+
|
47
|
+
it "lists up drafts" do
|
48
|
+
expect(render[:data]).to eq(:'admin/entries/index')
|
49
|
+
|
50
|
+
entries = render[:ivars][:@entries]
|
51
|
+
expect(entries).to eq(Days::Entry.order(id: :desc).draft.page(nil))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "with scheduled=1" do
|
56
|
+
subject { get '/admin/entries?scheduled=1', {}, env }
|
57
|
+
|
58
|
+
it "lists up scheduled entries" do
|
59
|
+
expect(render[:data]).to eq(:'admin/entries/index')
|
60
|
+
|
61
|
+
entries = render[:ivars][:@entries]
|
62
|
+
expect(entries).to eq(Days::Entry.order(id: :desc).scheduled.page(1))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "with published=1" do
|
67
|
+
subject { get '/admin/entries?published=1', {}, env }
|
68
|
+
|
69
|
+
it "lists up published entries" do
|
70
|
+
expect(render[:data]).to eq(:'admin/entries/index')
|
71
|
+
|
72
|
+
entries = render[:ivars][:@entries]
|
73
|
+
expect(entries).to eq(Days::Entry.order(id: :desc).published.page(nil))
|
74
|
+
end
|
23
75
|
end
|
24
76
|
end
|
25
77
|
|
@@ -28,13 +80,13 @@ describe Days::App, type: :controller do
|
|
28
80
|
|
29
81
|
it_behaves_like 'an admin page'
|
30
82
|
|
31
|
-
it {
|
83
|
+
it { is_expected.to be_ok }
|
32
84
|
|
33
85
|
it "renders form page" do
|
34
|
-
render[:data].
|
86
|
+
expect(render[:data]).to eq(:'admin/entries/form')
|
35
87
|
entry = render[:ivars][:@entry]
|
36
|
-
entry.
|
37
|
-
entry.
|
88
|
+
expect(entry).to be_a(Days::Entry)
|
89
|
+
expect(entry).to be_new_record
|
38
90
|
end
|
39
91
|
end
|
40
92
|
|
@@ -47,26 +99,56 @@ describe Days::App, type: :controller do
|
|
47
99
|
it_behaves_like 'an admin page'
|
48
100
|
|
49
101
|
it "creates entry" do
|
50
|
-
subject.
|
102
|
+
expect(subject).to be_redirect
|
51
103
|
|
52
|
-
entry
|
53
|
-
entry.
|
54
|
-
entry.
|
104
|
+
entry = Days::Entry.last
|
105
|
+
expect(entry.title).to eq("Hello")
|
106
|
+
expect(entry.body).to eq("World")
|
107
|
+
expect(entry.user).to eq(user)
|
55
108
|
end
|
56
109
|
|
57
110
|
context "when entry is invalid" do
|
58
111
|
before do
|
59
|
-
Days::Entry.
|
112
|
+
allow_any_instance_of(Days::Entry).to receive_messages(:valid? => false, :save => false)
|
60
113
|
end
|
61
114
|
|
62
|
-
specify { subject.status.
|
115
|
+
specify { expect(subject.status).to eq(406) } # not acceptable
|
63
116
|
|
64
117
|
it "renders form" do
|
65
|
-
render[:data].
|
118
|
+
expect(render[:data]).to eq(:'admin/entries/form')
|
66
119
|
ientry = render[:ivars][:@entry]
|
67
|
-
ientry.
|
68
|
-
ientry.title.
|
69
|
-
ientry.body.
|
120
|
+
expect(ientry).to be_a_new_record
|
121
|
+
expect(ientry.title).to eq('Hello')
|
122
|
+
expect(ientry.body).to eq('World')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "with config.html_pipeline" do
|
127
|
+
let(:pipeline) do
|
128
|
+
double('pipeline')
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:entry) do
|
132
|
+
Days::Entry.new(entry_params)
|
133
|
+
end
|
134
|
+
|
135
|
+
before do
|
136
|
+
Days::App.config.html_pipeline = pipeline
|
137
|
+
allow(Days::Entry).to receive(:new).and_return(entry)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "sets pipeline to entry" do
|
141
|
+
allow(entry).to receive(:save).and_wrap_original do |m, *args|
|
142
|
+
expect(entry.pipeline).to eq(pipeline)
|
143
|
+
entry.pipeline = nil
|
144
|
+
m.call
|
145
|
+
end
|
146
|
+
|
147
|
+
expect(subject).to be_redirect
|
148
|
+
end
|
149
|
+
|
150
|
+
after do
|
151
|
+
Days::App.config.html_pipeline = nil
|
70
152
|
end
|
71
153
|
end
|
72
154
|
|
@@ -79,11 +161,12 @@ describe Days::App, type: :controller do
|
|
79
161
|
{entry: entry_params.merge(categories: categories)}
|
80
162
|
end
|
81
163
|
|
82
|
-
it {
|
164
|
+
it { is_expected.to be_redirect }
|
83
165
|
|
84
166
|
it "creates entry with categories" do
|
85
167
|
subject
|
86
|
-
entry
|
168
|
+
entry = Days::Entry.last
|
169
|
+
expect(entry.categories.reload.map(&:id)).to eq(Days::Category.pluck(:id))
|
87
170
|
end
|
88
171
|
end
|
89
172
|
end
|
@@ -94,14 +177,14 @@ describe Days::App, type: :controller do
|
|
94
177
|
it_behaves_like 'an admin page'
|
95
178
|
|
96
179
|
it "renders form page" do
|
97
|
-
render[:data].
|
98
|
-
render[:ivars][:@entry].
|
180
|
+
expect(render[:data]).to eq(:'admin/entries/form')
|
181
|
+
expect(render[:ivars][:@entry]).to eq(entry)
|
99
182
|
end
|
100
183
|
|
101
184
|
context "with invalid entry" do
|
102
|
-
|
185
|
+
before { entry.destroy }
|
103
186
|
|
104
|
-
it {
|
187
|
+
it { is_expected.to be_not_found }
|
105
188
|
end
|
106
189
|
end
|
107
190
|
|
@@ -114,43 +197,71 @@ describe Days::App, type: :controller do
|
|
114
197
|
it_behaves_like 'an admin page'
|
115
198
|
|
116
199
|
it "updates entry" do
|
117
|
-
subject.
|
118
|
-
URI.parse(subject['Location']).path.
|
200
|
+
expect(subject).to be_redirect
|
201
|
+
expect(URI.parse(subject['Location']).path).to eq(path)
|
119
202
|
|
120
203
|
entry.reload
|
121
|
-
entry.title.
|
122
|
-
entry.body.
|
204
|
+
expect(entry.title).to eq('New')
|
205
|
+
expect(entry.body).to eq('foo')
|
123
206
|
end
|
124
207
|
|
125
208
|
context "when invalid" do
|
126
209
|
before do
|
127
|
-
Days::Entry.
|
210
|
+
allow_any_instance_of(Days::Entry).to receive_messages(:valid? => false, :save => false)
|
128
211
|
end
|
129
212
|
|
130
213
|
it "renders form" do
|
131
|
-
render[:data].
|
214
|
+
expect(render[:data]).to eq(:'admin/entries/form')
|
132
215
|
ientry = render[:ivars][:@entry]
|
133
|
-
ientry.id.
|
134
|
-
ientry.title.
|
135
|
-
|
216
|
+
expect(ientry.id).to eq(entry.id)
|
217
|
+
expect(ientry.title).to eq('New')
|
218
|
+
|
219
|
+
entry.reload
|
220
|
+
expect(entry.title).to eq('foo')
|
136
221
|
end
|
137
222
|
end
|
138
223
|
|
139
224
|
context "with category" do
|
225
|
+
let(:category) { Days::Category.create!(name: 'daily') }
|
140
226
|
let(:params) do
|
141
|
-
{entry: {categories: {
|
227
|
+
{entry: {categories: {category.id.to_s => '1'}}}
|
142
228
|
end
|
143
229
|
|
144
230
|
it "creates entry with categories" do
|
145
|
-
subject.
|
146
|
-
entry.categories.reload.map(&:id).
|
231
|
+
expect(subject).to be_redirect
|
232
|
+
expect(entry.reload.categories.reload.map(&:id)).to eq([category.id])
|
147
233
|
end
|
148
234
|
end
|
149
235
|
|
150
236
|
context "with invalid entry" do
|
151
|
-
|
237
|
+
before { entry.destroy }
|
238
|
+
|
239
|
+
it { is_expected.to be_not_found }
|
240
|
+
end
|
241
|
+
|
242
|
+
context "with config.html_pipeline" do
|
243
|
+
let(:pipeline) do
|
244
|
+
double('pipeline')
|
245
|
+
end
|
246
|
+
|
247
|
+
before do
|
248
|
+
Days::App.config.html_pipeline = pipeline
|
249
|
+
expect(Days::Entry).to receive(:find_by).with(id: entry.id.to_s).and_return(entry)
|
250
|
+
end
|
251
|
+
|
252
|
+
it "sets pipeline to entry" do
|
253
|
+
allow(entry).to receive(:save).and_wrap_original do |m, *args|
|
254
|
+
expect(entry.pipeline).to eq(pipeline)
|
255
|
+
entry.pipeline = nil
|
256
|
+
m.call
|
257
|
+
end
|
152
258
|
|
153
|
-
|
259
|
+
expect(subject).to be_redirect
|
260
|
+
end
|
261
|
+
|
262
|
+
after do
|
263
|
+
Days::App.config.html_pipeline = nil
|
264
|
+
end
|
154
265
|
end
|
155
266
|
end
|
156
267
|
|
@@ -161,14 +272,14 @@ describe Days::App, type: :controller do
|
|
161
272
|
|
162
273
|
it "destroys entry" do
|
163
274
|
expect { subject }.to change { Days::Entry.where(id: entry.id).count }.from(1).to(0)
|
164
|
-
subject.
|
165
|
-
URI.parse(subject.location).path.
|
275
|
+
expect(subject).to be_redirect
|
276
|
+
expect(URI.parse(subject.location).path).to eq("/admin/entries")
|
166
277
|
end
|
167
278
|
|
168
279
|
context "with invalid entry" do
|
169
|
-
|
280
|
+
before { entry.destroy }
|
170
281
|
|
171
|
-
it {
|
282
|
+
it { is_expected.to be_not_found }
|
172
283
|
end
|
173
284
|
end
|
174
285
|
|
@@ -2,27 +2,18 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Days::App, type: :controller do
|
4
4
|
describe "admin: sessions" do
|
5
|
-
let(:user) do
|
5
|
+
let!(:user) do
|
6
6
|
Days::User.create(
|
7
7
|
name: 'Blogger', login_name: 'blogger',
|
8
8
|
password: 'password', password_confirmation: 'password'
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
12
|
-
before do
|
13
|
-
Days::User.destroy_all
|
14
|
-
user
|
15
|
-
end
|
16
|
-
|
17
|
-
after do
|
18
|
-
user.destroy
|
19
|
-
end
|
20
|
-
|
21
12
|
describe "GET /admin/login" do
|
22
13
|
subject { get '/admin/login' }
|
23
14
|
|
24
15
|
it "renders login page" do
|
25
|
-
render[:data].
|
16
|
+
expect(render[:data]).to eq(:'admin/login')
|
26
17
|
end
|
27
18
|
end
|
28
19
|
|
@@ -36,15 +27,15 @@ describe Days::App, type: :controller do
|
|
36
27
|
end
|
37
28
|
|
38
29
|
it "redirects to /admin" do
|
39
|
-
subject.
|
40
|
-
URI.parse(subject.location).path.
|
30
|
+
expect(subject).to be_redirect
|
31
|
+
expect(URI.parse(subject.location).path).to eq('/admin')
|
41
32
|
end
|
42
33
|
|
43
34
|
context "without login name" do
|
44
35
|
let(:params) { {password: 'password'} }
|
45
36
|
|
46
37
|
specify do
|
47
|
-
subject.status.
|
38
|
+
expect(subject.status).to eq(400)
|
48
39
|
end
|
49
40
|
end
|
50
41
|
|
@@ -52,7 +43,7 @@ describe Days::App, type: :controller do
|
|
52
43
|
let(:params) { {login_name: 'blogger'} }
|
53
44
|
|
54
45
|
specify do
|
55
|
-
subject.status.
|
46
|
+
expect(subject.status).to eq(400)
|
56
47
|
end
|
57
48
|
end
|
58
49
|
|
@@ -61,12 +52,12 @@ describe Days::App, type: :controller do
|
|
61
52
|
|
62
53
|
it "doesn't log in" do
|
63
54
|
subject
|
64
|
-
session[:user_id].
|
55
|
+
expect(session[:user_id]).to be_nil
|
65
56
|
end
|
66
57
|
|
67
58
|
it "returns login page" do
|
68
|
-
subject.status.
|
69
|
-
render[:data].
|
59
|
+
expect(subject.status).to eq(401)
|
60
|
+
expect(render[:data]).to eq(:'admin/login')
|
70
61
|
end
|
71
62
|
end
|
72
63
|
|
@@ -75,12 +66,12 @@ describe Days::App, type: :controller do
|
|
75
66
|
|
76
67
|
it "doesn't log in" do
|
77
68
|
subject
|
78
|
-
session[:user_id].
|
69
|
+
expect(session[:user_id]).to be_nil
|
79
70
|
end
|
80
71
|
|
81
72
|
it "returns login page" do
|
82
|
-
subject.status.
|
83
|
-
render[:data].
|
73
|
+
expect(subject.status).to eq(401)
|
74
|
+
expect(render[:data]).to eq(:'admin/login')
|
84
75
|
end
|
85
76
|
end
|
86
77
|
end
|
@@ -91,8 +82,8 @@ describe Days::App, type: :controller do
|
|
91
82
|
before { login(user) }
|
92
83
|
|
93
84
|
it "redirects to /admin/login" do
|
94
|
-
subject.
|
95
|
-
URI.parse(subject.location).path.
|
85
|
+
expect(subject).to be_redirect
|
86
|
+
expect(URI.parse(subject.location).path).to eq('/admin/login')
|
96
87
|
end
|
97
88
|
|
98
89
|
specify do
|
@@ -102,8 +93,8 @@ describe Days::App, type: :controller do
|
|
102
93
|
|
103
94
|
context "when not logged in" do
|
104
95
|
it "redirects to /admin/login" do
|
105
|
-
subject.
|
106
|
-
URI.parse(subject.location).path.
|
96
|
+
expect(subject).to be_redirect
|
97
|
+
expect(URI.parse(subject.location).path).to eq('/admin/login')
|
107
98
|
end
|
108
99
|
end
|
109
100
|
end
|
@@ -3,10 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe Days::App, type: :controller do
|
4
4
|
shared_examples "an setup page" do
|
5
5
|
context "when user exists" do
|
6
|
-
|
6
|
+
before do
|
7
|
+
Days::User.create!(
|
8
|
+
name: 'Blogger', login_name: 'blogger',
|
9
|
+
password: 'password', password_confirmation: 'password'
|
10
|
+
)
|
11
|
+
end
|
7
12
|
|
8
13
|
it "denies access" do
|
9
|
-
subject.status.
|
14
|
+
expect(subject.status).to eq(403)
|
10
15
|
end
|
11
16
|
end
|
12
17
|
end
|
@@ -18,17 +23,13 @@ describe Days::App, type: :controller do
|
|
18
23
|
it_behaves_like 'an setup page'
|
19
24
|
|
20
25
|
context "when user not exists" do
|
21
|
-
|
22
|
-
Days::User.destroy_all
|
23
|
-
end
|
24
|
-
|
25
|
-
it { should be_ok }
|
26
|
+
it { is_expected.to be_ok }
|
26
27
|
|
27
28
|
it "renders form page" do
|
28
|
-
render[:data].
|
29
|
+
expect(render[:data]).to eq(:'admin/setup')
|
29
30
|
user = render[:ivars][:@user]
|
30
|
-
user.
|
31
|
-
user.
|
31
|
+
expect(user).to be_a(Days::User)
|
32
|
+
expect(user).to be_new_record
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -43,40 +44,36 @@ describe Days::App, type: :controller do
|
|
43
44
|
it_behaves_like 'an setup page'
|
44
45
|
|
45
46
|
context "when user not exists" do
|
46
|
-
before do
|
47
|
-
Days::User.destroy_all
|
48
|
-
end
|
49
|
-
|
50
47
|
it "creates user" do
|
51
48
|
expect { subject }.to change { Days::User.count }.from(0).to(1)
|
52
49
|
user = Days::User.last
|
53
|
-
user.name.
|
50
|
+
expect(user.name).to eq("Newbie")
|
54
51
|
end
|
55
52
|
|
56
53
|
it "logs in" do
|
57
|
-
session[:user_id].
|
54
|
+
expect(session[:user_id]).to be_nil
|
58
55
|
subject
|
59
|
-
session[:user_id].
|
56
|
+
expect(session[:user_id]).to eq(Days::User.last.id)
|
60
57
|
end
|
61
58
|
|
62
59
|
it "redirects to /admin" do
|
63
|
-
subject.
|
64
|
-
URI.parse(subject.location).path.
|
60
|
+
expect(subject).to be_redirect
|
61
|
+
expect(URI.parse(subject.location).path).to eq('/admin')
|
65
62
|
end
|
66
63
|
|
67
64
|
context "when user is invalid" do
|
68
65
|
before do
|
69
|
-
Days::User.
|
66
|
+
allow_any_instance_of(Days::User).to receive_messages(:valid? => false, :save => false)
|
70
67
|
end
|
71
68
|
|
72
|
-
specify { subject.status.
|
69
|
+
specify { expect(subject.status).to eq(406) } # not acceptable
|
73
70
|
|
74
71
|
it "renders form" do
|
75
|
-
render[:data].
|
72
|
+
expect(render[:data]).to eq(:'admin/setup')
|
76
73
|
iuser = render[:ivars][:@user]
|
77
|
-
iuser.
|
78
|
-
iuser.name.
|
79
|
-
iuser.login_name.
|
74
|
+
expect(iuser).to be_a_new_record
|
75
|
+
expect(iuser.name).to eq('Newbie')
|
76
|
+
expect(iuser.login_name).to eq('newbie')
|
80
77
|
end
|
81
78
|
end
|
82
79
|
end
|