Compare commits

...

43 Commits

Author SHA1 Message Date
Mario Visic 3cad1b734e Merge pull request #384 from Ruxton/patch-1
Patch 1
2012-04-26 01:08:17 -07:00
Greg Tangey (Ruxton) 8067c93880 Fixes issue in public/javascripts/admin/tutorial.js - was matching on /admin/content_types/new when you have a model called news. Thanks to @karlbright 2012-04-26 16:06:05 +08:00
Mario Visic 0663aadcf8 Merge remote-tracking branch 'origin/master' 2012-03-24 21:20:24 +08:00
Mario Visic 86345b281d Bump rails to 3.0.12. Fixes #328. 2012-03-24 21:19:54 +08:00
Didier Lafforgue 6066d6b840 Merge pull request #318 from splendeo/Septiembre
Corrected Spanish misspelling: Setiembre -> Septiembre
2012-03-07 17:29:30 -08:00
Enrique García Cota 69d1732b75 Corrected Spanish misspelling: Setiembre -> Septiembre 2012-03-07 10:24:31 +01:00
Mario Visic 9077390db7 Using a File as a highlighted field will now print the filename as the value. Fixes #289. 2012-03-05 21:15:43 +08:00
Mario Visic 12acf5e9ff Merge remote-tracking branch 'origin/master' 2012-03-05 11:13:44 +08:00
Mario Visic 724954071a Merge pull request #315 from andreacampi/GH-294
Fix filters order. Fix #294
2012-03-04 19:13:31 -08:00
Mario Visic fa42eb4f74 Added a failing cucumber scenario for bug #294. Complements patch #315. 2012-03-05 11:11:45 +08:00
Mario Visic be2a340417 Merge pull request #314 from andreacampi/GH-313
Make sure the ETag changes when either the page model or the actual rendered content changes. Fixes #313
2012-03-04 19:03:34 -08:00
Andrea Campi 98a6740a7d Make sure the ETag changes when either the page model or the actual rendered content changes. Fixes #313 2012-03-05 11:02:00 +08:00
Andrea Campi 9f8ddf2b3e Fix filters order. Fix #294 2012-03-03 19:57:36 +01:00
Andrea Campi 907eedd9fe Make sure the ETag changes when either the page model or the actual rendered content changes. Fixes #313 2012-03-03 19:54:52 +01:00
Mario Visic e3e9909268 Merge pull request #295 from cwoodcox/upgrade-heroku
Upgrade Heroku dependency
2012-03-03 07:32:46 -08:00
Mario Visic 6d3dd1d91e After login path now uses stored location. Fixes #305. 2012-03-03 23:25:00 +08:00
Mario Visic fd42d1fabc Merge remote-tracking branch 'origin/master' 2012-03-03 23:20:50 +08:00
Mario Visic 5e8aebbfa5 Failing cucumber scenario for issue #305. 2012-03-03 23:18:08 +08:00
Mario Visic 7223c171e5 Merge pull request #278 from paulsponagl/order_by
with_scope order_by: "fieldname [asc|desc]"
2012-03-03 07:02:12 -08:00
Paul Sponagl 487e92214e with_scope order_by: "fieldname [asc|desc]" 2012-03-03 22:52:35 +08:00
Didier Lafforgue a8f422ba42 merge pull request #300 2012-03-03 15:06:50 +01:00
Didier Lafforgue 9a25c06969 Merge pull request #301 from paulsponagl/export_with_cache_strategy
add cache_strategy to import/export
2012-03-03 05:52:28 -08:00
Didier Lafforgue e1d75ddac3 Merge pull request #302 from giorgian/fix_asset_urls_importing_contents
Fix asset urls importing contents
2012-03-03 05:46:28 -08:00
Didier Lafforgue 31669d5253 Merge pull request #303 from giorgian/export_contents_order
Export contents order
2012-03-03 05:35:01 -08:00
Didier Lafforgue e42a48dfa6 Merge pull request #312 from splendeo/current_user_liquid_extensions
current_user liquid extension
2012-03-03 01:39:33 -08:00
Enrique García Cota 5a4cc5508c Merge remote-tracking branch 'upstream/master' into current_user_liquid_extensions 2012-03-03 00:05:59 +01:00
Enrique García Cota 7466f17141 Merge remote-tracking branch 'upstream/master' into current_user_liquid_extensions 2012-03-03 00:01:14 +01:00
Enrique García Cota db171eba22 use memberships correctly 2012-03-02 23:59:58 +01:00
Enrique García Cota ae18098c6d kinda-sorta working? 2012-03-02 14:02:33 +01:00
Sean Grove 188cb373e3 Comments out S3 storage in assets.yml by default 2012-03-01 19:03:19 -08:00
Enrique García Cota b359152757 semi working 2012-03-01 17:07:09 +01:00
Enrique García Cota f407bc7a8f initial version 2012-02-28 19:29:54 +01:00
Pietro Giorgianni de3d1b0a12 Ensure that fixtured content types always define order_by. 2012-02-16 12:38:27 +01:00
Pietro Giorgianni ad3fefe304 Export contents preserving manual order. 2012-02-16 12:37:52 +01:00
Pietro Giorgianni 881f74bb32 Spec: exporting a manually ordered content type. 2012-02-16 12:37:09 +01:00
Pietro Giorgianni b9664fe84f Rewrite assets URLs in contents text fields. 2012-02-15 17:23:35 +01:00
Pietro Giorgianni 5139480285 Import assets before content_types. 2012-02-15 17:23:18 +01:00
Pietro Giorgianni 3ba89666a7 Move method to parent class so that it's available to siblings. 2012-02-15 17:22:14 +01:00
Pietro Giorgianni a8b00b247b Spec: assets URLs in contents text fields should be correctly mapped. 2012-02-15 17:20:00 +01:00
Paul Sponagl 4385eedbbb add cache_strategy to import/export 2012-02-13 16:45:23 +01:00
Paul Sponagl f1e165d7df with_scope order_by: "fieldname [asc|desc]" 2012-02-13 15:19:42 +01:00
Didier Lafforgue d75604d654 stick to cells 3.8.0 2012-02-09 12:48:35 +01:00
Corey Woodcox 635af37be5 upgrade heroku gem to 2.19.1 to allow use with cedar stack for rails 3 2012-01-30 15:25:41 -07:00
33 changed files with 367 additions and 113 deletions

2
.gitignore vendored
View File

@ -34,5 +34,5 @@ sites/
permanent
doc/bushido
*.swp
/spec/dummy

View File

@ -4,7 +4,7 @@ source :rubygems
gem 'rake', '0.9.2'
gem 'rails', '3.0.10'
gem 'rails', '3.0.12'
gem 'warden'
gem 'devise', '~>1.5.0'
@ -33,14 +33,14 @@ gem 'cancan'
gem 'fog', '0.8.2'
gem 'mimetype-fu'
gem 'actionmailer-with-request', :require => 'actionmailer_with_request'
gem 'heroku', '1.19.1'
gem 'heroku', '2.19.1'
gem 'httparty', '0.7.8'
gem 'RedCloth', '4.2.9'
gem 'delayed_job_mongoid', '1.0.8'
gem 'rubyzip'
gem 'locomotive_jammit-s3', :require => 'jammit-s3'
gem 'SystemTimer', :platforms => :ruby_18
gem 'cells'
gem 'cells', '3.8.0'
gem 'sanitize'
gem 'highline'

View File

@ -9,34 +9,34 @@ GEM
SystemTimer (1.2.3)
ZenTest (4.6.2)
abstract (1.0.0)
actionmailer (3.0.10)
actionpack (= 3.0.10)
actionmailer (3.0.12)
actionpack (= 3.0.12)
mail (~> 2.2.19)
actionmailer-with-request (0.3.0)
rails (>= 3)
actionpack (3.0.10)
activemodel (= 3.0.10)
activesupport (= 3.0.10)
actionpack (3.0.12)
activemodel (= 3.0.12)
activesupport (= 3.0.12)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.5.0)
rack (~> 1.2.1)
rack (~> 1.2.5)
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.10)
activesupport (= 3.0.10)
activemodel (3.0.12)
activesupport (= 3.0.12)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.10)
activemodel (= 3.0.10)
activesupport (= 3.0.10)
activerecord (3.0.12)
activemodel (= 3.0.12)
activesupport (= 3.0.12)
arel (~> 2.0.10)
tzinfo (~> 0.3.23)
activeresource (3.0.10)
activemodel (= 3.0.10)
activesupport (= 3.0.10)
activesupport (3.0.10)
activeresource (3.0.12)
activemodel (= 3.0.12)
activesupport (= 3.0.12)
activesupport (3.0.12)
archive-tar-minitar (0.5.2)
arel (2.0.10)
autotest (4.4.6)
@ -128,10 +128,11 @@ GEM
growl-glue (1.0.7)
haml (3.1.2)
has_scope (0.5.1)
heroku (1.19.1)
activesupport (>= 2.1.0)
launchy (~> 0.3.2)
rest-client (>= 1.4.0, < 1.7.0)
heroku (2.19.1)
launchy (>= 0.3.2)
rest-client (~> 1.6.1)
rubyzip
term-ansicolor (~> 1.0.5)
highline (1.6.9)
httparty (0.7.8)
crack (= 0.1.8)
@ -165,7 +166,7 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
mime-types (1.18)
mimemagic (0.1.8)
mimetype-fu (0.1.2)
mocha (0.9.12)
@ -192,17 +193,17 @@ GEM
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.10)
actionmailer (= 3.0.10)
actionpack (= 3.0.10)
activerecord (= 3.0.10)
activeresource (= 3.0.10)
activesupport (= 3.0.10)
rails (3.0.12)
actionmailer (= 3.0.12)
actionpack (= 3.0.12)
activerecord (= 3.0.12)
activeresource (= 3.0.12)
activesupport (= 3.0.12)
bundler (~> 1.0)
railties (= 3.0.10)
railties (3.0.10)
actionpack (= 3.0.10)
activesupport (= 3.0.10)
railties (= 3.0.12)
railties (3.0.12)
actionpack (= 3.0.12)
activesupport (= 3.0.12)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.4)
@ -266,7 +267,7 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.31)
tzinfo (0.3.32)
unicorn (4.1.1)
kgio (~> 2.4)
rack
@ -294,7 +295,7 @@ DEPENDENCIES
cancan
capybara
carrierwave (= 0.5.6)
cells
cells (= 3.8.0)
cucumber-rails (= 1.2.0)
custom_fields (= 1.0.0.beta.25)
database_cleaner
@ -307,7 +308,7 @@ DEPENDENCIES
formtastic (~> 1.2.3)
growl-glue
haml (= 3.1.2)
heroku (= 1.19.1)
heroku (= 2.19.1)
highline
httparty (= 0.7.8)
inherited_resources (~> 1.1.2)
@ -323,7 +324,7 @@ DEPENDENCIES
mongoid (~> 2.0.2)
pickle
rack-cache
rails (= 3.0.10)
rails (= 3.0.12)
rake (= 0.9.2)
rmagick (= 2.12.2)
rspec-cells

View File

@ -11,10 +11,10 @@ module Admin
skip_before_filter :validate_site_membership
before_filter :is_step_already_done?
before_filter :allow_installation?
before_filter :is_step_already_done?
skip_load_and_authorize_resource
def show

View File

@ -12,7 +12,7 @@ module Admin
protected
def after_sign_in_path_for(resource)
admin_pages_url
stored_location_for(resource) || admin_pages_url
end
def after_sign_out_path_for(resource)

View File

@ -41,7 +41,7 @@ class ContentInstance
end
def highlighted_field_value
self.send(self.content_type.highlighted_field_name)
self.send(self.content_type.highlighted_field_name).to_s
end
alias :_label :highlighted_field_value

View File

@ -83,28 +83,39 @@ class ContentType
list = (if conditions.nil? || conditions.empty?
self.contents
else
# check for order_by: "field [asc|desc]" condition
if order_by = ( conditions.delete('order_by') || conditions.delete(:order_by) )
column, sort_order = order_by.split
column = column.to_sym
else
sort_order = nil
end
conditions_with_names = {}
conditions.each do |key, value|
# convert alias (key) to name
field = self.content_custom_fields.detect { |f| f._alias == key }
if field = self.content_custom_fields.detect { |f| f._alias == key }
case field.kind.to_sym
when :category
if (category_item = field.category_items.where(:name => value).first).present?
conditions_with_names[field._name.to_sym] = category_item._id
case field.kind.to_sym
when :category
if (category_item = field.category_items.where(:name => value).first).present?
conditions_with_names[field._name.to_sym] = category_item._id
end
else
conditions_with_names[field._name.to_sym] = value
end
else
conditions_with_names[field._name.to_sym] = value
end
end
self.contents.where(conditions_with_names)
conditions_with_names.blank? ? self.contents : self.contents.where(conditions_with_names)
end).sort { |a, b| (a.send(column) && b.send(column)) ? (a.send(column) || 0) <=> (b.send(column) || 0) : 0 }
return list if self.order_manually?
self.asc_order? ? list : list.reverse
if sort_order.nil?
(self.order_manually? || self.asc_order?) ? list : list.reverse
else
sort_order == 'asc' ? list : list.reverse
end
end
def sort_contents!(ids)

View File

@ -108,4 +108,4 @@ module Extensions
end
end
end
end

View File

@ -2,9 +2,10 @@ embed_assets: off
# compress_assets: off
# package_assets: off
s3_bucket: <%= ENV['S3_BUCKET'] %>
s3_access_key_id: <%= ENV['S3_KEY_ID'] %>
s3_secret_access_key: <%= ENV['S3_SECRET_KEY'] %>
# If you're using S3 for asset storage, uncomment the following lines
# s3_bucket: <%= ENV['S3_BUCKET'] %>
# s3_access_key_id: <%= ENV['S3_KEY_ID'] %>
# s3_secret_access_key: <%= ENV['S3_SECRET_KEY'] %>
javascripts:
box:

View File

@ -117,8 +117,8 @@ es:
day_names: [Domingo, Lunes, Martes, Miércoles, Jueves, Viernes, Sábado]
abbr_day_names: [Dom, Lun, Mar, Mie, Jue, Vie, Sab]
month_names: [~, Enero, Febrero, Marzo, Abril, Mayo, Junio, Julio, Agosto, Setiembre, Octubre, Noviembre, Diciembre]
abbr_month_names: [~, Ene, Feb, Mar, Abr, May, Jun, Jul, Ago, Set, Oct, Nov, Dic]
month_names: [~, Enero, Febrero, Marzo, Abril, Mayo, Junio, Julio, Agosto, Septiembre, Octubre, Noviembre, Diciembre]
abbr_month_names: [~, Ene, Feb, Mar, Abr, May, Jun, Jul, Ago, Sep, Oct, Nov, Dic]
order: [ year, month, day ]
time:
@ -216,4 +216,4 @@ es:
skip_last_comma: true
words_connector: ", "
two_words_connector: " y "
last_word_connector: " y "
last_word_connector: " y "

View File

@ -0,0 +1,10 @@
Feature: Installation
As A User
In order to get setup with locomotive quickly
I want to be able to create an admin account and my first site
Scenario: Viewing the installation deatils after creating a site (Bug)
Given I have a site set up
When I am on the installation page
Then I should not be able to see any admin user details

View File

