classiccms 0.5.6 → 0.5.7

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.
data/Guardfile CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
2
  # --drb
3
- guard 'rspec', :cli => "--fail-fast", :notification => false do
4
- watch /(lib|spec).*/
3
+ guard :rspec, :cli => "--fail-fast" do
4
+ #watch(%r{^.*$}) #{|m| "spec/#{m[1]}_spec.rb" }
5
+ #watch(%r{^spec/(.+)\.rb$}) #{|m| "spec/#{m[1]}_spec.rb" }
5
6
  end
data/classiccms.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency "rack-test"
26
26
 
27
27
  #database
28
- s.add_runtime_dependency "mongoid", '2.4.11'
28
+ s.add_runtime_dependency "mongoid", '3.0.3'
29
29
  s.add_runtime_dependency "mongo", '1.6.2'
30
30
  s.add_runtime_dependency "bson_ext", '1.5'
31
31
 
@@ -58,7 +58,7 @@ module Classiccms
58
58
 
59
59
  #FROM App
60
60
  #require mongoid
61
- Mongoid.load!(File.join(Dir.pwd, 'config/mongoid.yml'))
61
+ Mongoid.load!(File.join(Dir.pwd, 'config/mongoid.yml'), ENV['RACK_ENV'])
62
62
 
63
63
  $app.configure do |d|
64
64
  d.url_format = '/assets/:job'
@@ -26,7 +26,7 @@ module Classiccms
26
26
  end
27
27
  get '/:id/?*' do
28
28
  response.headers['Cache-Control'] = 'no-cache'
29
- pass unless Slug.exists?(conditions: {_id: params[:id]})
29
+ pass unless Slug.where(_id: params[:id]).exists?
30
30
  index = CONFIG[:home].kind_of?(String) ? CONFIG[:home] : 'application/index'
31
31
 
32
32
 
@@ -1,16 +1,25 @@
1
1
  class ImageField
2
- include Mongoid::Fields::Serializable
2
+ #include Mongoid::Fields::Serializable
3
3
 
4
- def deserialize(object)
5
- Image.find(object).file
6
- end
4
+ class << self
5
+
6
+ # Get the object as it was stored in the database, and instantiate
7
+ # this custom class from it.
8
+ def demongoize(object)
9
+ Image.find(object).file
10
+ end
7
11
 
8
- def serialize(object)
9
- if object.class == BSON::ObjectId
10
- return object
11
- else
12
- return BSON::ObjectId(object)
12
+ # Takes any possible object and converts it to how it would be
13
+ # stored in the database.
14
+ def mongoize(object)
15
+ case object
16
+ when BSON::ObjectId then object
17
+ else BSON::ObjectId(object)
18
+ end
13
19
  end
20
+
21
+ # Converts the object that was supplied to a criteria and converts it
22
+ # into a database friendly form.
14
23
  end
15
24
  end
16
25
 
@@ -108,7 +108,7 @@ module Classiccms
108
108
 
109
109
  #simple function that return id if user is allowed to sort the item
110
110
  def sort(object)
111
- if object.kind_of? BSON::ObjectId or object.kind_of? String
111
+ if object.kind_of? Moped::BSON::ObjectId or object.kind_of? String
112
112
  object = Base.where(:_id => object).first
113
113
  end
114
114
  if @user != nil
@@ -3,7 +3,7 @@ module Classiccms
3
3
 
4
4
  #in charge of get the first item of a given model (for menu items etc.)
5
5
  def get_first_item
6
- Base.where(:_type => CONFIG[:model], :connections.matches => {:parent => nil, :section => CONFIG[:section], :order_id.lte => 1}).first
6
+ Base.where(:_type => CONFIG[:model], :'connections.parrent' => nil, :'connections.section' => CONFIG[:section], :'connections.order_id'.lte => 1).first
7
7
  end
8
8
 
9
9
  #This method will get you the most awesome route through a tree! (OMG!)
@@ -1,5 +1,7 @@
1
1
  require 'mongoid'
2
-
2
+ Mongoid::Fields.option :input do |model, field, value|
3
+ #model.validates_presence_of field if value
4
+ end
3
5
  class Base
4
6
  include Mongoid::Document
5
7
  include Mongoid::Timestamps
@@ -15,7 +17,7 @@ class Base
15
17
 
16
18
 
17
19
  def remove_slugs
18
- Slug.where(:document_id => id).destroy
20
+ Slug.delete_all(:document_id => id)
19
21
  end
20
22
  def remove_connections
21
23
  records = Base.where(:'connections.parent_id' => id)
