alchemy_cms 3.0.0.rc6 → 3.0.0.rc7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46aef856d1de74f7fdd263bd44290ab72970a408
4
- data.tar.gz: c8db252636d2e4af9b8172f89b27fc7d7ba209e9
3
+ metadata.gz: 02135f0ba23a59280b20309cec71a326a544ff42
4
+ data.tar.gz: 053e8ad503e06ae42a9c07435c41ef161828161e
5
5
  SHA512:
6
- metadata.gz: 316bf6685dc74ea7a82a54a9f6f2c1f3efff0abf0ff24952fca2bb5de42315ae027cc154016dac6fc5075006f90104eaed1680b4bfba10d28e0ff10518366572
7
- data.tar.gz: b86f3962f5e93226710495596dc5dc9ec7dd16ffbac5972b80fecd3e085b2feb812d4b11b51f260dad7c370ab03f61aa9939b1f229f4cd9af669a31f9617fc44
6
+ metadata.gz: 19c8cb6b48175d8b27345fff351ff9d5acea1e7a95af065e2c2094a44f6428474f79b6d1d5a8be2ac7aaf78068295c4a41131d4a9a6d1cdff975046a53462e47
7
+ data.tar.gz: e182d4b3f9a33a1e2c148e83b8b0824df7474d5c952cfdc3ab42c7c3bf612d8992df8dc4eab8ddd6db0ba614f214e3e2edd8a94469a568fbf829296d7a88a894
@@ -2,16 +2,22 @@ module Alchemy
2
2
  module Page::PageUsers
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ # Returns the creator of this page.
6
+ #
5
7
  def creator
6
- Alchemy.user_class.try(:find, creator_id)
8
+ Alchemy.user_class.try(:find_by, {id: creator_id})
7
9
  end
8
10
 
11
+ # Returns the last updater of this page.
12
+ #
9
13
  def updater
10
- Alchemy.user_class.try(:find, updater_id)
14
+ Alchemy.user_class.try(:find_by, {id: updater_id})
11
15
  end
12
16
 
17
+ # Returns the user currently editing this page.
18
+ #
13
19
  def locker
14
- Alchemy.user_class.try(:find, locked_by)
20
+ Alchemy.user_class.try(:find_by, {id: locked_by})
15
21
  end
16
22
 
17
23
  # Returns the name of the creator of this page.
@@ -1,5 +1,26 @@
1
1
  FactoryGirl.define do
2
2
 
3
+ factory :user, class: 'DummyUser' do
4
+ sequence(:email) { |n| "john.#{n}@doe.com" }
5
+ password 's3cr3t'
6
+
7
+ factory :admin_user do
8
+ alchemy_roles 'admin'
9
+ end
10
+
11
+ factory :member_user do
12
+ alchemy_roles 'member'
13
+ end
14
+
15
+ factory :author_user do
16
+ alchemy_roles 'author'
17
+ end
18
+
19
+ factory :editor_user do
20
+ alchemy_roles 'editor'
21
+ end
22
+ end
23
+
3
24
  factory :language, :class => 'Alchemy::Language' do
4
25
  name 'Deutsch'
5
26
  code 'de'
@@ -1,5 +1,5 @@
1
1
  module Alchemy
2
- VERSION = "3.0.0.rc6"
2
+ VERSION = "3.0.0.rc7"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -233,6 +233,61 @@ module Alchemy
233
233
  end
234
234
  end
235
235
 
