change load behaviour in a better engine way and add more tests

This commit is contained in:
2012-12-14 18:19:04 +01:00
parent 0d6aeea49a
commit 90fd490909
13 changed files with 146 additions and 61 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
rvm:
- 1.9.2
- 1.9.3
services:
- couchdb
before_script:
+13 -15
View File
@@ -9,7 +9,7 @@ GIT
GIT
remote: git://github.com/bterkuile/simply_stored.git
revision: 04f58b15bb308420f78c66d27ce4d4d3b58183ff
revision: fe749c792e303817f825fa4964936cc68a62b14b
specs:
simply_stored (1.0.0)
activesupport
@@ -65,8 +65,10 @@ GEM
addressable (2.3.2)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bourbon (2.1.2)
sass (>= 3.2)
bootstrap-sass (2.2.1.1)
sass (~> 3.2)
bourbon (3.0.1)
sass (>= 3.2.0)
thor
builder (3.0.4)
capybara (2.0.1)
@@ -128,7 +130,6 @@ GEM
less-rails (2.2.6)
actionpack (>= 3.1)
less (~> 2.2.0)
libv8 (3.3.10.4)
libwebsocket (0.1.7.1)
addressable
websocket
@@ -138,7 +139,7 @@ GEM
treetop (~> 1.4.8)
method_source (0.8.1)
mime-types (1.19)
multi_json (1.4.0)
multi_json (1.5.0)
nokogiri (1.5.5)
orm_adapter (0.0.7)
paperclip (3.3.1)
@@ -174,12 +175,13 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.0.2)
rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
ref (1.0.2)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec-core (2.12.1)
rspec-core (2.12.2)
rspec-expectations (2.12.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.0)
@@ -196,7 +198,7 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
selenium-webdriver (2.26.0)
selenium-webdriver (2.27.2)
childprocess (>= 0.2.5)
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
@@ -219,8 +221,8 @@ GEM
capybara (>= 1.0.0)
rspec-rails (>= 2.5.0)
temple (0.5.5)
therubyracer (0.10.2)
libv8 (~> 3.3.10)
therubyracer (0.11.0)
ref
thin (1.5.0)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
@@ -232,10 +234,6 @@ GEM
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
twitter-bootstrap-rails (2.1.7)
actionpack (>= 3.1)
execjs
railties (>= 3.1)
tzinfo (0.3.35)
warden (1.1.1)
rack (>= 1.0)
@@ -247,6 +245,7 @@ PLATFORMS
ruby
DEPENDENCIES
bootstrap-sass
bourbon
cmtool!
coffee-script
@@ -267,4 +266,3 @@ DEPENDENCIES
therubyracer
thin
tinymce-rails
twitter-bootstrap-rails
+1 -1
View File
@@ -31,7 +31,7 @@
= f.text_area :sidebar, :rows => 15, :cols => 80, :class => 'editor_full'
.field
= f.label :parent_id
= f.select :parent_id, tree_options_for_select(Page.full_tree(@page.locale), exclude: @page.id, selected: @page.parent_id), include_blank: ' -- '
= f.select :parent_id, tree_options_for_select(Page.full_tree(@page.locale || Page.locales.first), exclude: @page.id, selected: @page.parent_id), include_blank: ' -- '
.field
= f.label :position
= f.select :position, (0..20).to_a
-27
View File
@@ -1,27 +0,0 @@
Cmtool::Menu.register do
group label: :site do
title t('cmtool.menu.site.title')
resource_link Page, scope: Cmtool
resource_link Cmtool::Keyword
end
group label: :publications do
title t('cmtool.menu.publications.title')
resource_link Cmtool::News
resource_link Cmtool::Faq
resource_link Cmtool::Quote
end
group label: :forms do
title t('cmtool.menu.forms.title')
resource_link Cmtool::ContactForm
resource_link Cmtool::NewsletterSubscription
end
group label: :files do
title t('cmtool.menu.files.title')
resource_link Cmtool::Image
resource_link Cmtool::Directory
end
resource_link User, label: :users, scope: Cmtool
end
Cmtool::Menu.register do
end
+26 -1
View File
@@ -14,7 +14,32 @@ require 'bourbon'
module Cmtool
class Engine < ::Rails::Engine
isolate_namespace Cmtool
initializer "cmtool" do
initializer "cmtool.build_menu" do
Cmtool::Menu.register do
group label: :site do
title t('cmtool.menu.site.title')
resource_link Page, scope: Cmtool
resource_link Cmtool::Keyword
end
group label: :publications do
title t('cmtool.menu.publications.title')
resource_link Cmtool::News
resource_link Cmtool::Faq
resource_link Cmtool::Quote
end
group label: :forms do
title t('cmtool.menu.forms.title')
resource_link Cmtool::ContactForm
resource_link Cmtool::NewsletterSubscription
end
group label: :files do
title t('cmtool.menu.files.title')
resource_link Cmtool::Image
resource_link Cmtool::Directory
end
resource_link User, label: :users, scope: Cmtool
end
end
ActiveSupport.on_load(:action_view) do
require File.expand_path('../../../app/helpers/cmtool/application_helper', __FILE__)
+7
View File
@@ -22,6 +22,7 @@ module Cmtool
klass.validates :name, presence: true
klass.validates :locale, presence: true
klass.validate :parent_locale_match
# RELATIONS
klass.has_and_belongs_to_many :keywords, storing_keys: true, class_name: 'Cmtool::Keyword'
@@ -36,6 +37,12 @@ module Cmtool
def generate_name
name = self.class.generate_name(title)
end
private
def parent_locale_match
if parent.present?
errors.add(:locale, 'must be the same as the parent') unless parent.locale == locale
end
end
end
module ClassMethods
+1 -1
View File
@@ -1,3 +1,3 @@
module Cmtool
VERSION = "0.4.0"
VERSION = "0.5.0"
end
+45
View File
@@ -0,0 +1,45 @@
require 'acceptance/acceptance_helper'
feature 'Pages index', %q{
In order have pages
As a user
I want to see pages
} do
scenario 'visit root' do
visit '/cmtool'
page.current_path.should == '/users/sign_in'
end
context 'with logged in user' do
background do
create_user 'test@example.com'
login_as 'test@example.com'
end
context 'without pages' do
scenario 'list pages as root' do
visit '/cmtool'
page.should have_link 'New Page'
end
end
context 'with pages' do
background do
@nl1 = create :page, name: 'nl1', locale: 'nl'
@nl11 = create :page, name: 'nl11', locale: 'nl', parent_id: @nl1.id
@nl111 = create :page, name: 'nl111', locale: 'nl', parent_id: @nl11.id
@nl12 = create :page, name: 'nl12', locale: 'nl', parent_id: @nl1.id
@en1 = create :page, name: 'en1', locale: 'en'
end
scenario 'see both languages' do
visit '/cmtool'
page.should have_link 'nl1'
page.should have_link '- nl11'
page.should have_link '- - nl111'
page.should have_link '- nl12'
page.should have_link 'en1'
end
end
end
end
+13
View File
@@ -1,6 +1,19 @@
module HelperMethods
# Put helper methods you need to be available in all acceptance specs here.
def create_user(email, password='secret')
@user = User.find_by_email(email) || FactoryGirl.create(:user, email: email, password: password)
end
def login_as(email)
visit "/users/sign_in"
fill_in "user_email", with: email
fill_in "user_password", with: "secret"
submit_form
end
def submit_form
find("[type=submit]").click
end
end
RSpec.configuration.include HelperMethods, :type => :acceptance
+10
View File
@@ -63,5 +63,15 @@ describe Cmtool::Menu do
second_last.should be_a Cmtool::Menu::ResourceLink
second_last.resource.should == Page
end
it "should fall back to normal behaviour when no menu item specified is found" do
Cmtool::Menu.reset!
Cmtool::Menu.register do
append_to :publications do
resource_link Cmtool::Directory
end
end
Cmtool::Menu.items.size.should == 1
end
end
end
+6
View File
@@ -0,0 +1,6 @@
FactoryGirl.define do
factory :page, class: Page do
sequence(:name){|i| "page#{i}"}
locale 'en'
end
end
+21
View File
@@ -0,0 +1,21 @@
require 'spec_helper'
describe Page do
before :each do
@nl1 = create :page, name: 'nl1', locale: 'nl'
@nl11 = create :page, name: 'nl11', locale: 'nl', parent_id: @nl1.id
@nl111 = create :page, name: 'nl111', locale: 'nl', parent_id: @nl11.id
@nl12 = create :page, name: 'nl12', locale: 'nl', parent_id: @nl1.id
@en1 = create :page, name: 'en1', locale: 'en'
end
describe :ancestry do
it "should not be valid when the parent has a different locale then the page itself" do
@nl12.parent_id = @en1.id
@nl12.should_not be_valid
@nl12.error_on(:locale).should_not be_empty
end
end
end
+1 -14
View File
@@ -15,7 +15,7 @@ Dir[File.join(ENGINE_RAILS_ROOT, "spec/factories/**/*.rb")].each {|f| require f
I18n.locale = :en
Devise.stretches = 1
Capybara.default_driver = :selenium
#Capybara.default_driver = :selenium
RSpec.configure do |config|
config.mock_with :rspec
config.include FactoryGirl::Syntax::Methods
@@ -42,19 +42,6 @@ RSpec.configure do |config|
config.before :all do
end
config.before :each, type: :request do
#Capybara.current_driver = :selenium
sign_in_user_through_request
end
config.after :each, type: :request do
visit "/users/sign_out"
end
def sign_in_user_through_request
visit "/users/sign_in"
fill_in 'user[email]', with: @user.email
fill_in 'user[password]', with: @user.password
click_on 'Sign in'
end
def create_pages_tree
root1 = Page.create(name: 'root1', locale: 'en')