constructor-pages 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,8 +53,8 @@ module ConstructorPages
53
53
 
54
54
  instance_variable_set('@'+@page.template.code_name.to_s, @page)
55
55
 
56
- @children_of_current_root = Page.children_of(@page.root)
57
- @children_of_current_page = Page.children_of(@page)
56
+ @children_of_current_root = @page.root.children
57
+ @children_of_current_page = @page.children
58
58
 
59
59
  respond_to do |format|
60
60
  format.html { render :template => "html_templates/#{@page.template.code_name}" }
@@ -107,8 +107,8 @@ module ConstructorPages
107
107
 
108
108
  instance_variable_set('@'+template.code_name.pluralize, @pages)
109
109
 
110
- @children_of_current_root = Page.children_of(@page.root)
111
- @children_of_current_page = Page.children_of(@page)
110
+ @children_of_current_root = @page.root.children
111
+ @children_of_current_page = @page.children
112
112
 
113
113
  render :template => "templates/#{template.code_name}_search"
114
114
  end
@@ -2,29 +2,27 @@
2
2
 
3
3
  module ConstructorPages
4
4
  class Field < ActiveRecord::Base
5
- attr_accessible :name, :code_name, :type_value, :template_id
5
+ attr_accessible :name, :code_name, :type_value, :template_id, :template
6
6
  validates_presence_of :name
7
-
8
- validate :method_uniqueness
9
-
10
7
  validates_uniqueness_of :code_name, :scope => :template_id
8
+ validate :method_uniqueness
11
9
 
12
10
  after_create :create_page_fields
13
11
  after_destroy :destroy_page_fields
14
12
 
15
13
  belongs_to :template
16
14
 
17
- has_one :string_type, :class_name => "Types::StringType"
18
- has_one :integer_type, :class_name => "Types::IntegerType"
19
- has_one :float_type, :class_name => "Types::FloatType"
20
- has_one :boolean_type, :class_name => "Types::BooleanType"
21
- has_one :text_type, :class_name => "Types::TextType"
22
- has_one :date_type, :class_name => "Types::DateType"
23
- has_one :html_type, :class_name => "Types::HtmlType"
24
- has_one :image_type, :class_name => "Types::ImageType"
15
+ has_one :string_type, class_name: 'Types::StringType'
16
+ has_one :integer_type, class_name: 'Types::IntegerType'
17
+ has_one :float_type, class_name: 'Types::FloatType'
18
+ has_one :boolean_type, class_name: 'Types::BooleanType'
19
+ has_one :text_type, class_name: 'Types::TextType'
20
+ has_one :date_type, class_name: 'Types::DateType'
21
+ has_one :html_type, class_name: 'Types::HtmlType'
22
+ has_one :image_type, class_name: 'Types::ImageType'
25
23
 
26
- acts_as_list :scope => :template_id
27
- default_scope :order => :position
24
+ acts_as_list scope: :template_id
25
+ default_scope order: :position
28
26
 
29
27
  private
30
28
 
@@ -33,28 +31,22 @@ module ConstructorPages
33
31
  or Page.first.respond_to?(code_name.pluralize) \
34
32
  or Page.first.respond_to?(code_name.singularize) \
35
33
  or template.self_and_ancestors.map{|t| t.code_name unless t.code_name == code_name}.include?(code_name.pluralize) \
36
- or template.self_and_ancestors.map{|t| t.code_name t.code_name == code_name}.include?(code_name.singularize) \
37
- or template.descendants.map{|t| t.code_name t.code_name == code_name}.include?(code_name.pluralize) \
38
- or template.descendants.map{|t| t.code_name t.code_name == code_name}.include?(code_name.singularize)
39
- errors.add(:base, "Такой метод уже используется")
34
+ or template.self_and_ancestors.map{|t| t.code_name unless t.code_name == code_name}.include?(code_name.singularize) \
35
+ or template.descendants.map{|t| t.code_name unless t.code_name == code_name}.include?(code_name.pluralize) \
36
+ or template.descendants.map{|t| t.code_name unless t.code_name == code_name}.include?(code_name.singularize)
37
+ errors.add(:base, 'Такой метод уже используется')
40
38
  end
41
39
  end
42
40
 
43
41
  def create_page_fields
44
42
  self.template.pages.each do |page|
45
- "constructor_pages/types/#{type_value}_type".classify.constantize.create(
46
- :page_id => page.id,
47
- :field_id => id
48
- )
43
+ "constructor_pages/types/#{type_value}_type".classify.constantize.create page_id: page.id, field_id: id
49
44
  end
50
45
  end
51
46
 
52
47
  def destroy_page_fields
53
48
  self.template.pages.each do |page|
54
- "constructor_pages/types/#{type_value}_type".classify.constantize.destroy_all(
55
- :page_id => page.id,
56
- :field_id => id
57
- )
49
+ "constructor_pages/types/#{type_value}_type".classify.constantize.destroy_all page_id: page.id, field_id: id
58
50
  end
59
51
  end
60
52
  end
@@ -4,45 +4,59 @@ module ConstructorPages
4
4
  class Page < ActiveRecord::Base
5
5
  attr_accessible :name, :title, :keywords, :description,
6
6
  :url, :full_url, :active, :auto_url,
7
- :parent_id, :link, :in_menu, :in_map,
8
- :in_nav, :template_id
9
-
10
- has_many :string_types,:dependent => :destroy, :class_name => "Types::StringType"
11
- has_many :float_types, :dependent => :destroy, :class_name => "Types::FloatType"
12
- has_many :boolean_types, :dependent => :destroy, :class_name => "Types::BooleanType"
13
- has_many :integer_types, :dependent => :destroy, :class_name => "Types::IntegerType"
14
- has_many :text_types, :dependent => :destroy, :class_name => "Types::TextType"
15
- has_many :date_types, :dependent => :destroy, :class_name => "Types::DateType"
16
- has_many :html_types, :dependent => :destroy, :class_name => "Types::HtmlType"
17
- has_many :image_types, :dependent => :destroy, :class_name => "Types::ImageType"
7
+ :parent, :parent_id, :link, :in_menu, :in_map,
8
+ :in_nav, :template_id, :template
9
+
10
+ has_many :string_types, dependent: :destroy, class_name: 'Types::StringType'
11
+ has_many :float_types, dependent: :destroy, class_name: 'Types::FloatType'
12
+ has_many :boolean_types, dependent: :destroy, class_name: 'Types::BooleanType'
13
+ has_many :integer_types, dependent: :destroy, class_name: 'Types::IntegerType'
14
+ has_many :text_types, dependent: :destroy, class_name: 'Types::TextType'
15
+ has_many :date_types, dependent: :destroy, class_name: 'Types::DateType'
16
+ has_many :html_types, dependent: :destroy, class_name: 'Types::HtmlType'
17
+ has_many :image_types, dependent: :destroy, class_name: 'Types::ImageType'
18
18
 
19
19
  belongs_to :template
20
20
 
21
- default_scope order(:lft)
21
+ default_scope order :lft
22
22
 
23
- before_save :url_prepare, :content_filter
24
- after_update :full_url_descendants_change
25
-
26
- before_update :full_url_change
27
- before_create :full_url_create
23
+ validate :template_check
28
24
 
25
+ before_save :friendly_url, :template_assign, :full_url_update
26
+ after_update :descendants_update
29
27
  after_create :create_fields
30
-
28
+
31
29
  acts_as_nested_set
32
-
33
- def self.children_of(page)
34
- Page.where(:parent_id => page)
30
+
31
+ # generate full_url from parent page and url
32
+ def self.full_url_generate(parent_id, url = '')
33
+ Page.find(parent_id).self_and_ancestors.map {|c| c.url}.append(url).join('/')
35
34
  end
36
35
 
37
- def field(code_name, meth = "value")
38
- field = ConstructorPages::Field.where(:code_name => code_name, :template_id => self.template_id).first
36
+ def field(code_name, meth = 'value')
37
+ field = Field.where(code_name: code_name, template_id: self.template_id).first
39
38
 
40
39
  if field
41
- f = "constructor_pages/types/#{field.type_value}_type".classify.constantize.where(:field_id => field.id, :page_id => self.id).first
40
+ f = "constructor_pages/types/#{field.type_value}_type".classify.constantize.where(field_id: field.id, page_id: self.id).first
42
41
  f.send(meth) if f
43
42
  end
44
43
  end
45
44
 
45
+ def as_json(options = {})
46
+ options = {
47
+ :name => self.name,
48
+ :title => self.title
49
+ }.merge options
50
+
51
+ self.template.fields.each do |field|
52
+ unless self.send(field.code_name)
53
+ options = {field.code_name => self.send(field.code_name)}.merge options
54
+ end
55
+ end
56
+
57
+ options
58
+ end
59
+
46
60
  def method_missing(name, *args, &block)
47
61
  name = name.to_s
48
62
 
@@ -61,56 +75,32 @@ module ConstructorPages
61
75
  end
62
76
  end
63
77
 
64
- def as_json(options = {})
65
- options = {
66
- :name => self.name,
67
- :title => self.title
68
- }.merge options
69
-
70
- self.template.fields.each do |field|
71
- unless self.send(field.code_name)
72
- options = {field.code_name => self.send(field.code_name)}.merge options
73
- end
74
- end
75
-
76
- options
77
- end
78
-
79
78
  private
80
79
 
81
- def full_url_change
82
- if parent_id
83
- self.full_url = '/' + Page.find(parent_id).self_and_ancestors.map {|c| c.url}.append(self.url).join('/')
84
- else
85
- self.full_url = '/' + self.url
86
- end
80
+ # if url has been changed by manually or url is empty
81
+ def friendly_url
82
+ self.url = ((auto_url || url.empty?) ? name : url).parameterize
87
83
  end
88
84
 
89
- def full_url_create
90
- if self.parent.nil?
91
- self.full_url = '/' + self.url
92
- else
93
- self.full_url = self.parent.full_url + '/' + self.url
94
- end
85
+ # page is not valid if there is no template
86
+ def template_check
87
+ errors.add_on_empty(:template_id) if Template.count == 0
95
88
  end
96
89
 
97
- def full_url_descendants_change
98
- self.descendants.each { |c| c.save }
90
+ # if template_id is nil then get first template
91
+ def template_assign
92
+ self.template_id = Template.first.id unless template_id
99
93
  end
100
94
 
101
- def url_prepare
102
- if self.auto_url or self.url.empty?
103
- self.url = self.name.parameterize
104
- else
105
- self.url = self.url.parameterize
106
- end
95
+ def full_url_update
96
+ self.full_url = '/' + (parent_id ? Page.full_url_generate(parent_id, url) : url)
107
97
  end
108
98
 
99
+ def descendants_update; descendants.map(&:save) end
100
+
109
101
  def create_fields
110
102
  template.fields.each do |field|
111
- "constructor_pages/types/#{field.type_value}_type".classify.constantize.create(
112
- :page_id => id,
113
- :field_id => field.id)
103
+ "constructor_pages/types/#{field.type_value}_type".classify.constantize.create page_id: id, field: field
114
104
  end
115
105
  end
116
106
  end
@@ -3,7 +3,8 @@
3
3
  module ConstructorPages
4
4
  class Template < ActiveRecord::Base
5
5
  attr_accessible :name, :code_name, :child_id, :parent_id
6
- validates_presence_of :name
6
+
7
+ validates_presence_of :name, :code_name
7
8
  validates_uniqueness_of :code_name
8
9
 
9
10
  validate :method_uniqueness
@@ -3,7 +3,7 @@
3
3
  module ConstructorPages
4
4
  module Types
5
5
  class BooleanType < ActiveRecord::Base
6
- attr_accessible :value, :field_id, :page_id
6
+ attr_accessible :value, :field_id, :field, :page_id, :page
7
7
 
8
8
  belongs_to :field
9
9
  belongs_to :page
@@ -3,7 +3,7 @@
3
3
  module ConstructorPages
4
4
  module Types
5
5
  class DateType < ActiveRecord::Base
6
- attr_accessible :value, :field_id, :page_id
6
+ attr_accessible :value, :field_id, :field, :page_id, :page
7
7
 
8
8
  belongs_to :field
9
9
  belongs_to :page
@@ -3,7 +3,7 @@
3
3
  module ConstructorPages
4
4
  module Types
5
5
  class FloatType < ActiveRecord::Base
6
- attr_accessible :value, :field_id, :page_id
6
+ attr_accessible :value, :field_id, :field, :page_id, :page
7
7
 
8
8
  belongs_to :field
9
9
  belongs_to :page
@@ -3,7 +3,7 @@
3
3
  module ConstructorPages
4
4
  module Types
5
5
  class HtmlType < ActiveRecord::Base
6
- attr_accessible :value, :field_id, :page_id
6
+ attr_accessible :value, :field_id, :field, :page_id, :page
7
7
 
8
8
  belongs_to :field
9
9
  belongs_to :page
@@ -3,7 +3,7 @@
3
3
  module ConstructorPages
4
4
  module Types
5
5
  class ImageType < ActiveRecord::Base
6
- attr_accessible :value, :field_id, :page_id
6
+ attr_accessible :value, :field_id, :field, :page_id, :page
7
7
 
8
8
  belongs_to :field
9
9
  belongs_to :page
@@ -3,7 +3,7 @@
3
3
  module ConstructorPages
4
4
  module Types
5
5
  class IntegerType < ActiveRecord::Base
6
- attr_accessible :value, :field_id, :page_id
6
+ attr_accessible :value, :field_id, :field, :page_id, :page
7
7
 
8
8
  belongs_to :field
9
9
  belongs_to :page
@@ -3,7 +3,7 @@
3
3
  module ConstructorPages
4
4
  module Types
5
5
  class StringType < ActiveRecord::Base
6
- attr_accessible :value, :field_id, :page_id
6
+ attr_accessible :value, :field_id, :field, :page_id, :page
7
7
 
8
8
  belongs_to :field
9
9
  belongs_to :page
@@ -3,7 +3,7 @@
3
3
  module ConstructorPages
4
4
  module Types
5
5
  class TextType < ActiveRecord::Base
6
- attr_accessible :value, :field_id, :page_id
6
+ attr_accessible :value, :field_id, :field, :page_id, :page
7
7
 
8
8
  belongs_to :field
9
9
  belongs_to :page
@@ -1,22 +1,32 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require File.expand_path('../../core/lib/constructor_core/version', __FILE__)
4
+
3
5
  Gem::Specification.new do |s|
4
6
  s.platform = Gem::Platform::RUBY
5
7
  s.name = %q{constructor-pages}
6
- s.version = '0.3.2'
7
- s.summary = %q{Pages for ConstructorCms}
8
+ s.version = ConstructorCore::VERSION
9
+ s.summary = %q{Pages for Constructor CMS}
8
10
  s.authors = ['Ivan Zotov']
9
11
  s.require_paths = %w(lib)
12
+ s.homepage = 'http://ivanzotov.github.com/constructor'
13
+ s.description = 'Pages for Constructor CMS'
14
+ s.email = 'ivanzotov@gmail.com'
10
15
 
11
16
  s.files = `git ls-files`.split("\n")
12
17
  s.test_files = `git ls-files -- spec/*`.split("\n")
13
18
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
14
-
19
+
20
+ s.add_dependency 'constructor-core', ConstructorCore::VERSION
21
+
15
22
  s.add_dependency 'dragonfly'
16
23
  s.add_dependency 'rack-cache'
17
24
  s.add_dependency 'awesome_nested_set', '~> 2.0'
18
25
  s.add_dependency 'haml-rails'
19
26
  s.add_dependency 'aws-s3'
20
27
  s.add_dependency 'russian', '~> 0.6.0'
21
- s.add_dependency 'RedCloth'
28
+ s.add_dependency 'RedCloth'
29
+ s.add_dependency 'acts_as_list'
30
+
31
+ s.add_development_dependency 'rspec-rails'
22
32
  end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module ConstructorPages