236
+ describe '#edit' do
237
+ let!(:page) { create(:page) }
238
+ let!(:other_user) { create(:author_user) }
239
+
240
+ context 'if page is locked by another user' do
241
+ before { page.lock_to!(other_user) }
242
+
243
+ context 'that is signed in' do
244
+ before { DummyUser.any_instance.stub(logged_in?: true) }
245
+
246
+ it 'redirects to sitemap' do
247
+ get :edit, id: page.id
248
+ expect(response).to redirect_to(admin_pages_path)
249
+ end
250
+ end
251
+
252
+ context 'that is not signed in' do
253
+ before { DummyUser.any_instance.stub(logged_in?: false) }
254
+
255
+ it 'renders the edit view' do
256
+ get :edit, id: page.id
257
+ expect(response).to render_template(:edit)
258
+ end
259
+ end
260
+ end
261
+
262
+ context 'if page is locked by myself' do
263
+ before do
264
+ Page.any_instance.stub(locker: user)
265
+ user.stub(logged_in?: true)
266
+ end
267
+
268
+ it 'renders the edit view' do
269
+ get :edit, id: page.id
270
+ expect(response).to render_template(:edit)
271
+ end
272
+ end
273
+
274
+ context 'if page is not locked' do
275
+ before do
276
+ Page.any_instance.stub(locker: nil)
277
+ end
278
+
279
+ it 'renders the edit view' do
280
+ get :edit, id: page.id
281
+ expect(response).to render_template(:edit)
282
+ end
283
+
284
+ it "lockes the page to myself" do
285
+ Page.any_instance.should_receive(:lock_to!)
286
+ get :edit, id: page.id
287
+ end
288
+ end
289
+ end
290
+
236
291
  describe '#destroy' do
237
292
  let(:clipboard) { session[:clipboard] = Clipboard.new }
238
293
  let(:page) { FactoryGirl.create(:public_page) }
@@ -1,17 +1,7 @@
1
- class DummyUser
2
- include ActiveModel::Validations
3
-
4
- attr_accessor :alchemy_roles, :language, :cache_key, :email, :password, :name, :id
1
+ class DummyUser < ActiveRecord::Base
2
+ attr_accessor :alchemy_roles, :name
5
3
 
6
4
  def self.logged_in
7
5
  []
8
6
  end
9
-
10
- def self.stamper_class_name
11
- :DummyUser
12
- end
13
-
14
- def update_attributes(attributes)
15
- attributes.each { |key,value| send("#{key}=".to_sym, value) }
16
- end
17
7
  end
@@ -33,7 +33,7 @@ describe 'Dashboard feature' do
33
33
  user = DummyUser.new
34
34
  user.update_attributes(alchemy_roles: %w(admin), name: "Sue Smith", id: 2)
35
35
  a_page.lock_to!(user)
36
- DummyUser.stub(:find).and_return(user)
36
+ DummyUser.stub(:find_by).and_return(user)
37
37
  visit admin_dashboard_path
38
38
  locked_pages_widget = all('div[@class="widget"]').first
39
39
  expect(locked_pages_widget).to have_content "Currently locked pages:"
@@ -1349,6 +1349,41 @@ module Alchemy
1349
1349
 
1350
1350
  context 'indicate page editors' do
1351
1351
  let(:page) { Page.new }
1352
+ let(:user) { create(:editor_user) }
1353
+
1354
+ describe '#creator' do
1355
+ before { page.update(creator_id: user.id) }
1356
+
1357
+ it "returns the user that created the page" do
1358
+ expect(page.creator).to eq(user)
1359
+ end
1360
+ end
1361
+
1362
+ describe '#updater' do
1363
+ before { page.update(updater_id: user.id) }
1364
+
1365
+ it "returns the user that created the page" do
1366
+ expect(page.updater).to eq(user)
1367
+ end
1368
+ end
1369
+
1370
+ describe '#locker' do
1371
+ before { page.update(locked_by: user.id) }
1372
+
1373
+ it "returns the user that created the page" do
1374
+ expect(page.locker).to eq(user)
1375
+ end
1376
+ end
1377
+
1378
+ context 'with user that can not be found' do
1379
+ it 'does not raise not found error' do
1380
+ %w(creator updater locker).each do |user_type|
1381
+ expect {
1382
+ page.send(user_type)
1383
+ }.to_not raise_error(ActiveRecord::RecordNotFound)
1384
+ end
1385
+ end
1386
+ end
1352
1387
 
1353
1388
  context 'with user class having a name accessor' do
1354
1389
  let(:user) { double(name: 'Paul Page') }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc6
4
+ version: 3.0.0.rc7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas von Deyen
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-06-03 00:00:00.000000000 Z
15
+ date: 2014-06-04 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails