alchemy_cms 2.9.0 → 2.9.1

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: b424447a096b31e81ed5a0d290b0ad668337b5b8
4
- data.tar.gz: a7eefe0821effccdd65312b9ac99573ad0784f7f
3
+ metadata.gz: 3cea20dd64fa70cb769c8efaed115271f6299ac2
4
+ data.tar.gz: 7765f71df28daf51b5605c9729b88a63a06470c5
5
5
  SHA512:
6
- metadata.gz: f2b2833ceef66d2a76b6512430f076f6133da8472e9456712d69b3c7f7b0c1531f76f9babbf3d516cbc0e0dd3318aa770ea233099ff20f5b73787ce9bb8587d0
7
- data.tar.gz: 4eed6223c08ea0903cd629998c681c5d9117098e69866fccab2e92ff6354663c0b6dbdb68281c38f4c953712b940f2e42557df745b3363c063631fd06035f4d0
6
+ metadata.gz: bc35cce02f544a78c3166f8dc6d6a4957b0534eb0bc910a570c0417ad2a9ac17935fe81c229b7edd1b50cad26b4c613e813544ac49f3cbc46187e0fd44cd2174
7
+ data.tar.gz: 8e3a5e4faa7efe8f93b594dd93452fd6d1513c68022f4f5b32ba2b9da48ee4b48373d96d666899063b568db2d640c09189a3beb264f6459c77936bad6e8a72cf
@@ -83,16 +83,17 @@ module Alchemy
83
83
  end
84
84
 
85
85
  def order
86
- @trashed_elements = []
87
- params[:element_ids].each do |element_id|
88
- element = Element.find(element_id)
89
- if element.trashed?
90
- element.page_id = params[:page_id]
91
- element.cell_id = params[:cell_id]
92
- element.insert_at
93
- @trashed_elements << element
86
+ @trashed_elements = Element.trashed.where(id: params[:element_ids]).pluck(:id)
87
+ Element.transaction do
88
+ params[:element_ids].each_with_index do |element_id, idx|
89
+ # Ensure to set page_id and cell_id to the current page and
90
+ # cell because of trashed elements could still have old values
91
+ Element.where(id: element_id).update_all(
92
+ page_id: params[:page_id],
93
+ cell_id: params[:cell_id],
94
+ position: idx + 1
95
+ )
94
96
  end
95
- element.move_to_bottom
96
97
  end
97
98
  end
98
99
 
@@ -309,7 +309,7 @@ module Alchemy
309
309
  # A children node
310
310
  #
311
311
  def process_url(ancestors_path, item)
312
- default_urlname = (ancestors_path.blank? ? "" : "#{ancestors_path}/") + item['slug']
312
+ default_urlname = (ancestors_path.blank? ? "" : "#{ancestors_path}/") + item['slug'].to_s
313
313
 
314
314
  pair = {my_urlname: default_urlname, children_path: default_urlname}
315
315
 
@@ -12,12 +12,10 @@ module Alchemy
12
12
 
13
13
  def database_config
14
14
  raise "Could not find #{database_config_file}!" if !File.exists?(database_config_file)
15
- @database_config ||= begin
16
- config_file = YAML.load_file(database_config_file)
17
- config_file.fetch(environment)
18
- rescue KeyError
19
- raise "Database configuration for #{environment} not found!"
20
- end
15
+ config_file = YAML.load_file(database_config_file)
16
+ config_file.fetch(environment)
17
+ rescue KeyError
18
+ raise "Database configuration for #{environment} not found!"
21
19
  end
22
20
 
23
21
  private
@@ -1,5 +1,5 @@
1
1
  module Alchemy
2
- VERSION = "2.9.0"
2
+ VERSION = "2.9.1"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -106,32 +106,48 @@ module Alchemy
106
106
 
107
107
  end
108
108
 
109
- describe "untrashing" do
110
-
111
- before(:each) do
112
- @element = FactoryGirl.create(:element, :public => false, :position => nil, :page_id => 58, :cell_id => 32)
113
- # Because of a before_create filter it can not be created with a nil position and needs to be trashed here
114
- @element.trash!
109
+ describe "#order" do
110
+ let(:element_1) { FactoryGirl.create(:element) }
111
+ let(:element_2) { FactoryGirl.create(:element) }
112
+ let(:element_3) { FactoryGirl.create(:element) }
113
+ let(:element_ids) { [element_1.id, element_3.id, element_2.id] }
114
+
115
+ it "sets new position for given element ids" do
116
+ xhr :post, :order, element_ids: element_ids
117
+ expect(Element.scoped.pluck(:id)).to eq(element_ids)
115
118
  end
