kuhsaft 2.3.0 → 2.3.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: 67da27e272a61ce14b7b0f1f0c1cbf7f6bb5ffaa
4
- data.tar.gz: 0a6cd02acddbcc083c6e21282dca46e1ee7afdf9
3
+ metadata.gz: c60f8ceefd0183f0e24eee551f4560d802969351
4
+ data.tar.gz: bc32915f907f3630621dea9ca3283d5961f0fdb9
5
5
  SHA512:
6
- metadata.gz: ab2e3d901758c86dc668b3a3d891bc5c24b82d4b7e20effdb158c421e77dc81a73dd8a03566919f4526dd63984a78f8e3db41c0dcf320459d8f1c2db2feb6f8f
7
- data.tar.gz: 7994bf1fdafcd117491681eec33296e7730a7da0597e9bbce2fb4e7496b45b7318ccd5717b5aa18b1aeda651f0ba45c7d3fe1de3e29d2b6691515b4306eeba78
6
+ metadata.gz: 5196609fd60806c055d1501f725d3347e5f875da67f952d3a4b249739cea4c80c82ba72665bd7a81e68c085ab1124b9d3eb0ace015cd9335aa609909480cb37c
7
+ data.tar.gz: a226eaf1a6674895c40d81655b82df983c174618cbc15693b5b7f5873e3cb84e7dcbc24c158180e471d74b44754f7529572cf1fb27a89a2b296871ac95f40e9e
data/README.md CHANGED
@@ -193,6 +193,18 @@ de:
193
193
  your_partial: Your Partial
