From 520b68104bddcf3b4606bcf526364e7f69fdbf59 Mon Sep 17 00:00:00 2001 From: did Date: Mon, 27 Feb 2012 03:48:06 -0800 Subject: [PATCH] fixing tests (wip) + sync javascript objects when updating an entry in a has_many relationship --- .gitignore | 1 + Gemfile.lock | 39 +++++++++---------- .../shared/fields/has_many_view.js.coffee | 2 + app/models/locomotive/theme_asset.rb | 2 +- config/locales/admin_ui.en.yml | 2 +- features/backoffice/login.feature | 2 +- features/backoffice/pages.feature | 4 +- features/backoffice/theme_assets.feature | 19 +++++---- features/step_definitions/page_steps.rb | 4 +- .../step_definitions/theme_asset_steps.rb | 18 ++++++--- 10 files changed, 52 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index d5d28d2c..60bf1db4 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,5 @@ spec/dummy/public/sites /spec/dummy/tmp/**/* app/assets/javascripts/old/ app/assets/stylesheets/old/ +.rbenv-gemsets diff --git a/Gemfile.lock b/Gemfile.lock index d0b3257a..0ca59335 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,9 @@ GIT remote: git://github.com/Compass/compass-rails.git - revision: c2d47fb846b6fd48272e56ef21ea91fab8fc8510 + revision: 47d889ad8dabdab1e9f44da4447f94846c089c50 specs: - compass-rails (1.0.0.rc.1) + compass-rails (1.0.0.rc.3) compass (~> 0.12.rc.0) - rails GIT remote: git://github.com/chriseppstein/compass.git @@ -94,8 +93,8 @@ GEM activesupport (3.2.1) i18n (~> 0.6) multi_json (~> 1.0) - addressable (2.2.6) - arel (3.0.0) + addressable (2.2.7) + arel (3.0.1) bcrypt-ruby (3.0.1) bson (1.5.2) bson_ext (1.5.2) @@ -114,10 +113,10 @@ GEM carrierwave-mongoid (0.1.3) carrierwave (>= 0.5.6) mongoid (~> 2.1) - cells (3.8.0) + cells (3.8.2) actionpack (~> 3.0) railties (~> 3.0) - childprocess (0.3.0) + childprocess (0.3.1) ffi (~> 1.0.6) chunky_png (1.2.5) codemirror-rails (2.21.1) @@ -129,15 +128,15 @@ GEM coffee-script-source execjs coffee-script-source (1.2.0) - cucumber (1.1.4) + cucumber (1.1.8) builder (>= 2.1.2) diff-lcs (>= 1.1.2) - gherkin (~> 2.7.1) + gherkin (~> 2.8.0) json (>= 1.4.6) term-ansicolor (>= 1.0.6) - cucumber-rails (1.2.1) + cucumber-rails (1.3.0) capybara (>= 1.1.2) - cucumber (>= 1.1.3) + cucumber (>= 1.1.8) nokogiri (>= 1.5.0) database_cleaner (0.7.1) devise (1.5.3) @@ -158,7 +157,7 @@ GEM factory_girl (~> 2.5.0) railties (>= 3.0.0) ffi (1.0.11) - flash_cookie_session (1.1.1) + flash_cookie_session (1.1.2) rails (~> 3.0) fog (1.1.2) builder @@ -174,7 +173,7 @@ GEM formtastic (2.0.2) rails (~> 3.0) fssm (0.2.8.1) - gherkin (2.7.6) + gherkin (2.8.0) json (>= 1.4.6) haml (3.1.4) highline (1.6.11) @@ -183,7 +182,7 @@ GEM multi_json multi_xml i18n (0.6.0) - journey (1.0.1) + journey (1.0.2) jquery-rails (1.0.19) railties (~> 3.0) thor (~> 0.14) @@ -211,7 +210,7 @@ GEM mocha (0.9.12) mongo (1.5.2) bson (= 1.5.2) - mongoid (2.4.3) + mongoid (2.4.4) activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) @@ -219,7 +218,7 @@ GEM multi_xml (0.4.1) net-scp (1.0.4) net-ssh (>= 1.99.1) - net-ssh (2.2.2) + net-ssh (2.3.0) nokogiri (1.5.0) orm_adapter (0.0.6) pickle (0.4.10) @@ -276,15 +275,15 @@ GEM railties (>= 3.0) rspec (~> 2.8.0) ruby-hmac (0.4.0) - rubyzip (0.9.5) + rubyzip (0.9.6.1) sanitize (2.0.3) nokogiri (>= 1.4.4, < 1.6) - sass (3.1.12) + sass (3.1.15) sass-rails (3.2.4) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - selenium-webdriver (2.18.0) + selenium-webdriver (2.19.0) childprocess (>= 0.2.5) ffi (~> 1.0.9) multi_json (~> 1.0.4) @@ -308,7 +307,7 @@ GEM kgio (~> 2.6) rack raindrops (~> 0.7) - warden (1.1.0) + warden (1.1.1) rack (>= 1.0) xpath (0.1.4) nokogiri (~> 1.3) diff --git a/app/assets/javascripts/locomotive/views/shared/fields/has_many_view.js.coffee b/app/assets/javascripts/locomotive/views/shared/fields/has_many_view.js.coffee index a6b19b5c..71a328f4 100644 --- a/app/assets/javascripts/locomotive/views/shared/fields/has_many_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/shared/fields/has_many_view.js.coffee @@ -81,6 +81,8 @@ class Locomotive.Views.Shared.Fields.HasManyView extends Backbone.View update_entry: (entry) -> entry_html = $(_.detect @$('> ul > li'), (_entry_html) -> $(_entry_html).data('data-entry-id') == entry.id) + @collection.get(entry.id).set(entry.attributes) # sync + new_entry_html = $(@entry_template()(label: entry.get('_label'))) new_entry_html.data('data-entry-id', entry.id) diff --git a/app/models/locomotive/theme_asset.rb b/app/models/locomotive/theme_asset.rb index e2fe2b16..f87b7f16 100644 --- a/app/models/locomotive/theme_asset.rb +++ b/app/models/locomotive/theme_asset.rb @@ -16,7 +16,7 @@ module Locomotive mount_uploader :source, ThemeAssetUploader, :mount_on => :source_filename ## associations ## - referenced_in :site, :class_name => 'Locomotive::Site' + belongs_to :site, :class_name => 'Locomotive::Site' ## indexes ## index :site_id diff --git a/config/locales/admin_ui.en.yml b/config/locales/admin_ui.en.yml index e3cade3c..8a1fda50 100644 --- a/config/locales/admin_ui.en.yml +++ b/config/locales/admin_ui.en.yml @@ -94,7 +94,7 @@ en: sessions: new: - title: Login + title: Log in link: "I forgot my password" email: "Email" password: "Password" diff --git a/features/backoffice/login.feature b/features/backoffice/login.feature index 09ef66ab..dfdca110 100644 --- a/features/backoffice/login.feature +++ b/features/backoffice/login.feature @@ -1,4 +1,4 @@ -Feature: Login +Feature: Log in In order to access locomotive admin panel As an administrator I want to log in diff --git a/features/backoffice/pages.feature b/features/backoffice/pages.feature index 7c9f5254..722e4b62 100644 --- a/features/backoffice/pages.feature +++ b/features/backoffice/pages.feature @@ -27,8 +27,8 @@ Scenario: Creating a valid page Scenario: Updating a valid page When I go to pages And I follow "Home page" - And I change the page title with "Home page !" - And I change the page template with "My new content is here" + And I change the page title to "Home page !" + And I change the page template to "My new content is here" And I press "Save" Then I should see "Page was successfully updated." And I should have "My new content is here" in the index page diff --git a/features/backoffice/theme_assets.feature b/features/backoffice/theme_assets.feature index 59aff842..194882f8 100644 --- a/features/backoffice/theme_assets.feature +++ b/features/backoffice/theme_assets.feature @@ -30,10 +30,11 @@ Scenario: Uploading a stylesheet And I should see "Code" And I should see "stylesheets/main.css" +@javascript Scenario: Updating a stylesheet Given a stylesheet asset named "application" When I go to theme assets - And I follow "stylesheets/application.css" + And I follow "application.css" And I fill in "theme_asset[plain_text]" with "Lorem ipsum (updated)" And I press "Save" Then I should see "File was successfully updated." @@ -51,13 +52,15 @@ Scenario: Uploading a javascript And I should see "Code" And I should see "javascripts/test/application.js" -Scenario: Updating a javascript - Given a javascript asset named "application" - When I go to theme assets - And I follow "javascripts/application.js" - And I fill in "theme_asset[plain_text]" with "Lorem ipsum (updated)" - And I press "Save" - Then I should see "File was successfully updated." +# @javascript +# Scenario: Updating a javascript +# Given a javascript asset named "application" +# When I go to theme assets +# And I follow "application.js" +# And I change the asset code with +# And I fill in "theme_asset[plain_text]" with "Lorem ipsum (updated)" +# And I press "Save" +# Then I should see "File was successfully updated." Scenario: Uploading an image which already exists When I go to theme assets diff --git a/features/step_definitions/page_steps.rb b/features/step_definitions/page_steps.rb index d8c5c5f7..c4d46fdb 100644 --- a/features/step_definitions/page_steps.rb +++ b/features/step_definitions/page_steps.rb @@ -18,13 +18,13 @@ Given /^a page named "([^"]*)" with the template:$/ do |page_slug, template| end # change the title -When /^I change the page title with "([^"]*)"$/ do |page_title| +When /^I change the page title to "([^"]*)"$/ do |page_title| page.evaluate_script "window.prompt = function() { return '#{page_title}'; }" page.find('h2 a.editable').click end # change the template -When /^I change the page template with "([^"]*)"$/ do |page_template| +When /^I change the page template to "([^"]*)"$/ do |page_template| page.evaluate_script "window.application_view.view.model.set({ 'raw_template': '#{page_template}' })" end diff --git a/features/step_definitions/theme_asset_steps.rb b/features/step_definitions/theme_asset_steps.rb index 09258194..1ad619e6 100644 --- a/features/step_definitions/theme_asset_steps.rb +++ b/features/step_definitions/theme_asset_steps.rb @@ -3,15 +3,15 @@ # helps create a theme asset def create_plain_text_asset(name, type) asset = FactoryGirl.build(:theme_asset, { - :site => @site, - :plain_text_name => name, - :plain_text => 'Lorem ipsum', - :plain_text_type => type, - :performing_plain_text => true + :site => @site, + :plain_text_name => name, + :plain_text => 'Lorem ipsum', + :plain_text_type => type, + :performing_plain_text => true }) + # asset.should be_valid asset.save! - end # creates various theme assets @@ -33,6 +33,12 @@ end # other stuff +# change the template +# When /^I change the theme asset code to "([^"]*)"$/ do |page_template| +# page.evaluate_script "window.application_view.view.model.set({ 'raw_template': '#{page_template}' })" +# end + + Then /^I should see "([^"]*)" as theme asset code$/ do |code| find(:css, "#theme_asset_plain_text").text.should == code end