116
119
 
117
- it "should set a new position to the element" do
118
- post :order, {:element_ids => ["#{@element.id}"], :format => :js}
119
- @element.reload
120
- @element.position.should_not == nil
121
- end
120
+ context "untrashing" do
121
+ let(:trashed_element) { FactoryGirl.create(:element, public: false, position: nil, page_id: 58, cell_id: 32) }
122
122
 
123
- it "should assign the (new) page_id to the element" do
124
- post :order, {:element_ids => ["#{@element.id}"], :page_id => 1, :cell_id => nil, :format => :js}
125
- @element.reload
126
- @element.page_id.should == 1
127
- end
123
+ before do
124
+ # Because of a before_create filter it can not be created with a nil position and needs to be trashed here
125
+ trashed_element.trash!
126
+ end
128
127
 
129
- it "should assign the (new) cell_id to the element" do
130
- post :order, {:element_ids => ["#{@element.id}"], :page_id => 1, :cell_id => 5, :format => :js}
131
- @element.reload
132
- @element.cell_id.should == 5
133
- end
128
+ it "sets a list of trashed element ids" do
129
+ xhr :post, :order, element_ids: [trashed_element.id]
130
+ expect(assigns(:trashed_elements).to_a).to eq [trashed_element.id]
131
+ end
134
132
 
133
+ it "should set a new position to the element" do
134
+ xhr :post, :order, element_ids: [trashed_element.id]
135
+ trashed_element.reload
136
+ trashed_element.position.should_not == nil
137
+ end
138
+
139
+ it "should assign the (new) page_id to the element" do
140
+ xhr :post, :order, element_ids: [trashed_element.id], page_id: 1, cell_id: nil
141
+ trashed_element.reload
142
+ trashed_element.page_id.should == 1
143
+ end
144
+
145
+ it "should assign the (new) cell_id to the element" do
146
+ xhr :post, :order, element_ids: [trashed_element.id], page_id: 1, cell_id: 5
147
+ trashed_element.reload
148
+ trashed_element.cell_id.should == 5
149
+ end
150
+ end
135
151
  end
136
152
 
137
153
  describe '#new' do
@@ -140,6 +140,24 @@ module Alchemy
140
140
  end
141
141
  end
142
142
 
143
+ context 'with page having number as slug' do
144
+ let(:page_item_2) do
145
+ {
146
+ id: page_2.id,
147
+ slug: 42,
148
+ children: [page_item_3]
149
+ }
150
+ end
151
+
152
+ it "does not raise error" do
153
+ expect {
154
+ xhr :post, :order, set: set_of_pages.to_json
155
+ }.to_not raise_error(TypeError)
156
+ [page_1, page_2, page_3].map(&:reload)
157
+ expect(page_3.urlname).to eq("#{page_1.slug}/#{page_2.slug}/#{page_3.slug}")
158
+ end
159
+ end
160
+
143
161
  it "creates legacy urls" do
144
162
  xhr :post, :order, set: set_of_pages.to_json
145
163
  [page_2, page_3].map(&:reload)
@@ -247,5 +247,16 @@ module Alchemy
247
247
 
248
248
  end
249
249
 
250
+ context "with invalid byte code char in urlname parameter" do
251
+ it "should render page not found" do
252
+ begin
253
+ visit '/%ed'
254
+ page.status_code.should == 404
255
+ rescue ArgumentError
256
+ # capturing the invalid byte sequence in UTF-8 error
257
+ end
258
+ end
259
+ end
260
+
250
261
  end
251
262
  end
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: 2.9.0
4
+ version: 2.9.1
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-16 00:00:00.000000000 Z
15
+ date: 2015-03-31 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
@@ -1099,7 +1099,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1099
1099
  requirements:
1100
1100
  - ImageMagick (libmagick), v6.6 or greater.
1101
1101
  rubyforge_project:
1102
- rubygems_version: 2.2.2
1102
+ rubygems_version: 2.4.3
1103
1103
  signing_key:
1104
1104
  specification_version: 4
1105
1105
  summary: A powerful, userfriendly and flexible CMS for Rails 3