Compare commits
43 Commits
master
...
1.0-stable
Author | SHA1 | Date | |
---|---|---|---|
|
3cad1b734e | ||
|
8067c93880 | ||
|
0663aadcf8 | ||
|
86345b281d | ||
|
6066d6b840 | ||
|
69d1732b75 | ||
|
9077390db7 | ||
|
12acf5e9ff | ||
|
724954071a | ||
|
fa42eb4f74 | ||
|
be2a340417 | ||
|
98a6740a7d | ||
|
9f8ddf2b3e | ||
|
907eedd9fe | ||
|
e3e9909268 | ||
|
6d3dd1d91e | ||
|
fd42d1fabc | ||
|
5e8aebbfa5 | ||
|
7223c171e5 | ||
|
487e92214e | ||
|
a8f422ba42 | ||
|
9a25c06969 | ||
|
e1d75ddac3 | ||
|
31669d5253 | ||
|
e42a48dfa6 | ||
|
5a4cc5508c | ||
|
7466f17141 | ||
|
db171eba22 | ||
|
ae18098c6d | ||
|
188cb373e3 | ||
|
b359152757 | ||
|
f407bc7a8f | ||
|
de3d1b0a12 | ||
|
ad3fefe304 | ||
|
881f74bb32 | ||
|
b9664fe84f | ||
|
5139480285 | ||
|
3ba89666a7 | ||
|
a8b00b247b | ||
|
4385eedbbb | ||
|
f1e165d7df | ||
|
d75604d654 | ||
|
635af37be5 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -34,5 +34,5 @@ sites/
|
||||
permanent
|
||||
doc/bushido
|
||||
*.swp
|
||||
|
||||
/spec/dummy
|
||||
|
||||
|
6
Gemfile
6
Gemfile
@ -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'
|
||||
|
||||
|
69
Gemfile.lock
69
Gemfile.lock
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -83,11 +83,19 @@ 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
|
||||
@ -98,13 +106,16 @@ class ContentType
|
||||
conditions_with_names[field._name.to_sym] = value
|
||||
end
|
||||
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)
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
10
features/admin/installation.feature
Normal file
10
features/admin/installation.feature
Normal 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
|
@ -3,17 +3,17 @@ Feature: Login
|
||||
As an administrator
|
||||
I want to log in
|
||||
|
||||
Background:
|
||||
Background:
|
||||
Given I have the site: "test site" set up
|
||||
|
||||
Scenario: Successfully logging in
|
||||
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
|
||||
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 ""
|
||||
@ -21,7 +21,7 @@ Scenario: Attempting to login with an invalid emai or password
|
||||
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
|
||||
Scenario: Attempting to login with an account without a membership
|
||||
Given the following accounts exist:
|
||||
| email | password | password_confirmation |
|
||||
| john@locomotiveapp.org | bluecheese | bluecheese |
|
||||
@ -31,3 +31,9 @@ Scenario: Attempting to login with an account without a membership
|
||||
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
|
||||
|
@ -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
|
||||
|
3
features/step_definitions/installation_steps.rb
Normal file
3
features/step_definitions/installation_steps.rb
Normal 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
|
@ -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:
|
||||
|
@ -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|
|
||||
|
@ -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
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
26
lib/locomotive/liquid/drops/current_user.rb
Normal file
26
lib/locomotive/liquid/drops/current_user.rb
Normal 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
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
BIN
spec/fixtures/themes/default.zip
vendored
BIN
spec/fixtures/themes/default.zip
vendored
Binary file not shown.
BIN
spec/fixtures/themes/default2.zip
vendored
Normal file
BIN
spec/fixtures/themes/default2.zip
vendored
Normal file
Binary file not shown.
@ -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
|
||||
|
@ -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
|
||||
|
63
spec/lib/locomotive/liquid/drops/current_user_spec.rb
Normal file
63
spec/lib/locomotive/liquid/drops/current_user_spec.rb
Normal 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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -90,6 +90,13 @@ describe ContentType do
|
||||
@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')
|
||||
@content_type.content_custom_fields.build :label => 'Active at', :name => 'active_at', :kind => 'Date'
|
||||
|
Loading…
Reference in New Issue
Block a user