6
+ end
@@ -0,0 +1,148 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module ConstructorPages
6
+ describe Page do
7
+ before :all do
8
+ Template.delete_all
9
+ Template.create name: 'Page', code_name: 'page'
10
+
11
+
12
+ Field.delete_all
13
+ Types::TextType.delete_all
14
+ end
15
+
16
+ it 'should be valid' do
17
+ page = Page.create
18
+ page.valid?.should be_true
19
+ end
20
+
21
+ describe '.field' do
22
+ it 'should get value from type_field' do
23
+ template = Template.create name: 'Page template', code_name: 'page_template'
24
+ page = Page.create name: 'Home page', template: template
25
+ field = Field.create name: 'Content', code_name: 'desc', template: template, type_value: 'text'
26
+ page.field('desc').should == field.text_type.value
27
+ end
28
+ end
29
+
30
+ describe '.full_url_generate' do
31
+ it 'should generate full_url from parent_id and url' do
32
+ end
33
+ end
34
+
35
+ describe '#as_json' do
36
+ it 'should return page as json format with fields'
37
+ end
38
+
39
+ describe '#auto_url' do
40
+ it 'should be true by default' do
41
+ page = Page.create
42
+ page.auto_url.should be_true
43
+ end
44
+ end
45
+
46
+ describe '#template' do
47
+ context 'if there is no template' do
48
+ it 'should not be valid' do
49
+ Template.delete_all
50
+ page = Page.create
51
+ page.valid?.should_not be_true
52
+ Template.create name: 'Page', code_name: 'page'
53
+ end
54
+ end
55
+
56
+ context 'if template_id is nil' do
57
+ it 'should be first template' do
58
+ page = Page.create
59
+ page.template.should == Template.first
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '#url' do
65
+ context 'if url is empty or if auto_url is true' do
66
+ it 'should be generated from name' do
67
+ page = Page.create name: 'Hello world'
68
+ page.url.should == 'hello-world'
69
+ end
70
+ end
71
+
72
+ context 'else' do
73
+ it 'should get url field value' do
74
+ page = Page.create name: 'Hello', auto_url: true
75
+ page.url.should == 'hello'
76
+
77
+ page.auto_url = false
78
+ page.url = 'world'
79
+ page.save
80
+ page.url.should == 'world'
81
+
82
+ page.auto_url = true
83
+ page.name = 'Another world'
84
+ page.url = 'world-two'
85
+ page.save
86
+ page.url.should == 'another-world'
87
+ end
88
+ end
89
+ end
90
+
91
+ describe '#full_url' do
92
+ it 'should be generated from url and ancestors' do
93
+ page = Page.create name: 'Hello'
94
+ page.full_url.should == '/hello'
95
+
96
+ page_two = Page.create name: 'World', parent: page
97
+ page_two.full_url.should == '/hello/world'
98
+ end
99
+
100
+ context 'if parent or url has been changed' do
101
+ it 'should update full_url' do
102
+ page = Page.create name: 'Change url', url: 'change-url', auto_url: false
103
+ page.full_url.should == '/change-url'
104
+
105
+ page.url = 'another-change-url'
106
+ page.save
107
+ page.full_url.should == '/another-change-url'
108
+ end
109
+ end
110
+
111
+ context 'if parent is root or nil' do
112
+ it 'should be as /self.url' do
113
+ page = Page.create name: 'Page', url: 'page', auto_url: false, parent_id: nil
114
+ page.full_url.should == '/page'
115
+
116
+ parent = Page.create name: 'Parent'
117
+ page.parent = parent
118
+ page.save
119
+
120
+ page.full_url.should == '/parent/page'
121
+
122
+ page.parent = nil
123
+ page.save
124
+ page.full_url.should == '/page'
125
+ end
126
+ end
127
+ end
128
+
129
+ describe 'descendants_update' do
130
+ it 'should update descendants full_url' do
131
+ page = Page.create name: 'Update descendants', url: 'update-descendants', auto_url: false
132
+ page_two = Page.create name: 'Child', url: 'child', parent: page
133
+ page_two.full_url.should == '/update-descendants/child'
134
+
135
+ page = Page.find(page.id)
136
+ page.url = 'another-update-descendants'
137
+ page.save
138
+
139
+ page_two = Page.find(page_two.id)
140
+ page_two.full_url.should == '/another-update-descendants/child'
141
+ end
142
+ end
143
+
144
+ describe 'create_fields' do
145
+ it 'should create type_fields after update page'
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module ConstructorPages
6
+ describe Template do
7
+ it 'should be valid' do
8
+ template = Template.create name: 'Page template', code_name: 'page_template'
9
+ template.valid?.should be_true
10
+ end
11
+
12
+ describe '#code_name' do
13
+ context 'validation' do
14
+ it 'should be uniqueness'
15
+ end
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constructor-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-06 00:00:00.000000000 Z
12
+ date: 2013-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: constructor-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.3.3
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: dragonfly
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -123,8 +139,40 @@ dependencies:
123
139
  - - ! '>='
124
140
  - !ruby/object:Gem::Version
125
141
  version: '0'
126
- description:
127
- email:
142
+ - !ruby/object:Gem::Dependency
143
+ name: acts_as_list
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: rspec-rails
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ description: Pages for Constructor CMS
175
+ email: ivanzotov@gmail.com
128
176
  executables: []
129
177
  extensions: []
130
178
  extra_rdoc_files: []
@@ -196,9 +244,10 @@ files:
196
244
  - lib/constructor-pages.rb
197
245
  - lib/constructor_pages/engine.rb
198
246
  - public/hello.txt
199
- - spec/factories.rb
200
- - spec/models/page_model_spec.rb
201
- homepage:
247
+ - spec/models/constructor_pages/field_model_spec.rb
248
+ - spec/models/constructor_pages/page_model_spec.rb
249
+ - spec/models/constructor_pages/template_model_spec.rb
250
+ homepage: http://ivanzotov.github.com/constructor
202
251
  licenses: []
203
252
  post_install_message:
204
253
  rdoc_options: []
@@ -221,7 +270,8 @@ rubyforge_project:
221
270
  rubygems_version: 1.8.25
