diff --git a/.travis.yml b/.travis.yml index 5962258..ccdbb6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ rvm: -- 1.9.2 +- 1.9.3 services: - couchdb before_script: diff --git a/Gemfile.lock b/Gemfile.lock index 8cca510..f338188 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/views/cmtool/pages/_form.html.haml b/app/views/cmtool/pages/_form.html.haml index 93410cc..e4c6ac8 100644 --- a/app/views/cmtool/pages/_form.html.haml +++ b/app/views/cmtool/pages/_form.html.haml @@ -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 diff --git a/config/initializers/cmtool_menu.rb b/config/initializers/cmtool_menu.rb deleted file mode 100644 index e7acca1..0000000 --- a/config/initializers/cmtool_menu.rb +++ /dev/null @@ -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 diff --git a/lib/cmtool/engine.rb b/lib/cmtool/engine.rb index 58e8f14..226073f 100644 --- a/lib/cmtool/engine.rb +++ b/lib/cmtool/engine.rb @@ -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__) diff --git a/lib/cmtool/includes/page.rb b/lib/cmtool/includes/page.rb index d75c5aa..2c3f15a 100644 --- a/lib/cmtool/includes/page.rb +++ b/lib/cmtool/includes/page.rb @@ -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 diff --git a/lib/cmtool/version.rb b/lib/cmtool/version.rb index 3d93b08..dc6c49a 100644 --- a/lib/cmtool/version.rb +++ b/lib/cmtool/version.rb @@ -1,3 +1,3 @@ module Cmtool - VERSION = "0.4.0" + VERSION = "0.5.0" end diff --git a/spec/acceptance/cmtool/pages_spec.rb b/spec/acceptance/cmtool/pages_spec.rb new file mode 100644 index 0000000..15c0d82 --- /dev/null +++ b/spec/acceptance/cmtool/pages_spec.rb @@ -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 diff --git a/spec/acceptance/support/helpers.rb b/spec/acceptance/support/helpers.rb index ed4c0e0..2f56cf5 100644 --- a/spec/acceptance/support/helpers.rb +++ b/spec/acceptance/support/helpers.rb @@ -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 \ No newline at end of file +RSpec.configuration.include HelperMethods, :type => :acceptance diff --git a/spec/cmtool_menu_spec.rb b/spec/cmtool_menu_spec.rb index 445bc6e..6010ff9 100644 --- a/spec/cmtool_menu_spec.rb +++ b/spec/cmtool_menu_spec.rb @@ -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 diff --git a/spec/factories/page_factory.rb b/spec/factories/page_factory.rb new file mode 100644 index 0000000..3170041 --- /dev/null +++ b/spec/factories/page_factory.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :page, class: Page do + sequence(:name){|i| "page#{i}"} + locale 'en' + end +end diff --git a/spec/models/page_spec.rb b/spec/models/page_spec.rb new file mode 100644 index 0000000..9eb318d --- /dev/null +++ b/spec/models/page_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6d8130a..af2fe8f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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')