@ -3,31 +3,37 @@ Feature: Login
As an administrator
I want to log in
Background:
Given I have the site: "test site" set up
Background:
Given I have the site: "test site" set up
Scenario: Successfully logging in
When I go to login
And I fill in "Email" with "admin@locomotiveapp.org"
And I fill in "Password" with "easyone"
And I press "Log in"
Then I should see "Listing pages"
Scenario: Successfully logging in
When I go to login
And I fill in "Email" with "admin@locomotiveapp.org"
And I fill in "Password" with "easyone"
And I press "Log in"
Then I should see "Listing pages"
Scenario: Attempting to login with an invalid emai or password
When I go to login
And I fill in "Email" with "admin@locomotiveapp.org"
And I fill in "Password" with ""
And I press "Log in"
Then I should not see "Listing pages"
And I should see "Invalid email or password"
Scenario: Attempting to login with an invalid emai or password
When I go to login
And I fill in "Email" with "admin@locomotiveapp.org"
And I fill in "Password" with ""
And I press "Log in"
Then I should not see "Listing pages"
And I should see "Invalid email or password"
Scenario: Attempting to login with an account without a membership
Given the following accounts exist:
| email | password | password_confirmation |
| john@locomotiveapp.org | bluecheese | bluecheese |
When I go to login
And I fill in "Email" with "john@locomotiveapp.org"
And I fill in "Password" with "bluecheese"
And I press "Log in"
Then I should not see "Listing pages"
And I should see "not a member of this site"
Scenario: Attempting to login with an account without a membership
Given the following accounts exist:
| email | password | password_confirmation |
| john@locomotiveapp.org | bluecheese | bluecheese |
When I go to login
And I fill in "Email" with "john@locomotiveapp.org"
And I fill in "Password" with "bluecheese"
And I press "Log in"
Then I should not see "Listing pages"
And I should see "not a member of this site"
Scenario: Being redirected to the previous admin page after login
Given I have an admin account
And I attempt to access an admin page when not logged in
When I login with my admin account
Then I should be redirected the the admin page I was attempting to access

View File

@ -28,6 +28,27 @@ Then /^I am redirected to "([^\"]*)"$/ do |url|
visit location
end
Given /^I have an admin account$/ do
@member = Site.first.memberships.where(:role => 'admin').first || FactoryGirl.create(:admin, :site => Site.first, :password => 'easyone')
@email = @member.account.email
@password = 'easyone'
end
Given /^I attempt to access an admin page when not logged in$/ do
@admin_path = edit_admin_current_site_path
visit @admin_path
end
When /^I login with my admin account$/ do
fill_in 'Email', :with => @email
fill_in 'Password', :with => @password
click_button 'Log in'
end
Then /^I should be redirected the the admin page I was attempting to access$/ do
current_path.should == edit_admin_current_site_path
end
### Cross-domain authentication
When /^I forget to press the button on the cross-domain notice page$/ do

View File

@ -0,0 +1,3 @@
Then /^I should not be able to see any admin user details$/ do
page.should_not have_content @admin.email
end

View File

@ -40,6 +40,8 @@ module NavigationHelpers
when /the "(.*)" model edition page/
content_type = Site.first.content_types.where(:name => $1).first
edit_admin_content_type_path(content_type)
when /the installation page/
admin_installation_path
# Add more mappings here.
# Here is an example that pulls values out of the Regexp:

View File

@ -173,7 +173,7 @@ module Locomotive
protected
def _copy_pages(page)
attributes = self.extract_attributes(page, %w{title seo_title meta_description meta_keywords redirect_url content_type published})
attributes = self.extract_attributes(page, %w{title seo_title meta_description meta_keywords redirect_url content_type published cache_strategy})
attributes['listed'] = page.listed? # in some cases, page.listed can be nil
@ -277,7 +277,7 @@ module Locomotive
highlighted_field_name = content_type.highlighted_field_name
content_type.contents.each do |content|
content_type.ordered_contents.each do |content|
hash = {}
content.custom_fields.each do |field|
@ -340,4 +340,4 @@ module Locomotive
end
end
end

View File