222
271
  signing_key:
223
272
  specification_version: 3
224
- summary: Pages for ConstructorCms
273
+ summary: Pages for Constructor CMS
225
274
  test_files:
226
- - spec/factories.rb
227
- - spec/models/page_model_spec.rb
275
+ - spec/models/constructor_pages/field_model_spec.rb
276
+ - spec/models/constructor_pages/page_model_spec.rb
277
+ - spec/models/constructor_pages/template_model_spec.rb
data/spec/factories.rb DELETED
@@ -1,7 +0,0 @@
1
- FactoryGirl.define do
2
- factory :page do
3
- sequence(:title) {|n| "Page title #{n}" }
4
- sequence(:url) {|n| "/page-#{n}" }
5
- content ""
6
- end
7
- end
@@ -1,113 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require './../spec/spec_helper'
4
-
5
- describe Page do
6
- describe "Title and Url" do
7
- before :each do
8
- Factory(:page, :title => "Hello", :url => '/hello')
9
- end
10
-
11
- it "should be unique" do
12
- page = Factory.build(:page, :title => "Hello", :url => '/hello')
13
- page.should_not be_valid
14
- page.url = '/hello@#$%^&'
15
- page.should_not be_valid
16
- page.should have(1).error_on(:base)
17
-
18
- page.url = "/world"
19
- page.should be_valid
20
- end
21
-
22
- it "should be unique even before save" do
23
- page = Factory.build(:page, :title => "Hello", :url => "")
24
-
25
- page.should_not be_valid
26
- page.should have(1).error_on(:base)
27
- end
28
- end
29
-
30
- describe "Title" do
31
- it "should not be empty" do
32
- page = Factory.build(:page, :title => ' ')
33
- page.should_not be_valid
34
- page.should have(1).error_on(:title)
35
- page.errors[:title].should == ['не может быть пустым']
36
-
37
- page.title = "Title"
38
- page.should be_valid
39
- end
40
- end
41
-
42
- describe "In nav, in menu, in map" do
43
- it "should be true by default" do
44
- page = Page.new
45
- page.in_nav.should be_true
46
- page.in_menu.should be_true
47
- page.in_map.should be_true
48
- end
49
-
50
- it "should change when given in new method" do
51
- page = Page.new(:in_nav => false, :in_menu => false, :in_map => false)
52
- page.in_nav.should be_false
53
- page.in_menu.should be_false
54
- page.in_map.should be_false
55
- end
56
- end
57
-
58
- describe "Parent" do
59
- it "should not be same as self" do
60
- page = Factory(:page)
61
- page.parent_id = page.id
62
-
63
- page.save
64
- page.should have(1).errors
65
- end
66
- end
67
-
68
- describe "Url" do
69
- context "Fix mistakes if remote" do
70
- it "should fix http// and http:/" do
71
- page = Factory(:page, :url => 'http:/myurl.com/')
72
- page.url.should == 'http://myurl.com/'
73
-
74
- page = Factory(:page, :url => 'http//myurl.com/')
75
- page.url.should == 'http://myurl.com/'
76
- end
77
- end
78
-
79
- context "If empty or nil" do
80
- it "should be generated from title" do
81
- page = Factory(:page, :title => " //Hello!@#$\%^&*() my WORLD /// привет// ", :url => ' ')
82
- page.url.should == "\/hello-my-world\/privet"
83
- end
84
-
85
- it "should add parent url before if parent selected" do
86
- page_parent = Factory(:page, :id => 1, :url => '/hello')
87
- page = Factory(:page, :parent_id => page_parent, :title => 'World', :url => ' ')
88
- page.url.should == '/hello/world'
89
-
90
- # if parent not selected
91
- page.parent_id = nil
92
- page.url = ' '
93
- page.save
94
- page.url.should == '/world'
95
- end
96
-
97
- it "should be empty when page not valid" do
98
- Factory(:page, :title => "Hello", :url => "/hello")
99
- page = Factory.build(:page, :title => "Hello", :url => "")
100
-
101
- page.should_not be_valid
102
- page.url.should == ""
103
- end
104
- end
105
-
106
- context "Finish cleanup" do
107
- it "should cleanup url: remove spaces, fix backslashes, unknown chars etc." do
108
- page = Factory(:page, :url => " //Hello!@#$\%^&*() my WORLD /// привет// ")
109
- page.url.should == "\/hello-my-world\/privet"
110
- end
111
- end
112
- end
113
- end