194
194
  ```
195
195
 
196
+ ## Invalidating placeholder bricks containing other models on model changes
197
+
198
+ Include the TouchPlaceholders module if your model is used within a
199
+ placeholder brick and define which templates it appears in:
200
+
201
+ ```ruby
202
+ class Dummy < ActiveRecord::Base
203
+ include Kuhsaft::TouchPlaceholders
204
+ placeholder_templates 'some_template', 'some_other_template'
205
+ end
206
+ ```
207
+
196
208
  ## Adding additional content languages
197
209
 
198
210
  If you want to translate your pages into another language, generate a new translation migration:
data/Rakefile CHANGED
@@ -32,6 +32,13 @@ module Postgres
32
32
  end
33
33
  end
34
34
 
35
+ def within_dummy_app
36
+ Dir.chdir('spec/dummy') do
37
+ ENV['BUNDLE_GEMFILE'] = File.join File.dirname(__FILE__), 'Gemfile'
38
+ yield
39
+ end
40
+ end
41
+
35
42
  desc 'Run specs'
36
43
  RSpec::Core::RakeTask.new(spec: :setup)
37
44
 
@@ -46,7 +53,7 @@ end
46
53
  desc 'set up the dummy app for testing'
47
54
  task :setup do
48
55
  Postgres.create_user 'screenconcept'
49
- Dir.chdir('spec/dummy') do
56
+ within_dummy_app do
50
57
  `bundle exec rake kuhsaft:install:migrations`
51
58
  `bundle exec rails generate kuhsaft:install:assets`
52
59
  `bundle exec rake db:create`
@@ -60,8 +67,16 @@ task default: [:spec]
60
67
 
61
68
  desc 'start the dummy app'
62
69
  task :start_dummy do
63
- Dir.chdir('spec/dummy') do
64
- ENV['BUNDLE_GEMFILE'] = '../../Gemfile'
70
+ within_dummy_app do
65
71
  `bundle exec rails server`
66
72
  end
67
73
  end
74
+
75
+ namespace :dummy_db do
76
+ desc 'migrate in dummy app'
77
+ task :migrate do
78
+ within_dummy_app do
79
+ `bundle exec rake db:migrate 2>&1`
80
+ end
81
+ end
82
+ end
@@ -1,3 +1,5 @@
1
+ require_relative '../../../lib/kuhsaft/brick_list'
2
+
1
3
  module Kuhsaft
2
4
  class Brick < ActiveRecord::Base
3
5
  include Kuhsaft::BrickList
@@ -31,6 +31,7 @@ module Kuhsaft
31
31
  validates :slug, presence: true
32
32
  validates :redirect_url, presence: true, if: :redirect?
33
33
  validates :title, :slug, :keywords, :page_type, length: { maximum: 255 }
34
+ validates :identifier, uniqueness: true, allow_blank: true
34
35
 
35
36
  class << self
36
37
  def flat_tree(pages = nil)
@@ -48,6 +49,10 @@ module Kuhsaft
48
49
 
49
50
  arr
50
51
  end
52
+
53
+ def by_identifier(identifier)
54
+ where(identifier: identifier).first
55
+ end
51
56
  end
52
57
 
53
58
  def without_self
@@ -1,3 +1,5 @@
1
+ require_relative './brick'
2
+
1
3
  module Kuhsaft
2
4
  class PlaceholderBrick < Brick
3
5
  PARTIAL_PATH = '/app/views/kuhsaft/placeholder_bricks/partials/_*.haml'
@@ -0,0 +1,6 @@
1
+ class AddIdentifierToKuhsaftPages < ActiveRecord::Migration
2
+ def change
3
+ add_column :kuhsaft_pages, :identifier, :string
4
+ add_index :kuhsaft_pages, :identifier, unique: true
5
+ end
6
+ end
@@ -6,6 +6,7 @@ module Kuhsaft
6
6
  require 'kuhsaft/searchable'
7
7
  require 'kuhsaft/brick_list'
8
8
  require 'kuhsaft/partial_extractor'
9
+ require 'kuhsaft/touch_placeholders'
9
10
  require 'simple_form'
10
11
  require 'carrierwave'
11
12
  require 'rdiscount'
@@ -0,0 +1,32 @@
1
+ require_relative '../../app/models/kuhsaft/placeholder_brick'
2
+
3
+ module Kuhsaft
4
+ module TouchPlaceholders
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+
8
+ base.class_eval do
9
+ after_save :touch_placeholders
10
+ end
11
+ end
12
+
13
+ def touch_placeholders
14
+ if self.class.placeholder_templates.present?
15
+ self.class.placeholder_templates.each do |template_name|
16
+ related_templates = Kuhsaft::PlaceholderBrick.where(template_name: template_name)
17
+ related_templates.each { |p| p.touch } if related_templates
18
+ end
19
+ end
20
+ end
21
+
22
+ module ClassMethods
23
+ def placeholder_templates(*attributes)
24
+ if attributes.empty?
25
+ @shoestrap_placeholder_templates
26
+ else
27
+ @shoestrap_placeholder_templates = attributes
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Kuhsaft
2
- VERSION = '2.3.0'
2
+ VERSION = '2.3.1'
3
3
  end
@@ -15,6 +15,11 @@ FactoryGirl.define do
15
15
  tb.text 'DummyText'
16
16
  end
17
17
 
18
+ factory :placeholder_brick, class: 'Kuhsaft::PlaceholderBrick' do |tb|
19
+ tb.type 'Kuhsaft::PlaceholderBrick'
20
+ tb.template_name 'foo'
21
+ end
22
+
18
23
  factory :asset, class: Kuhsaft::Asset do |a|
19
24
  a.file File.open("#{Kuhsaft::Engine.root}/spec/dummy/app/assets/images/spec-image.png")
20
25
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require_relative '../../lib/kuhsaft/touch_placeholders'
3
+
4
+ describe Kuhsaft::TouchPlaceholders do
5
+
6
+ before :all do
7
+ m = ActiveRecord::Migration.new
8
+ m.verbose = false
9
+ m.create_table :dummy_models do |t|
10
+ t.timestamps
11
+ end
12
+
13
+ class DummyModel < ActiveRecord::Base
14
+ include Kuhsaft::TouchPlaceholders
15
+ end
16
+
17
+ @page = FactoryGirl.create(:page)
18
+ @placeholder = FactoryGirl.create(:placeholder_brick, brick_list: @page, template_name: 'foo')
19
+ end
20
+
21
+ after :all do
22
+ m = ActiveRecord::Migration.new
23
+ m.verbose = false
24
+ m.drop_table :dummy_models
25
+
26
+ @page.destroy
27
+ @placeholder.destroy
28
+ end
29
+
30
+ describe 'placeholder_templates class method' do
31
+ it 'returns the attribute names defined with class macro' do
32
+ DummyModel.class_eval { placeholder_templates 'key_benefit_slider', 'key_benefit_grid' }
33
+ expect(DummyModel.placeholder_templates).to eq %w(key_benefit_slider key_benefit_grid)
34
+ end
35
+ end
36
+
37
+ describe 'after_save_callback' do
38
+ it 'looks for the bricks with affected templates and touches them' do
39
+ DummyModel.class_eval { placeholder_templates 'foo' }
40
+ expect_any_instance_of(Kuhsaft::PlaceholderBrick).to receive(:touch)
41
+ DummyModel.create
42
+ end
43
+ end
44
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Kuhsaft::Page do
4
- subject { described_class }
4
+ # subject { described_class }
5
5
 
6
6
  describe '.search' do
7
7
  before do
@@ -336,10 +336,10 @@ describe Kuhsaft::Page do
336
336
 
337
337
  describe '#fulltext' do
338
338
  let :page do
339
- p = create(:page, keywords: 'key words', description: 'descrip tion', title: 'my title')
340
- p.bricks << Kuhsaft::TextBrick.new(locale: I18n.locale, text: 'oh la la')
341
- p.save
342
- p
339
+ create(:page, keywords: 'key words', description: 'descrip tion', title: 'my title').tap do |p|
340
+ p.bricks << Kuhsaft::TextBrick.new(locale: I18n.locale, text: 'oh la la')
341
+ p.save
342
+ end
343
343
  end
344
344
 
345
345
  context 'when saved' do
@@ -437,4 +437,16 @@ describe Kuhsaft::Page do
437
437
  end
438
438
  end
439
439
  end
440
+
441
+ describe '#identifier' do
442
+ let(:cat_page) { create :page, identifier: 'cat_content' }
443
+
444
+ it 'should check for uniqueness' do
445
+ expect(build(:page, identifier: cat_page.identifier)).to be_invalid
446
+ end
447
+
448
+ it 'should be findable via scope' do
449
+ expect(Kuhsaft::Page.by_identifier(cat_page.identifier)).to eq(cat_page)
450
+ end
451
+ end
440
452
  end
@@ -1,5 +1,5 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- ENV['RAILS_ENV'] ||= 'test'
2
+ ENV['RAILS_ENV'] = 'test'
3
3
  require_relative File.expand_path('../dummy/config/environment.rb', __FILE__)
4
4
  require 'rspec/rails'
5
5
  require 'rspec/autorun'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuhsaft
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Immanuel Häussermann
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-03-26 00:00:00.000000000 Z
15
+ date: 2014-04-01 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rspec
@@ -32,16 +32,16 @@ dependencies:
32
32
  name: rspec-rails
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
- - - '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: 2.14.2
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - '>='
42
+ - - ~>
43
43
  - !ruby/object:Gem::Version
44
- version: '0'
44
+ version: 2.14.2
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: factory_girl_rails
47
47
  requirement: !ruby/object:Gem::Requirement
@@ -398,14 +398,14 @@ dependencies:
398
398
  requirements:
399
399
  - - ~>
400
400
  - !ruby/object:Gem::Version
401
- version: 4.0.0
401
+ version: 4.0.2
402
402
  type: :runtime
403
403
  prerelease: false
404
404
  version_requirements: !ruby/object:Gem::Requirement
405
405
  requirements:
406
406
  - - ~>
407
407
  - !ruby/object:Gem::Version
408
- version: 4.0.0
408
+ version: 4.0.2
409
409
  - !ruby/object:Gem::Dependency
410
410
  name: rails
411
411
  requirement: !ruby/object:Gem::Requirement
@@ -627,6 +627,7 @@ files:
627
627
  - db/migrate/15_add_alt_text_to_bricks.rb
628
628
  - db/migrate/16_update_default_value_for_page_type.rb
629
629
  - db/migrate/17_set_page_type_to_content_for_empty_fields.rb
630
+ - db/migrate/20140327141200_add_identifier_to_kuhsaft_pages.rb
630
631
  - db/seeds.rb
631
632
  - lib/generators/kuhsaft/assets/install_generator.rb
632
633
  - lib/generators/kuhsaft/translations/add_generator.rb
@@ -637,6 +638,7 @@ files:
637
638
  - lib/kuhsaft/page_tree.rb
638
639
  - lib/kuhsaft/partial_extractor.rb
639
640
  - lib/kuhsaft/searchable.rb
641
+ - lib/kuhsaft/touch_placeholders.rb
640
642
  - lib/kuhsaft/translatable.rb
641
643
  - lib/kuhsaft/version.rb
642
644
  - lib/kuhsaft.rb
@@ -704,6 +706,7 @@ files:
704
706
  - spec/lib/image_uploader_mounting_spec.rb
705
707
  - spec/lib/page_tree_spec.rb
706
708
  - spec/lib/searchable_spec.rb
709
+ - spec/lib/touch_placeholders_spec.rb
707
710
  - spec/lib/translatable_spec.rb
708
711
  - spec/models/accordion_brick_spec.rb
709
712
  - spec/models/accordion_item_brick_spec.rb
@@ -807,6 +810,7 @@ test_files:
807
810
  - spec/lib/image_uploader_mounting_spec.rb
808
811
  - spec/lib/page_tree_spec.rb
809
812
  - spec/lib/searchable_spec.rb
813
+ - spec/lib/touch_placeholders_spec.rb
810
814
  - spec/lib/translatable_spec.rb
811
815
  - spec/models/accordion_brick_spec.rb
812
816
  - spec/models/accordion_item_brick_spec.rb