brightcontent-pages 2.0.33 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/brightcontent/pages.js +1 -2
  3. data/app/assets/stylesheets/brightcontent/pages.css.scss +1 -1
  4. data/app/helpers/render_sortable_tree_helper.rb +3 -58
  5. data/app/models/brightcontent/page_core.rb +27 -14
  6. data/app/views/brightcontent/pages/_form_field_body.html.erb +1 -1
  7. data/app/views/brightcontent/pages/_list_field_name.html.erb +1 -1
  8. data/app/views/brightcontent/pages/_page.html.erb +15 -0
  9. data/app/views/brightcontent/pages/index.html.erb +9 -7
  10. data/brightcontent-pages.gemspec +2 -1
  11. data/config/locales/brightcontent_pages.nl.yml +10 -0
  12. data/config/routes.rb +0 -7
  13. data/lib/brightcontent/pages/methods.rb +1 -1
  14. data/lib/brightcontent/pages/path_constraint.rb +26 -0
  15. data/lib/brightcontent/pages/routes.rb +13 -0
  16. data/lib/brightcontent/pages.rb +4 -0
  17. data/lib/generators/brightcontent/pages/install_generator.rb +4 -0
  18. data/script/rails +2 -2
  19. data/spec/dummy/config/application.rb +2 -6
  20. data/spec/dummy/config/environments/development.rb +1 -10
  21. data/spec/dummy/config/environments/production.rb +0 -4
  22. data/spec/dummy/config/environments/test.rb +1 -6
  23. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  24. data/spec/dummy/config/routes.rb +2 -1
  25. data/spec/dummy/db/migrate/20121206121725_create_brightcontent_admin_users.rb +1 -1
  26. data/spec/dummy/db/migrate/20140227110824_add_position_to_attachments.brightcontent_attachments_engine.rb +6 -0
  27. data/spec/dummy/db/schema.rb +16 -15
  28. data/spec/features/menu_spec.rb +1 -3
  29. data/spec/features/pages_index_spec.rb +3 -5
  30. data/spec/lib/brightcontent/pages/path_constraint_spec.rb +30 -0
  31. data/spec/models/brightcontent/page_spec.rb +21 -24
  32. metadata +48 -27
  33. data/app/assets/javascripts/brightcontent/wysithtml5-parser-rules.js +0 -553
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e852b578f63e5ca7873c1d786f9a0a796f31813
4
- data.tar.gz: 3df2f46ace5a26979aaa7361c607c962690a400e
3
+ metadata.gz: fce00f1da51773d10d82d547a0cac73e00965af5
4
+ data.tar.gz: e3819eb119baf8a62004b701c1c96ece8d7994d0
5
5
  SHA512:
6
- metadata.gz: 8aaf74cd4563675ae7f42a89a8e64957ed8ef12a9fdbae1d033a62acc60fa6d8d6a7a9a37a615e94abb5586e8c21185cfdb9b6f5bb24ae800fa6a49ff40e147f
7
- data.tar.gz: bdc5859f125da58bd9efa8c501f68b01a79c5fc6cf004aed345e6946ff068756bb10f6c9e26f35d184a15dcfcf796537665cca98b217097d2e60d2511589cbd7
6
+ metadata.gz: ebb8e5d9427bd83d768da06cc5a628360dbc5390b1bbea2309d026ac17ed847c39214425ce5ad609aa14fc2739486c81ff4483452bd0f9558d53aff66ba24445
7
+ data.tar.gz: 70784aa91cd3d3f763ea95664f082b4353abaa49c555caa710c60d312656e1ebdf0eb2023570f49c2e6a218c8b8140c8f27c0acbd1b26a26fd4b107396c66979
@@ -1,4 +1,3 @@
1
+ //= require jquery.ui.sortable
1
2
  //= require jquery.ui.nestedSortable
2
3
  //= require sortable_tree/initializer
3
- //= require brightcontent/wysithtml5-parser-rules
4
-
@@ -33,7 +33,7 @@
33
33
  }
34
34
 