@@ -3,7 +3,7 @@ class Connection
3
3
  embedded_in :base
4
4
 
5
5
  field :order_id, type: Integer, default: 0
6
- field :parent_id, type: BSON::ObjectId
6
+ field :parent_id, type: Moped::BSON::ObjectId
7
7
  field :file, type: String
8
8
  field :section, type: String
9
9
 
@@ -12,7 +12,7 @@ class Connection
12
12
  validate :parent_id_should_exist
13
13
 
14
14
  def parent_id_should_exist
15
- if parent_id != nil and !Base.exists?(conditions: {id: parent_id})
15
+ if parent_id != nil and !Base.where(_id: parent_id).exists?
16
16
  errors.add :parent_id, "id doesn't exist"
17
17
  end
18
18
  end
@@ -2,25 +2,25 @@ require 'cgi'
2
2
 
3
3
  class Slug
4
4
  include Mongoid::Document
5
- identity :type => String
6
- field :document_id, type: BSON::ObjectId
5
+ field :_id, :type => String
6
+ field :document_id, type: Moped::BSON::ObjectId
7
7
 
8
8
  #validations
9
9
  validate :document_id_should_exist
10
10
 
11
11
  def document_id_should_exist
12
- if !Base.exists?(conditions: {id: document_id})
12
+ if !Base.where(_id: document_id).exists?
13
13
  errors.add :document_id, "id doesn't exist"
14
14
  end
15
15
  end
16
16
 
17
17
  def generate_id
18
18
  i = 0
19
- i+=1 while Slug.exists? conditions: {id: i.to_s}
19
+ i+=1 while Slug.where(_id: i.to_s).exists?
20
20
  self.id = i.to_s
21
21
  end
22
22
  def set_id(url)
23
- Slug.where(id: url).delete_all
24
- self.id = url.gsub(/[^a-zA-Z0-9\-\/]+/, '-').downcase
23
+ Slug.delete_all(_id: url)
24
+ self._id = url.gsub(/[^a-zA-Z0-9\-\/]+/, '-').downcase
25
25
  end
26
26
  end
@@ -1,7 +1,7 @@
1
1
  defaults: &defaults
2
- host: 127.0.0.1
3
- port: 27017
4
2
  logger: false
3
+ hosts:
4
+ - localhost:27017
5
5
  # slaves:
6
6
  # - host: slave1.local
7
7
  # port: 27018
@@ -9,14 +9,23 @@ defaults: &defaults
9
9
  # port: 27019
10
10
 
11
11
  development:
12
- <<: *defaults
13
- database: $_development
12
+ sessions:
13
+ default:
14
+ hosts:
15
+ - localhost:27017
16
+ database: $_development
14
17
 
15
18
  test:
16
- <<: *defaults
17
- database: $_test
19
+ sessions:
20
+ default:
21
+ hosts:
22
+ - localhost:27017
23
+ database: $_test
18
24
 
19
25
  # set these environment variables on your prod server
20
26
  production:
21
- <<: *defaults
22
- database: $
27
+ sessions:
28
+ default:
29
+ hosts:
30
+ - localhost:27017
31
+ database: $
@@ -1,3 +1,3 @@
1
1
  module Classiccms #:nodoc
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
@@ -7,7 +7,7 @@
7
7
  = show :form, {}, {:record => record}
8
8
  #edit_bottom
9
9
  #edit_bottom_nav
10
- - if !record.new?
10
+ - if !record.new_record?
11
11
  .delete{:id => record.id}
12
12
  .delete_item item verwijderen
13
13
  .cancel
@@ -1,7 +1,7 @@
1
- %form{:action=>"/cms/#{record.new? ? 'create' : 'update' }", :method=>'post', :enctype=>'multypart/form-date'}
1
+ %form{:action=>"/cms/#{record.new_record? ? 'create' : 'update' }", :method=>'post', :enctype=>'multypart/form-date'}
2
2
  #edit_bg
3
3
  - model = record.class
4
- - if !record.new?
4
+ - if !record.new_record?
5
5
  %input{:type=>'hidden', :name=> "[#{model}][id]", :value=> record.id}
6
6
  - model.fields.each do |key, info|
7
7
  .item
@@ -23,7 +23,7 @@
23
23
  - when 'images'
24
24
  - else
25
25
  %label Comming soon
26
- - if record.new?
26
+ - if record.new_record?
27
27
  - record.connections.each do |connection|
28
28
  %input{:type=> 'hidden', :name=> "[#{record.class}][connections][][id]", :value => connection.id}
29
29
  %input{:type=> 'hidden', :name=> "[#{record.class}][connections][][parent_id]", :value => connection.parent_id}