@ -41,6 +41,20 @@ module Locomotive
def open_sample_asset(url)
File.open(File.join(self.theme_path, 'public', url))
end
def replace_images!(template)
return if template.blank?
template.gsub!(/\/samples\/([^'"]+?\.[a-zA-Z0-9]{3})/) do |match|
name = File.basename($1)
if asset = site.assets.where(:source_filename => name).first
asset.source.url
else
match
end
end
end
end
end
end

View File

@ -161,7 +161,9 @@ module Locomotive
field.category_items.build :name => value
end
value
else # string, text
when 'text'
replace_images!(value)
else # string
value
end)

View File

@ -42,7 +42,7 @@ module Locomotive
self.reset! if @options[:reset]
%w(site content_types assets snippets pages).each do |step|
%w(site assets content_types snippets pages).each do |step|
if @options[:enabled][step] != false
"Locomotive::Import::#{step.camelize}".constantize.process(context, @options)
@worker.update_attributes :step => step if @worker

View File

@ -113,6 +113,7 @@ module Locomotive
end
end
else
self.replace_images!(attributes['content'])
element.content = attributes['content']
end
end
@ -147,20 +148,6 @@ module Locomotive
parent || self.add_page(parent_fullpath)
end
def replace_images!(template)
return if template.blank?
template.gsub!(/\/samples\/(.*\.[a-zA-Z0-9]{3})/) do |match|
name = File.basename($1)
if asset = site.assets.where(:source_filename => name).first
asset.source.url
else
match
end
end
end
def pages
@pages ||= self.retrieve_pages
end

View File

@ -0,0 +1,26 @@
module Locomotive
module Liquid
module Drops
class CurrentUser < Base
include ::Rails.application.routes.url_helpers
def logged_in?
_source.present?
end
def name
_source.name if logged_in?
end
def email
_source.email if logged_in?
end
def logout_path
destroy_admin_session_path
end
def login_path
new_admin_session_path
end
end
end
end
end

View File

@ -68,7 +68,8 @@ module Locomotive
'path' => request.path,
'url' => request.url,
'now' => Time.now.utc,
'today' => Date.today
'today' => Date.today,
'current_user' => Locomotive::Liquid::Drops::CurrentUser.new(current_admin)
}
assigns.merge!(Locomotive.config.context_assign_extensions)
@ -97,7 +98,7 @@ module Locomotive
response.headers['Content-Type'] = 'text/html; charset=utf-8'
if @page.with_cache?
fresh_when :etag => @page, :last_modified => @page.updated_at.utc, :public => true
fresh_when :etag => [@page, output], :last_modified => @page.updated_at.utc, :public => true
if @page.cache_strategy != 'simple' # varnish
response.cache_control[:max_age] = @page.cache_strategy
@ -122,4 +123,4 @@ module Locomotive
end
end
end
end

View File

@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = '>= 1.3.6'
s.rubyforge_project = 'nowarning'
s.add_dependency 'rails', '~> 3.0.10'
s.add_dependency 'rails', '~> 3.0.12'
s.add_dependency 'warden'
s.add_dependency 'devise', '~>1.5.0'
s.add_dependency 'devise_bushido_authenticatable', '1.0.0.alpha10'
@ -35,13 +35,13 @@ Gem::Specification.new do |s|
s.add_dependency 'locomotive_liquid', '2.2.2'
s.add_dependency 'formtastic', '~> 1.2.3'
s.add_dependency 'inherited_resources', '~> 1.1.2'
s.add_dependency 'cells'
s.add_dependency 'cells', '3.8.0'
s.add_dependency 'highline'
s.add_dependency 'sanitize'
s.add_dependency 'json_pure', '1.5.1'
s.add_dependency 'bushido'
s.add_dependency 'heroku', '1.19.1'
s.add_dependency 'heroku', '2.19.1'
s.add_dependency 'rmagick', '2.12.2'
s.add_dependency 'carrierwave', '0.5.6'

View File

@ -357,8 +357,8 @@ $(document).ready(function(){
* New model
*
*/
if(window.location.pathname.match('admin/content_types/new') != null ||
window.location.pathname.match('admin/content_types/.+/edit')){
if(window.location.pathname.match(/admin\/content_types\/new[\/]?$/) != null ||
window.location.pathname.match(/admin\/content_types\/.+\/edit[\/]?$/)){
guiders.createGuider({
attachTo: "undefined",

View File

@ -136,6 +136,7 @@ FactoryGirl.define do
factory :content_type do
name 'My project'
site { Site.where(:subdomain => "acme").first || Factory(:site) }
order_by 'created_at'
end
factory :content_instance do

Binary file not shown.

BIN
spec/fixtures/themes/default2.zip vendored Normal file

Binary file not shown.

View File

@ -60,6 +60,27 @@ describe Locomotive::Export do
end
context 'manually ordered content_types' do
before(:each) do
site = FactoryGirl.build('another site')
Site.stubs(:find).returns(site)
@wish_type = build_wish_type(site)
@wish_type.contents.build(:what => 'nothing', :_position_in_list => 2)
@wish_type.contents.build(:what => 'everything', :_position_in_list => 1)
@wish_data = ::Locomotive::Export.new(site).send(:extract_contents, @wish_type)
end
it 'should have the right order' do
@wish_data.should == [{'everything' => {}}, {'nothing' => {}}]
end
end
def build_wish_type(site)
site.content_types.build(:slug => 'wishes', :name => 'Wishes', :site => site, :order_by => '_position_in_list', :order_direction => 'asc', :highlighted_field_name => 'custom_field_1').tap do |content_type|
content_type.content_custom_fields.build :label => 'What', :_alias => 'what', :kind => 'string'
end
end
context '#zipfile' do
before(:all) do

View File

@ -73,7 +73,7 @@ describe Locomotive::Import::Job do
it 'sets the editable text for a page from the site config file' do
page = @site.pages.where(:title => 'Contact').first
page.find_editable_element('content', 'address').content.should == '<p>Our office address: 215 Vine Street, Scranton, PA 18503</p>'
page.find_editable_element('content', 'address').content.should match('<p>Our office address: 215 Vine Street, Scranton, PA 18503<br /><img src="/sites/[^/]+/assets/[^/]+/office.jpg" alt="office.jpg" /></p>')
end
it 'sets the editable file for a page from the site config file' do
@ -137,4 +137,20 @@ describe Locomotive::Import::Job do
end
end
context 'with a content referencing an asset' do
before(:all) do
@site = FactoryGirl.create(:site)
job = Locomotive::Import::Job.new(FixturedTheme.duplicate_and_open('default2.zip'), @site, { :samples => true, :reset => true })
job.perform
job.success nil
end
it 'will fix the url inside content' do
content = @site.content_types.where(:slug => 'messages').first.contents.first
asset = @site.assets.first
content.message.should == "<img src=\"/sites/#{@site.id}/assets/#{asset.id}/#{asset.source_filename}\" />"
end
end
end

View File

@ -0,0 +1,63 @@
require 'spec_helper'
describe Locomotive::Liquid::Drops::CurrentUser do
before(:each) do
@page = FactoryGirl.build(:sub_page)
@site = @page.site
@site.pages.expects(:any_in).returns([@page])
@controller = Locomotive::TestController.new
@controller.stubs(:flash).returns(ActionDispatch::Flash::FlashHash.new())
@controller.stubs(:params).returns(:url => '/subpage')
@controller.stubs(:request).returns(OpenStruct.new(:url => '/subpage', :fullpath => '/subpage'))
@controller.current_site = @site
@admin = FactoryGirl.build(:admin).account
end
def expect_render(template, text)
@page.raw_template = template
@page.send(:serialize_template)
@controller.expects(:render).with(:text => text, :layout => false, :status => :ok).returns(true)
@controller.send(:render_locomotive_page)
end
context '#logged_in?' do
it 'returns false when no user is logged in' do
expect_render('{{ current_user.logged_in? }}', 'false')
end
it 'returns true when there is a user logged in' do
@controller.expects(:current_admin).twice.returns(true)
expect_render('{{ current_user.logged_in? }}', 'true')
end
end
context '#name' do
it 'returns nothing when no user is logged in' do
expect_render('{{ current_user.name }}', '')
end
it 'returns the username when the user is logged in' do
@controller.expects(:current_admin).twice.returns(@admin)
expect_render('{{ current_user.name }}', 'Admin')
end
end
context '#email' do
it 'returns nothing when no user is logged in' do
expect_render('{{ current_user.email }}', '')
end
it 'returns the username when the user is logged in' do
@controller.expects(:current_admin).twice.returns(@admin)
expect_render('{{ current_user.email }}', 'admin@locomotiveapp.org')
end
end
context '#logout_path' do
it 'returns the logout url' do
expect_render('{{ current_user.logout_path }}', '/admin/sign_out')
end
end
end

View File

@ -71,6 +71,50 @@ describe 'Locomotive rendering system' do
@controller.status.should == :not_found
end
context 'templatized page' do
before(:each) do
@content_type = FactoryGirl.build(:content_type, :site => nil)
@content = @content_type.contents.build(:_visible => true, :tile => 'one')
@page.templatized = true
@page.content_type = @content_type
end
it 'sets the etag' do
@page.cache_strategy = 'simple'
@page.stubs(:updated_at).returns(Time.now)
@controller.send(:prepare_and_set_response, 'Hello world !')
@controller.response.to_a # force to build headers
@controller.response.headers['ETag'].should == "\"d232eefab45e58af59c2d00409261365\""
end
it 'changes the etag if the page changes' do
@page.cache_strategy = 'simple'
@page.stubs(:updated_at).returns(Time.now)
@page.stubs(:to_param).returns("1")
@controller.send(:prepare_and_set_response, 'Hello world !')
@controller.response.to_a # force to build headers
old_etag = @controller.response.headers['ETag']
@page.stubs(:to_param).returns("2")
@controller.send(:prepare_and_set_response, 'Hello world !')
@controller.response.to_a # force to build headers
@controller.response.headers['ETag'].should_not == old_etag
end
it 'changes the etag if the output changes' do
@page.cache_strategy = 'simple'
@page.stubs(:updated_at).returns(Time.now)
@controller.send(:prepare_and_set_response, 'Hello world !')
@controller.response.to_a # force to build headers
old_etag = @controller.response.headers['ETag']
@controller.send(:prepare_and_set_response, 'Hello world !!')
@controller.response.to_a # force to build headers
@controller.response.headers['ETag'].should_not == old_etag
end
end
end
context 'when retrieving page' do

View File

@ -10,6 +10,7 @@ describe ContentInstance do
@content_type.content_custom_fields.build :label => 'Title', :kind => 'String'
@content_type.content_custom_fields.build :label => 'Description', :kind => 'Text'
@content_type.content_custom_fields.build :label => 'Visible ?', :kind => 'Text', :_alias => 'visible'
@content_type.content_custom_fields.build :label => 'Photo', :kind => 'File'
@content_type.highlighted_field_name = 'custom_field_1'
end
@ -211,4 +212,20 @@ describe ContentInstance do
def fake_bson_id(id)
BSON::ObjectId(id.to_s.rjust(24, '0'))
end
describe '#highlighted_field_value' do
it 'returns the value of the highlighted field' do
content = build_content(:title => 'Cheese')
content.highlighted_field_value.should == 'Cheese'
end
it 'returns the filename of a file type highlighted field' do
@content_type.highlighted_field_name = 'custom_field_4'
content = build_content(:photo => File.open(Rails.root.join('spec', 'fixtures', 'assets', '5k.png')))
content.highlighted_field_value.should be_a String
content.highlighted_field_value.should include '5k.png'
end
end
end

View File

@ -89,6 +89,13 @@ describe ContentType do
@content_type.order_direction = 'desc'
@content_type.ordered_contents.collect(&:name).should == %w(Sacha Did)
end
it 'returns a list of contents ordered through condition {order_by: "name asc"}' do
@content_type.order_by = 'name'
@content_type.order_direction = 'desc'
@content_type.ordered_contents(:order_by => 'name asc').collect(&:name).should == %w(Did Sacha)
end
it 'returns a list of contents ordered by a Date column when first instance is missing the value' do
@content_type = FactoryGirl.build(:content_type, :order_by => 'created_at')