This commit is contained in:
did 2011-05-24 12:23:05 -07:00
parent 8f36f5a2d8
commit 8ad6ee580e
9 changed files with 49 additions and 21 deletions

View File

@ -2,6 +2,8 @@ source :rubygems
# add in all the runtime dependencies
gem 'rake', '0.8.7'
gem 'rails', '>= 3.0.7'
gem 'warden'
@ -20,7 +22,7 @@ gem 'inherited_resources', '~> 1.1.2'
gem 'rmagick', '2.12.2'
gem 'locomotive_carrierwave', '0.5.0.1.beta3', :require => 'carrierwave'
gem 'custom_fields', '1.0.0.beta.12'
gem 'custom_fields', '1.0.0.beta.13'
gem 'fog', '0.3.7'
gem 'mimetype-fu'
gem 'actionmailer-with-request', :require => 'actionmailer_with_request'

View File

@ -1,6 +1,6 @@
GIT
remote: git://github.com/floehopper/mocha.git
revision: 7dd9512a874f89b8037d7320fe7988c222f439e1
revision: adeb8ae0189963cf3024f2b37d5348a7feaae11e
specs:
mocha (0.9.12.20110213002255)
@ -87,7 +87,7 @@ GEM
cucumber-rails (0.3.2)
cucumber (>= 0.8.0)
culerity (0.2.15)
custom_fields (1.0.0.beta.12)
custom_fields (1.0.0.beta.13)
activesupport (>= 3.0.7)
locomotive_carrierwave
mongoid (~> 2.0.1)
@ -110,7 +110,7 @@ GEM
factory_girl_rails (1.0.1)
factory_girl (~> 1.3)
railties (>= 3.0.0)
ffi (1.0.8)
ffi (1.0.9)
fog (0.3.7)
builder
excon (>= 0.2.3)
@ -120,7 +120,7 @@ GEM
net-ssh (~> 2.0.23)
nokogiri (~> 1.4.3.1)
ruby-hmac
formatador (0.1.3)
formatador (0.1.4)
formtastic (1.2.3)
actionpack (>= 2.3.7)
activesupport (>= 2.3.7)
@ -146,7 +146,7 @@ GEM
yui-compressor (>= 0.9.1)
json (1.5.1)
json_pure (1.4.6)
kgio (2.4.0)
kgio (2.4.1)
launchy (0.3.7)
configuration (>= 0.0.5)
rake (>= 0.8.1)
@ -172,11 +172,10 @@ GEM
mimetype-fu (0.1.2)
mongo (1.3.1)
bson (>= 1.3.1)
mongoid (2.0.1)
mongoid (2.0.2)
activemodel (~> 3.0)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
will_paginate (~> 3.0.pre)
net-ssh (2.0.24)
nokogiri (1.4.3.1)
open4 (1.0.1)
@ -185,7 +184,7 @@ GEM
rake
polyglot (0.3.1)
proxies (0.2.1)
rack (1.2.2)
rack (1.2.3)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
@ -257,7 +256,7 @@ GEM
rack
warden (0.10.7)
rack (>= 1.0.0)
will_paginate (3.0.pre2)
will_paginate (2.3.15)
yui-compressor (0.9.6)
POpen4 (>= 0.1.4)
@ -275,7 +274,7 @@ DEPENDENCIES
capybara
cucumber (= 0.8.5)
cucumber-rails
custom_fields (= 1.0.0.beta.12)
custom_fields (= 1.0.0.beta.13)
database_cleaner
delayed_job (= 2.1.4)
delayed_job_mongoid (= 1.0.2)
@ -298,6 +297,7 @@ DEPENDENCIES
mongoid (~> 2.0.1)
pickle
rails (>= 3.0.7)
rake (= 0.8.7)
rmagick (= 2.12.2)
rspec-rails (= 2.3.1)
ruby-debug

View File

@ -25,7 +25,6 @@ class ContentInstance
after_create :send_notifications
## named scopes ##
scope :persisted, where(:updated_at.ne => nil)
scope :latest_updated, :order_by => :updated_at.desc, :limit => Locomotive.config.lastest_items_nb
## methods ##

View File

@ -70,6 +70,10 @@ class ContentType
end
end
def latest_updated_contents
self.contents.latest_updated.reject { |c| !c.persisted? }
end
def ordered_contents(conditions = {})
column = self.order_by.to_sym

View File

@ -15,7 +15,7 @@
.inner
%h2!= t('admin.contents.index.lastest_items')
%ul
- content_type.contents.persisted.latest_updated.each do |content|
- content_type.latest_updated_contents.each do |content|
%li
= link_to truncate(content.send(content_type.highlighted_field_name).to_s, :length => 20), edit_admin_content_path(content_type.slug, content)
%span= time_ago_in_words(content.updated_at)

View File

@ -0,0 +1,10 @@
Feature: Manage Contents
In order to manage instances from custom content types
As an administrator
I want to add/edit/delete custom contents of my site
Background:
Given I have the site: "test site" set up
And I am an authenticated user

View File

@ -1,3 +1,8 @@
# Custom options for CustomFields
CustomFields.options = {
:reserved_aliases => Mongoid.destructive_fields + %w(created_at updated_at)
}
# Set correct paths
module CustomFields
module Types
@ -17,4 +22,3 @@ module CustomFields
end
end

View File

@ -37,7 +37,7 @@ Gem::Specification.new do |s|
s.add_dependency "rmagick", "2.12.2"
s.add_dependency "locomotive_carrierwave", "0.5.0.1.beta3"
s.add_dependency "custom_fields", "1.0.0.beta.12"
s.add_dependency "custom_fields", "1.0.0.beta.13"
s.add_dependency "fog", "0.3.7"
s.add_dependency "mimetype-fu"
s.add_dependency "actionmailer-with-request"

View File

@ -17,20 +17,20 @@ describe ContentType do
# Validations ##
%w{site name}.each do |field|
it "should validate presence of #{field}" do
it "requires the presence of #{field}" do
content_type = Factory.build(:content_type, field.to_sym => nil)
content_type.should_not be_valid
content_type.errors[field.to_sym].should == ["can't be blank"]
end
end
it 'should validate presence of slug' do
it 'requires the presence of slug' do
content_type = Factory.build(:content_type, :name => nil, :slug => nil)
content_type.should_not be_valid
content_type.errors[:slug].should == ["can't be blank"]
end
it 'should validate uniqueness of slug' do
it 'is not valid if slug is not unique' do
content_type = Factory.build(:content_type)
content_type.content_custom_fields.build :label => 'anything', :kind => 'String'
content_type.save
@ -38,12 +38,21 @@ describe ContentType do
content_type.errors[:slug].should == ["is already taken"]
end
it 'should validate size of content custom fields' do
it 'is not valid if there is not at least one field' do
content_type = Factory.build(:content_type)
content_type.should_not be_valid
content_type.errors[:content_custom_fields].should == ["is too small (minimum element number is 1)"]
end
%w(created_at updated_at).each do |_alias|
it "does not allow #{_alias} as alias" do
content_type = Factory.build(:content_type)
field = content_type.content_custom_fields.build :label => 'anything', :kind => 'String', :_alias => _alias
field.valid?.should be_false
field.errors[:_alias].should == ['is reserved']
end
end
end
context '#ordered_contents' do