35
35
  .handle{
36
- background: url(/assets/brightcontent/move.png) no-repeat;
36
+ background: image-url("brightcontent/move.png") no-repeat;
37
37
 
38
38
  width: 10px;
39
39
  height: 10px;
@@ -1,62 +1,7 @@
1
- # DOC:
2
- # We use Helper Methods for tree building,
3
- # because it's faster than View Templates and Partials
4
-
5
- # SECURITY note
6
- # Prepare your data on server side for rendering
7
- # or use h.html_escape(node.content)
8
- # for escape potentially dangerous content
9
1
  module RenderSortableTreeHelper
10
- module Render
11
- class << self
12
- attr_accessor :h, :options
13
-
14
- def render_node(h, options)
15
- @h, @options = h, options
16
-
17
- node = options[:node]
18
-
19
- "
20
- <li id='#{ node.id }_#{ options[:klass] }'>
21
- <div class='item #{"page-hidden" if node.hidden? }'>
22
- <i class='handle'></i>
23
- #{show_link}
24
- #{controls}
25
- </div>
26
- #{children}
27
- </li>
28
- "
29
- end
30
-
31
- def show_link
32
- node = options[:node]
33
- ns = options[:namespace]
34
- url = h.url_for(ns + [node])
35
- title_field = options[:title]
36
-
37
- h.link_to(node.send(title_field), url, class: 'link')
38
- end
39
-
40
- def controls
41
- node = options[:node]
42
-
43
- edit_path = h.url_for(:controller => options[:klass].pluralize, :action => :edit, :id => node)
44
- show_path = h.url_for(:controller => options[:klass].pluralize, :action => :show, :id => node)
45
-
46
- "
47
- <div class='controls'>
48
- #{ h.link_to 'Edit', edit_path, :class => 'btn btn-mini btn-primary btn-edit' }
49
- #{ h.link_to 'Delete', show_path, :class => 'btn btn-mini btn-delete', :method => :delete, :data => { :confirm => 'Are you sure?' } }
50
- </div>
51
- "
52
- end
53
-
54
- def children
55
- unless options[:children].blank?
56
- "<ol class='nested_set'>#{ options[:children] }</ol>"
57
- end
58
- end
59
-
2
+ module Render
3
+ def self.render_node(h, options)
4
+ h.render("page", item: options[:node], children: options[:children], klass: options[:klass])
60
5
  end
61
6
  end
62
7
  end
@@ -3,18 +3,30 @@ module Brightcontent
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- acts_as_nested_set
7
- has_attached_files Brightcontent.page_attachment_styles
8
- include Brightcontent::Attachable
9
6
  include TheSortableTree::Scopes
7
+
8
+ has_attached_files Brightcontent.page_attachment_styles
9
+ acts_as_nested_set
10
+
10
11
  validates_presence_of :name
11
- after_save :update_slug
12
- after_move :update_slug
12
+
13
+ after_save :update_slug, :expire_path_cache
14
+ after_move :update_slug, :expire_path_cache
15
+
16
+ default_scope { order(:lft) }
13
17
  end
14
18
 
15
19
  module ClassMethods
16
- def default_scope
17
- order(:lft)
20
+ def find_by_path(path)
21
+ find_by(slug: sanitize_path(path))
22
+ end
23
+
24
+ def find_by_path!(path)
25
+ find_by!(slug: sanitize_path(path))
26
+ end
27
+
28
+ def sanitize_path(path)
29
+ path[1..-1]
18
30
  end
19
31
  end
20
32
 
@@ -26,19 +38,20 @@ module Brightcontent
26
38
  "/" + slug
27
39
  end
28
40
 
29
- def root_parent_children
30
- root? ? children : ancestors.first.children
31
- end
32
-
33
41
  private
34
42
 
35
43
  def update_slug
36
- self.update_column(:slug, slug_name)
44
+ update_column(:slug, slug_name.to_s)
37
45
  end
38
46
 
39
47
  def slug_name
40
- homepage? ? "" : self_and_ancestors.map { |p| p.name.parameterize }.join("/")
48
+ unless homepage?
49
+ self_and_ancestors.map { |p| p.name.parameterize }.join("/")
50
+ end
51
+ end
52
+
53
+ def expire_path_cache
54
+ Pages::PathConstraint.expire
41
55
  end
42
56
  end
43
57
  end
44
-
@@ -1 +1 @@
1
- <%= form.input :body, input_html: { id: 'insertable' } %>
1
+ <%= form.input :body, input_html: { id: 'insertable', rows: 20, data: {wysihtml5: true} } %>
@@ -1 +1 @@
1
- <%= "—" * item.depth %> <%= item.name %> <% if item.hidden? %><span class="badge">Hidden</span><% end %>
1
+ <%= item.name %> <% if item.hidden? %><span class="badge"><%= t('brightcontent.hidden') %></span><% end %>
@@ -0,0 +1,15 @@
1
+ <li id="<%= item.id %>_brightcontent/page">
2
+ <div class='item'>
3
+ <i class='handle'></i>
4
+ <%= link_to item, class: 'link' do %>
5
+ <%= render_list_field(item, :name) %>
6
+ <% end %>
7
+ <div class='controls'>
8
+ <%= link_to t('brightcontent.edit'), [:edit, item], class: "btn btn-xs btn-primary" %>
9
+ <%= link_to t('brightcontent.delete'), item, class: "btn btn-xs btn-danger", data: {confirm: 'Are you sure?'}, method: :delete %>
10
+ </div>
11
+ </div>
12
+ <% unless children.blank? %>
13
+ <ol class='nested_set'><%= raw children %></ol>
14
+ <% end %>
15
+ </li>
@@ -1,10 +1,12 @@
1
- <div id="overview">
1
+ <div class="page-header">
2
+ <%= link_to "#{I18n.t('brightcontent.create_new', model: resource_class.model_name.human).humanize}", polymorphic_url([parent, resource_class], action: :new), class: "btn btn-primary pull-right" %>
3
+ <h1><%= nominative_plural(resource_class).capitalize %></h1>
4
+ </div>
2
5
 
3
- <%= link_to "Create new #{resource_instance_name.to_s.humanize}", polymorphic_url([parent, resource_class], action: :new), class: "btn btn-primary btn-right" %>
4
- <h1><%= resource_collection_name.to_s.humanize %></h1>
5
- <%= render "index_top" %>
6
+ <%= render_if_exists "index_top" %>
6
7
 
7
- <%= content_tag("ol", class:"sortable_tree", :"data-rebuild_url" => rebuild_pages_url, :"data-max_levels" => 5 ) do -%>
8
- <%= sortable_tree @pages, title:"name" -%>
9
- <% end -%>
8
+ <div class="panel-body">
9
+ <ol class="sortable_tree" data-rebuild_url="<%=rebuild_pages_url%>" data-max_levels="5">
10
+ <%= sortable_tree collection %>
11
+ </ol>
10
12
  </div>
@@ -17,7 +17,8 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_dependency "brightcontent-core", version
19
19
  s.add_dependency "brightcontent-attachments", version
20
- s.add_dependency "awesome_nested_set"
20
+ s.add_dependency "awesome_nested_set", ">= 3.0.0.rc.3"
21
+ s.add_dependency "jquery-ui-rails", ">= 2.3.0"
21
22
  s.add_dependency "the_sortable_tree", "~> 2.3.0"
22
23
 
23
24
  s.add_development_dependency "sqlite3"
@@ -0,0 +1,10 @@
1
+ nl:
2
+ activerecord:
3
+ models:
4
+ brightcontent/page: Pagina
5
+ attributes:
6
+ brightcontent/page:
7
+ name: Naam
8
+ body: Inhoud
9
+ hidden: Verborgen
10
+ parent_id: Bovenliggende pagina
data/config/routes.rb CHANGED
@@ -1,9 +1,2 @@
1
1
  Brightcontent::Engine.routes.draw do
2
- resources :pages do
3
- collection do
4
- get :index
5
- post :rebuild
6
- end
7
- end
8
- root to: "pages#index"
9
2
  end
@@ -2,7 +2,7 @@ module Brightcontent
2
2
  module Pages
3
3
  module Methods
4
4
  def current_page
5
- @current_page ||= Page.find_by_slug!(request.fullpath[1..-1])
5
+ @current_page ||= Page.find_by_path!(request.path)
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,26 @@
1
+ module Brightcontent
2
+ module Pages
3
+ class PathConstraint
4
+ CACHE_KEY = :brightcontent_page_slugs
5
+
6
+ def self.expire
7
+ Rails.cache.delete(CACHE_KEY)
8
+ end
9
+
10
+ def matches?(request)
11
+ slug = Page.sanitize_path(request.path)
12
+ cached_page_slugs.include?(slug)
13
+ end
14
+
15
+ private
16
+
17
+ def cached_page_slugs
18
+ Rails.cache.fetch(CACHE_KEY) { page_slugs }
19
+ end
20
+
21
+ def page_slugs
22
+ Page.pluck(:slug)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+ def pages_resources(&block)
4
+ resources :pages do
5
+ collection do
6
+ get :index
7
+ post :rebuild
8
+ end
9
+ instance_eval &block if block_given?
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,16 +1,20 @@
1
1
  require "brightcontent-core"
2
2
  require "brightcontent-attachments"
3
3
  require "awesome_nested_set"
4
+ require "jquery-ui-rails"
4
5
  require "the_sortable_tree"
5
6
 
7
+ require "brightcontent/pages/routes"
6
8
  require "brightcontent/pages/engine"
7
9
 
8
10
  module Brightcontent
11
+ register_extension 'pages'
9
12
 
10
13
  mattr_accessor :page_attachment_styles
11
14
  @@page_attachment_styles = {}
12
15
 
13
16
  module Pages
14
17
  autoload :Methods, 'brightcontent/pages/methods'
18
+ autoload :PathConstraint, 'brightcontent/pages/path_constraint'
15
19
  end
16
20
  end
@@ -9,6 +9,10 @@ module Brightcontent
9
9
  rake "brightcontent_pages_engine:install:migrations"
10
10
  end
11
11
 
12
+ def add_routes
13
+ inject_into_file 'config/routes.rb', "\n pages_resources", { :after => "brightcontent_resources do" }
14
+ end
15
+
12
16
  end
13
17
  end
14
18
  end
data/script/rails CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
3
 
4
- ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
- ENGINE_PATH = File.expand_path('../../lib/brightcontent/pages/engine', __FILE__)
4
+ ENGINE_ROOT = File.expand_path('../../../core', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../../core/lib/brightcontent/engine', __FILE__)
6
6
 
7
7
  require 'rails/all'
8
8
  require 'rails/engine/commands'
@@ -43,15 +43,11 @@ module Dummy
43
43
  # like if you have constraints or database-specific column types
44
44
  # config.active_record.schema_format = :sql
45
45
 
46
- # Enforce whitelist mode for mass assignment.
47
- # This will create an empty whitelist of attributes available for mass-assignment for all models
48
- # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
49
- # parameters by using an attr_accessible or attr_protected declaration.
50
- config.active_record.whitelist_attributes = false
51
-
52
46
  # Enable the asset pipeline
53
47
  config.assets.enabled = true
54
48
 
49
+ # config.i18n.enforce_available_locales = true
50
+
55
51
  # Version of your assets, change this if you want to expire all your assets
56
52
  config.assets.version = '1.0'
57
53
  end
@@ -1,14 +1,12 @@
1
1
  Dummy::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb
3
+ config.eager_load = false
3
4
 
4
5
  # In the development environment your application's code is reloaded on
5
6
  # every request. This slows down response time but is perfect for development
6
7
  # since you don't have to restart the web server when you make code changes.
7
8
  config.cache_classes = false
8
9
 
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
10
  # Show full error reports and disable caching
13
11
  config.consider_all_requests_local = true
14
12
  config.action_controller.perform_caching = false
@@ -22,13 +20,6 @@ Dummy::Application.configure do
22
20
  # Only use best-standards-support built into browsers
23
21
  config.action_dispatch.best_standards_support = :builtin
24
22
 
25
- # Raise exception on mass assignment protection for Active Record models
26
- config.active_record.mass_assignment_sanitizer = :strict
27
-
28
- # Log the query plan for queries taking more than this (works
29
- # with SQLite, MySQL, and PostgreSQL)
30
- config.active_record.auto_explain_threshold_in_seconds = 0.5
31
-
32
23
  # Do not compress assets
33
24
  config.assets.compress = false
34
25
 
@@ -60,8 +60,4 @@ Dummy::Application.configure do
60
60
 
61
61
  # Send deprecation notices to registered listeners
62
62
  config.active_support.deprecation = :notify
63
-
64
- # Log the query plan for queries taking more than this (works
65
- # with SQLite, MySQL, and PostgreSQL)
66
- # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
63
  end
@@ -1,5 +1,6 @@
1
1
  Dummy::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb
3
+ config.eager_load = false
3
4
 
4
5
  # The test environment is used exclusively to run your application's
5
6
  # test suite. You never need to work with it otherwise. Remember that
@@ -11,9 +12,6 @@ Dummy::Application.configure do
11
12
  config.serve_static_assets = true
12
13
  config.static_cache_control = "public, max-age=3600"
13
14
 
14
- # Log error messages when you accidentally call methods on nil
15
- config.whiny_nils = true
16
-
17
15
  # Show full error reports and disable caching
18
16
  config.consider_all_requests_local = true
19
17
  config.action_controller.perform_caching = false
@@ -29,9 +27,6 @@ Dummy::Application.configure do
29
27
  # ActionMailer::Base.deliveries array.
30
28
  config.action_mailer.delivery_method = :test
31
29
 
32
- # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
34
-
35
30
  # Print deprecation notices to the stderr
36
31
  config.active_support.deprecation = :stderr
37
32
  end
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- Dummy::Application.config.secret_token = '1582af16879d84e4319aa02ea51964c7c27576e6468838ea1bcadf1286623d44e9117613a747386fde1bc2253a9a49c291a2c100fec64ae5c2cc5c75efa553ef'
7
+ Dummy::Application.config.secret_key_base = '1582af16879d84e4319aa02ea51964c7c27576e6468838ea1bcadf1286623d44e9117613a747386fde1bc2253a9a49c291a2c100fec64ae5c2cc5c75efa553ef'
@@ -1,6 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
  brightcontent_resources do
3
+ pages_resources
3
4
  end
4
5
  root to: "pages#index"
5
- get "*path" => "pages#show"
6
+ get "*path" => "pages#show", constraints: Brightcontent::Pages::PathConstraint.new
6
7
  end
@@ -7,6 +7,6 @@ class CreateBrightcontentAdminUsers < ActiveRecord::Migration
7
7
  t.timestamps
8
8
  end
9
9
 
10
- Brightcontent::AdminUser.create!(:email => 'admin@example.com', :password => 'password')
10
+ Brightcontent::AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')
11
11
  end
12
12
  end
@@ -0,0 +1,6 @@
1
+ # This migration comes from brightcontent_attachments_engine (originally 20140203140819)
2
+ class AddPositionToAttachments < ActiveRecord::Migration
3
+ def change
4
+ add_column :brightcontent_attachments, :position, :integer
5
+ end
6
+ end
@@ -9,32 +9,33 @@
9
9
  # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
10
  # you'll amass, the slower it'll run and the greater likelihood for issues).
11
11
  #
12
- # It's strongly recommended to check this file into your version control system.
12
+ # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20130105142936) do
14
+ ActiveRecord::Schema.define(version: 20140227110824) do
15
15
 
16
- create_table "brightcontent_admin_users", :force => true do |t|
16
+ create_table "brightcontent_admin_users", force: true do |t|
17
17
  t.string "email"
18
18
  t.string "password_digest"
19
- t.datetime "created_at", :null => false
20
- t.datetime "updated_at", :null => false
19
+ t.datetime "created_at", null: false
20
+ t.datetime "updated_at", null: false
21
21
  end
22
22
 
23
- create_table "brightcontent_attachments", :force => true do |t|
23
+ create_table "brightcontent_attachments", force: true do |t|
24
24
  t.integer "attachable_id"
25
25
  t.string "attachable_type"
26
26
  t.string "asset_file_name"
27
27
  t.string "asset_content_type"
28
28
  t.integer "asset_file_size"
29
29
  t.datetime "asset_updated_at"
30
- t.datetime "created_at", :null => false
31
- t.datetime "updated_at", :null => false
30
+ t.datetime "created_at", null: false
31
+ t.datetime "updated_at", null: false
32
+ t.integer "position"
32
33
  end
33
34
 
34
- add_index "brightcontent_attachments", ["attachable_id"], :name => "index_brightcontent_attachments_on_attachable_id"
35
- add_index "brightcontent_attachments", ["attachable_type"], :name => "index_brightcontent_attachments_on_attachable_type"
35
+ add_index "brightcontent_attachments", ["attachable_id"], name: "index_brightcontent_attachments_on_attachable_id"
36
+ add_index "brightcontent_attachments", ["attachable_type"], name: "index_brightcontent_attachments_on_attachable_type"
36
37
 
37
- create_table "brightcontent_pages", :force => true do |t|
38
+ create_table "brightcontent_pages", force: true do |t|
38
39
  t.string "name"
39
40
  t.text "body"
40
41
  t.string "slug"
@@ -42,11 +43,11 @@ ActiveRecord::Schema.define(:version => 20130105142936) do
42
43
  t.integer "lft"
43
44
  t.integer "rgt"
44
45
  t.integer "parent_id"
45
- t.datetime "created_at", :null => false
46
- t.datetime "updated_at", :null => false
47
- t.boolean "hidden", :default => false, :null => false
46
+ t.datetime "created_at", null: false
47
+ t.datetime "updated_at", null: false
48
+ t.boolean "hidden", default: false, null: false
48
49
  end
49
50
 
50
- add_index "brightcontent_pages", ["slug"], :name => "index_brightcontent_pages_on_slug"
51
+ add_index "brightcontent_pages", ["slug"], name: "index_brightcontent_pages_on_slug"
51
52
 
52
53
  end
@@ -1,16 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  feature "Menu" do
4
-
5
4
  scenario "Shows menu for extra resources" do
6
5
  sign_in
7
6
  menu_should_have_link "Pages"
8
7
  end
9
8
 
10
9
  def menu_should_have_link(link_name)
11
- within "#menu" do
10
+ within ".js-menu" do
12
11
  page.should have_link link_name
13
12
  end
14
13
  end
15
-
16
14
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  feature "Pages index" do
4
-
5
4
  background do
6
5
  sign_in
7
6
  create(:page, name: "Test page")
@@ -9,13 +8,13 @@ feature "Pages index" do
9
8
 
10
9
  scenario "click on edit page" do
11
10
  click_link "Pages"
12
- page.find(:css, '.controls .btn-edit').click
13
- page.should have_content "Edit Page"
11
+ page.find(:css, '.controls .btn-primary').click
12
+ page.should have_content "Edit page"
14
13
  end
15
14
 
16
15
  scenario "click on delete page" do
17
16
  click_link "Pages"
18
- page.find(:css, '.controls .btn-delete').click
17
+ page.find(:css, '.controls .btn-danger').click
19
18
  page.should_not have_content "Test page"
20
19
  page.should have_content "successfully"
21
20
  end
@@ -25,5 +24,4 @@ feature "Pages index" do
25
24
  click_link "Pages"
26
25
  page.should have_css(".sortable_tree li", :count => 41)
27
26
  end
28
-
29
27
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module Brightcontent
4
+ module Pages
5
+ describe PathConstraint do
6
+ describe "#expire" do
7
+ it 'clear the cache' do
8
+ expect(Rails.cache).to receive(:delete)
9
+ PathConstraint.expire
10
+ end
11
+ end
12
+
13
+ describe ".matches?" do
14
+ before do
15
+ PathConstraint.expire
16
+ allow(Page).to receive(:pluck) { ['existing'] }
17
+ end
18
+
19
+ it 'returns true if path is existing' do
20
+ request = double(:request, path: '/existing')
21
+ expect(subject.matches?(request)).to be_true
22
+ end
23
+ it 'returns false if path is non-existing' do
24
+ request = double(:request, path: '/nonexisting')
25
+ expect(subject.matches?(request)).to be_false
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -8,6 +8,27 @@ module Brightcontent
8
8
  end
9
9
  end
10
10
 
11
+ describe "callbacks" do
12
+ it 'expires path cache after commit' do
13
+ expect(Pages::PathConstraint).to receive(:expire)
14
+ create(:page)
15
+ end
16
+ end
17
+
18
+ describe "#find_by_path" do
19
+ it 'finds the page by path' do
20
+ create(:page)
21
+ page = create(:page, name: "About us")
22
+ expect(Page.find_by_path('/about-us')).to eq page
23
+ end
24
+ end
25
+
26
+ describe '#sanitize_path' do
27
+ it 'removes the leading slash' do
28
+ expect(Page.sanitize_path('/path')).to eq 'path'
29
+ end
30
+ end
31
+
11
32
  describe "slugs" do
12
33
  context "first page" do
13
34
  subject { create(:page, name: "Homepage") }
@@ -55,29 +76,5 @@ module Brightcontent
55
76
  it { should_not be_homepage }
56
77
  end
57
78
  end
58
-
59
- describe "root_parent_children" do
60
- it "returns the children if page is root element" do
61
- root, child = build(:page), build(:page)
62
- root.children << child
63
- root.root_parent_children.should == [child]
64
- end
65
-
66
- it "returns the children of parent if page has parent" do
67
- root, page, child = create(:page), create(:page), create(:page)
68
- root.children << page
69
- page.children << child
70
- page.root_parent_children.should == [page]
71
- end
72
-
73
- it "returns the children of root parent if page has multiple parent" do
74
- root1, root2, page = create(:page), create(:page), create(:page)
75
- root1.children << root2
76
- root2.children << page
77
- page.root_parent_children.should == [root2]
78
- end
79
-
80
- end
81
-
82
79
  end
83
80
  end