@@ -1,22 +1,11 @@
1
- defaults: &defaults
2
- host: 127.0.0.1
3
- port: 27017
4
- logger: false
5
- # slaves:
6
- # - host: slave1.local
7
- # port: 27018
8
- # - host: slave2.local
9
- # port: 27019
10
-
11
1
  development:
12
- <<: *defaults
13
- database: ClassicCMS_development
14
-
2
+ sessions:
3
+ default:
4
+ database: mongoid
5
+ - localhost:27017
15
6
  test:
16
- <<: *defaults
17
- database: ClassicCMS_test
18
-
19
- # set these environment variables on your prod server
20
- production:
21
- <<: *defaults
22
- database: ClassicCMS
7
+ sessions:
8
+ default:
9
+ database: mongoid
10
+ hosts:
11
+ - localhost:27017
@@ -63,6 +63,7 @@ describe Classiccms do
63
63
  end
64
64
  it 'logout should destroy all session variables' do
65
65
  file 'haml', "= session[:user_id]" do
66
+ User.all.destroy
66
67
  u = create :user
67
68
  post '/login', {:username => u.username, :password => u.password}
68
69
  follow_redirect!
data/spec/helpers_spec.rb CHANGED
@@ -99,11 +99,10 @@ describe Classiccms do
99
99
  it 'should return the rendered file' do
100
100
  with_constants :CONFIG => {home: 'application/index4', model: 'Menu', section: 'menu'} do
101
101
  set_file "views/application/index4.haml", "= layout 'menu', 1"
102
- create_dir 'views/Menu'
103
- set_file "views/Menu/index.haml", "%h1 menu"
102
+ create_dir 'views/menu'
103
+ set_file "views/menu/index.haml", "%h1 menu"
104
104
 
105
105
  m = Menu.create connections: [Connection.new(section: 'menu', file: 'index')]
106
- m.connections
107
106
 
108
107
  get '/'
109
108
  last_response.body.should == "<h1>menu</h1>\n"
@@ -37,7 +37,7 @@ describe 'Base' do
37
37
  b1 = Base.create
38
38
  Slug.create(:document_id => b1.id)
39
39
  Slug.count.should == 1
40
- b1.destroy
40
+ b1.destroy!
41
41
 
42
42
  Slug.count.should == 0
43
43
  end
@@ -30,7 +30,7 @@ describe :Connection do
30
30
  end
31
31
  it 'should not allow a string' do
32
32
  @connection.order_id = 'string'
33
- @connection.valid?.should == false
33
+ @connection.order_id.should == 0
34
34
  end
35
35
  it 'should set 0 as default' do
36
36
  @connection.order_id.should == 0
@@ -69,14 +69,13 @@ describe :Slug do
69
69
  @slug.id.should == 'string'
70
70
  end
71
71
  it 'should remove exissting slugs with the same id' do
72
- slug = Slug.new document_id: Base.create.id
73
- slug.set_id 'string'
74
- slug.save
72
+ slug = Slug.create _id: 'string', document_id: Base.create.id
73
+
75
74
 
76
75
  @slug.set_id 'string'
77
76
  @slug.save
78
77
 
79
- Slug.count.should == 1
78
+ Slug.all.count.should == 1
80
79
  end
81
80
  it 'should sanetize the slug' do
82
81
  @slug.set_id 'test test'
data/spec/spec_helper.rb CHANGED
@@ -18,10 +18,10 @@ require 'sinatra'
18
18
  set :environment, :test
19
19
 
20
20
  RSpec.configure do |config|
21
- Mongoid.load!("spec/config/mongoid.yml")
21
+ Mongoid.load!("spec/config/mongoid.yml", :test)
22
22
 
23
23
  config.before(:each) do
24
- Mongoid.master.collections.reject { |c| c.name =~ /^system./ }.each(&:drop)
24
+ Mongoid.default_session.collections.select {|c| c.name !~ /system/ }.each(&:drop)
25
25
  end
26
26
  config.include Rack::Test::Methods
27
27
  config.include FactoryGirl::Syntax::Methods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classiccms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-06 00:00:00.000000000 Z
12
+ date: 2012-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - '='
100
100
  - !ruby/object:Gem::Version
101
- version: 2.4.11
101
+ version: 3.0.3
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ dependencies:
106
106
  requirements:
107
107
  - - '='
108
108
  - !ruby/object:Gem::Version
109
- version: 2.4.11
109
+ version: 3.0.3
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: mongo
112
112
  requirement: !ruby/object:Gem::Requirement