adva-core 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/admin/base_controller.rb +21 -0
- data/app/controllers/admin/pages_controller.rb +9 -0
- data/app/controllers/admin/sections_controller.rb +36 -0
- data/app/controllers/admin/sites_controller.rb +18 -0
- data/app/controllers/articles_controller.rb +3 -0
- data/app/controllers/base_controller.rb +22 -0
- data/app/controllers/installations_controller.rb +28 -0
- data/app/controllers/pages_controller.rb +2 -0
- data/app/controllers/sections_controller.rb +3 -0
- data/app/helpers/form_helper.rb +13 -0
- data/app/helpers/sections_helper.rb +7 -0
- data/app/helpers/url_helper.rb +18 -0
- data/app/models/account.rb +3 -0
- data/app/models/article.rb +2 -0
- data/app/models/content.rb +4 -0
- data/app/models/page.rb +17 -0
- data/app/models/section.rb +59 -0
- data/app/models/site.rb +26 -0
- data/app/views/admin/pages/_menu.html.rb +30 -0
- data/app/views/admin/pages/new.html.rb +19 -0
- data/app/views/admin/pages/show.html.rb +25 -0
- data/app/views/admin/sections/_menu.html.rb +12 -0
- data/app/views/admin/sections/_section.html.rb +7 -0
- data/app/views/admin/sections/_select_type.html.rb +16 -0
- data/app/views/admin/sections/index.html.rb +28 -0
- data/app/views/admin/sites/_menu.html.rb +6 -0
- data/app/views/admin/sites/edit.html.rb +22 -0
- data/app/views/admin/sites/index.html.rb +12 -0
- data/app/views/admin/sites/new.html.rb +39 -0
- data/app/views/admin/sites/show.html.rb +7 -0
- data/app/views/installations/new.html.rb +39 -0
- data/app/views/installations/show.html.rb +9 -0
- data/app/views/layouts/_flash.html.rb +9 -0
- data/app/views/layouts/admin.rb +38 -0
- data/app/views/layouts/admin/_header.rb +48 -0
- data/app/views/layouts/admin/_tabs.html.rb +18 -0
- data/app/views/layouts/admin/_top.rb +56 -0
- data/app/views/layouts/base.rb +58 -0
- data/app/views/layouts/default.rb +31 -0
- data/app/views/layouts/default/_menu.rb +24 -0
- data/app/views/layouts/simple.rb +16 -0
- data/app/views/pages/show.html.rb +7 -0
- data/config/initializers/simple_form.rb +53 -0
- data/config/locales/en.yml +137 -0
- data/config/redirects.rb +8 -0
- data/config/routes.rb +21 -0
- data/lib/adva-core.rb +1 -0
- data/lib/adva.rb +37 -0
- data/lib/adva/active_record/has_options.rb +55 -0
- data/lib/adva/cli.rb +16 -0
- data/lib/adva/controller.rb +7 -0
- data/lib/adva/controller/abstract_actions.rb +87 -0
- data/lib/adva/controller/internal_redirect.rb +26 -0
- data/lib/adva/controller/references.rb +28 -0
- data/lib/adva/core.rb +84 -0
- data/lib/adva/engine.rb +64 -0
- data/lib/adva/engine/sliced_models.rb +35 -0
- data/lib/adva/generators.rb +8 -0
- data/lib/adva/generators/app.rb +121 -0
- data/lib/adva/generators/engine.rb +58 -0
- data/lib/adva/generators/gemfile.rb +50 -0
- data/lib/adva/generators/install.rb +31 -0
- data/lib/adva/generators/templates/app/app_template.rb +3 -0
- data/lib/adva/generators/templates/engine/Gemfile.erb +3 -0
- data/lib/adva/generators/templates/engine/all.rb +1 -0
- data/lib/adva/generators/templates/engine/en.yml.erb +2 -0
- data/lib/adva/generators/templates/engine/engine.rb.erb +11 -0
- data/lib/adva/generators/templates/engine/gemspec.erb +21 -0
- data/lib/adva/generators/templates/engine/migration.rb.erb +11 -0
- data/lib/adva/generators/templates/engine/redirects.rb.erb +3 -0
- data/lib/adva/generators/templates/engine/routes.rb.erb +3 -0
- data/lib/adva/generators/templates/engine/test_helper.rb.erb +3 -0
- data/lib/adva/rack.rb +5 -0
- data/lib/adva/rack/static.rb +50 -0
- data/lib/adva/registry.rb +62 -0
- data/lib/adva/responder.rb +21 -0
- data/lib/adva/responder/redirect.rb +31 -0
- data/lib/adva/routing_filters/section_path.rb +72 -0
- data/lib/adva/routing_filters/section_root.rb +65 -0
- data/lib/adva/tasks/core.rake +9 -0
- data/lib/adva/tasks/core.rb +160 -0
- data/lib/adva/testing.rb +57 -0
- data/lib/adva/testing/engine.rb +37 -0
- data/lib/adva/view.rb +7 -0
- data/lib/adva/view/form.rb +44 -0
- data/lib/adva/view/form/tabs.rb +46 -0
- data/lib/adva/view/menu.rb +51 -0
- data/lib/adva/view/menu/admin.rb +48 -0
- data/lib/adva/view/tabs.rb +28 -0
- data/lib/core_ext/rails/action_view/has_many_through_collection_helpers.rb +27 -0
- data/lib/core_ext/rails/active_record/skip_callbacks.rb +51 -0
- data/lib/core_ext/ruby/array/flatten_once.rb +9 -0
- data/lib/core_ext/ruby/kernel/silence_stream.rb +17 -0
- data/lib/core_ext/ruby/module/include_anonymous.rb +36 -0
- data/lib/core_ext/ruby/module/option_reader.rb +9 -0
- data/lib/patches/arel/table_initialization_fixes.rb +68 -0
- data/lib/patches/inherited_resources.rb +34 -0
- data/lib/patches/rails/arel_table_options_fix.rb +13 -0
- data/lib/patches/rails/asset_expansion_multiple_registrations.rb +21 -0
- data/lib/patches/rails/recognize_path_env.rb +43 -0
- data/lib/patches/rails/route_set_to_param.rb +25 -0
- data/lib/patches/rails/sti_associations.rb +17 -0
- data/lib/patches/rails/template_resolver_caching.rb +9 -0
- data/lib/patches/rails/url_for.rb +60 -0
- data/lib/patches/simple_form.rb +37 -0
- data/lib/patches/thor/core_ext/hash.rb +7 -0
- data/lib/patches/thor/group/symbolized_options.rb +8 -0
- data/lib/patches/webrat/links-data-method.rb +19 -0
- data/lib/patches/webrat/logger.rb +19 -0
- data/lib/patches/webrat/upload_file.rb +28 -0
- data/lib/testing/assertions.rb +19 -0
- data/lib/testing/factories.rb +30 -0
- data/lib/testing/helpers/global_helpers.rb +9 -0
- data/lib/testing/paths.rb +54 -0
- data/lib/testing/step_definitions/common_steps.rb +279 -0
- data/lib/testing/step_definitions/menu_steps.rb +11 -0
- data/lib/testing/step_definitions/routes_steps.rb +18 -0
- data/lib/testing/step_definitions/transforms.rb +43 -0
- data/lib/testing/step_definitions/webrat_steps.rb +291 -0
- data/lib/testing/step_definitions/within_steps.rb +17 -0
- data/lib/webrat/integrations/rails.rb +33 -0
- data/public/images/adva-core/admin/header_bg.png +0 -0
- data/public/images/adva-core/admin/menu_checkmark.png +0 -0
- data/public/images/adva-core/admin/section_menu_bg.png +0 -0
- data/public/images/adva-core/admin/tab_action_active.png +0 -0
- data/public/images/adva-core/admin/tab_main_active.png +0 -0
- data/public/images/adva-core/admin/tab_sidebar_active.png +0 -0
- data/public/images/adva-core/admin/tab_top_active.png +0 -0
- data/public/images/adva-core/asset_selected.png +0 -0
- data/public/images/adva-core/avatar.gif +0 -0
- data/public/images/adva-core/feed.mini.png +0 -0
- data/public/images/adva-core/filter-bg.png +0 -0
- data/public/images/adva-core/grid.png +0 -0
- data/public/images/adva-core/icons/accept.png +0 -0
- data/public/images/adva-core/icons/add.png +0 -0
- data/public/images/adva-core/icons/arrow_cross.png +0 -0
- data/public/images/adva-core/icons/arrow_cross_2.png +0 -0
- data/public/images/adva-core/icons/arrow_cross_3.png +0 -0
- data/public/images/adva-core/icons/arrow_up_down.png +0 -0
- data/public/images/adva-core/icons/assets/audio.png +0 -0
- data/public/images/adva-core/icons/assets/doc.png +0 -0
- data/public/images/adva-core/icons/assets/pdf.png +0 -0
- data/public/images/adva-core/icons/assets/video.png +0 -0
- data/public/images/adva-core/icons/attach.png +0 -0
- data/public/images/adva-core/icons/bin.png +0 -0
- data/public/images/adva-core/icons/bin_closed.png +0 -0
- data/public/images/adva-core/icons/bin_empty.png +0 -0
- data/public/images/adva-core/icons/bullet_black.png +0 -0
- data/public/images/adva-core/icons/bullet_delete.png +0 -0
- data/public/images/adva-core/icons/bullet_error.png +0 -0
- data/public/images/adva-core/icons/bullet_go.png +0 -0
- data/public/images/adva-core/icons/bullet_red.png +0 -0
- data/public/images/adva-core/icons/bullet_white.png +0 -0
- data/public/images/adva-core/icons/bullet_yellow.png +0 -0
- data/public/images/adva-core/icons/cancel.png +0 -0
- data/public/images/adva-core/icons/comment.gif +0 -0
- data/public/images/adva-core/icons/comment.png +0 -0
- data/public/images/adva-core/icons/comment_add.png +0 -0
- data/public/images/adva-core/icons/comment_blue.gif +0 -0
- data/public/images/adva-core/icons/comment_delete.png +0 -0
- data/public/images/adva-core/icons/comment_edit.png +0 -0
- data/public/images/adva-core/icons/comment_yellow.gif +0 -0
- data/public/images/adva-core/icons/cross.png +0 -0
- data/public/images/adva-core/icons/delete.png +0 -0
- data/public/images/adva-core/icons/eye.png +0 -0
- data/public/images/adva-core/icons/favorites.png +0 -0
- data/public/images/adva-core/icons/help.png +0 -0
- data/public/images/adva-core/icons/hourglass.png +0 -0
- data/public/images/adva-core/icons/icon_attachment.gif +0 -0
- data/public/images/adva-core/icons/icon_padlock.gif +0 -0
- data/public/images/adva-core/icons/link.png +0 -0
- data/public/images/adva-core/icons/lock.png +0 -0
- data/public/images/adva-core/icons/magnifier.png +0 -0
- data/public/images/adva-core/icons/minus.gif +0 -0
- data/public/images/adva-core/icons/page_add.png +0 -0
- data/public/images/adva-core/icons/page_delete.png +0 -0
- data/public/images/adva-core/icons/page_edit.png +0 -0
- data/public/images/adva-core/icons/page_favorites.png +0 -0
- data/public/images/adva-core/icons/page_go.png +0 -0
- data/public/images/adva-core/icons/page_green.png +0 -0
- data/public/images/adva-core/icons/page_red.png +0 -0
- data/public/images/adva-core/icons/page_white_add.png +0 -0
- data/public/images/adva-core/icons/page_white_delete.png +0 -0
- data/public/images/adva-core/icons/page_white_edit.png +0 -0
- data/public/images/adva-core/icons/page_white_go.png +0 -0
- data/public/images/adva-core/icons/page_white_link.png +0 -0
- data/public/images/adva-core/icons/page_white_magnify.png +0 -0
- data/public/images/adva-core/icons/pencil.png +0 -0
- data/public/images/adva-core/icons/star.png +0 -0
- data/public/images/adva-core/icons/stop.png +0 -0
- data/public/images/adva-core/icons/tag_green.png +0 -0
- data/public/images/adva-core/icons/tick.png +0 -0
- data/public/images/adva-core/icons/zoom.png +0 -0
- data/public/images/adva-core/indicator.gif +0 -0
- data/public/images/adva-core/lines.png +0 -0
- data/public/images/adva-core/preview.png +0 -0
- data/public/images/adva-core/rails.png +0 -0
- data/public/images/adva-core/sortable_tree/drag.png +0 -0
- data/public/images/adva-core/theme_selected.png +0 -0
- data/public/javascripts/adva-core/admin.js +21 -0
- data/public/javascripts/adva-core/jquery/jquery-1.4.2.min.js +154 -0
- data/public/javascripts/adva-core/jquery/jquery.table_tree.js +292 -0
- data/public/javascripts/adva-core/jquery/jquery.tablednd_0_5.js +386 -0
- data/public/javascripts/adva-core/rails.js +127 -0
- data/public/javascripts/backup/admin/jquery.admin.js +77 -0
- data/public/javascripts/backup/admin/jquery.article.js +22 -0
- data/public/javascripts/backup/admin/jquery.cached_pages.js +14 -0
- data/public/javascripts/backup/admin/jquery.table_tree.backup.js +279 -0
- data/public/javascripts/backup/admin/jquery.table_tree.js +10 -0
- data/public/javascripts/backup/application.js +38 -0
- data/public/javascripts/backup/application.prototype.js +135 -0
- data/public/javascripts/backup/builder.js +136 -0
- data/public/javascripts/backup/controls.js +965 -0
- data/public/javascripts/backup/cookie.js +49 -0
- data/public/javascripts/backup/dragdrop.js +975 -0
- data/public/javascripts/backup/effects.js +1130 -0
- data/public/javascripts/backup/flash.js +49 -0
- data/public/javascripts/backup/jquery.dates.js +49 -0
- data/public/javascripts/backup/jquery.flash.js +40 -0
- data/public/javascripts/backup/jquery.roles.js +23 -0
- data/public/javascripts/backup/jquery/jquery-lowpro.js +224 -0
- data/public/javascripts/backup/jquery/jquery-ui.js +273 -0
- data/public/javascripts/backup/jquery/jquery.js +19 -0
- data/public/javascripts/backup/jquery/jquery.qtip.min.js +15 -0
- data/public/javascripts/backup/json.js +139 -0
- data/public/javascripts/backup/lowpro.js +320 -0
- data/public/javascripts/backup/parseuri.js +39 -0
- data/public/javascripts/backup/prototype.js +4320 -0
- data/public/javascripts/backup/roles.js +16 -0
- data/public/javascripts/backup/scriptaculous.js +60 -0
- data/public/javascripts/backup/slider.js +275 -0
- data/public/javascripts/backup/sound.js +55 -0
- data/public/javascripts/backup/unittest.js +568 -0
- data/public/stylesheets/adva-core/admin/forms.css +172 -0
- data/public/stylesheets/adva-core/admin/layout.css +38 -0
- data/public/stylesheets/adva-core/admin/lists.css +54 -0
- data/public/stylesheets/adva-core/admin/navigation.css +234 -0
- data/public/stylesheets/adva-core/admin/sidebar.css +87 -0
- data/public/stylesheets/adva-core/admin/styles.css +128 -0
- data/public/stylesheets/adva-core/common/forms.css +174 -0
- data/public/stylesheets/adva-core/common/layout.css +93 -0
- data/public/stylesheets/adva-core/common/reset.css +42 -0
- data/public/stylesheets/adva-core/common/styles.css +41 -0
- data/public/stylesheets/adva-core/default/layout.css +0 -0
- data/public/stylesheets/adva-core/default/styles.css +30 -0
- data/public/stylesheets/adva-core/simple/layout.css +11 -0
- data/public/stylesheets/backup/alternate/common.css +76 -0
- data/public/stylesheets/backup/alternate/forms.css +121 -0
- data/public/stylesheets/backup/alternate/header.css +125 -0
- data/public/stylesheets/backup/alternate/layout.css +103 -0
- data/public/stylesheets/backup/alternate/lists.css +153 -0
- data/public/stylesheets/backup/alternate/sidebar.css +65 -0
- data/public/stylesheets/backup/alternate/top.css +123 -0
- data/public/stylesheets/backup/content.css +11 -0
- data/public/stylesheets/backup/helptip.css +35 -0
- data/public/stylesheets/backup/jquery/alternate/jquery.tooltip.css +13 -0
- data/public/stylesheets/backup/jquery/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-icons_222222_256x240.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-icons_2e83ff_256x240.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-icons_454545_256x240.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-icons_888888_256x240.png +0 -0
- data/public/stylesheets/backup/jquery/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/public/stylesheets/backup/jquery/jquery-ui.css +406 -0
- data/public/stylesheets/backup/jquery/jquery.tooltip.css +10 -0
- data/public/stylesheets/backup/layout.css +22 -0
- data/public/stylesheets/backup/lists.css +17 -0
- data/public/stylesheets/backup/menu.css +129 -0
- data/public/stylesheets/backup/projection.css +118 -0
- data/public/stylesheets/backup/screen/top.css +8 -0
- data/public/stylesheets/backup/themes.css +49 -0
- data/public/stylesheets/backup/users.css +40 -0
- metadata +536 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
Factory.define :site do |f|
|
2
|
+
f.account Account.first || Account.create!
|
3
|
+
f.name 'adva-cms'
|
4
|
+
f.host 'www.example.com'
|
5
|
+
f.title 'adva-cms'
|
6
|
+
f.sections_attributes [{
|
7
|
+
:type => 'Page',
|
8
|
+
:name => 'Home',
|
9
|
+
:article_attributes => {
|
10
|
+
:body => 'Body'
|
11
|
+
}
|
12
|
+
}]
|
13
|
+
f.after_create { |site| Factory(:admin) }
|
14
|
+
end
|
15
|
+
|
16
|
+
Factory.define :section do |f|
|
17
|
+
f.site { Site.first || Factory(:site) }
|
18
|
+
f.name 'Home'
|
19
|
+
end
|
20
|
+
|
21
|
+
Factory.define :page do |f|
|
22
|
+
f.site { Site.first || Factory(:site) }
|
23
|
+
f.name 'Home'
|
24
|
+
end
|
25
|
+
|
26
|
+
Factory.define :content do |f|
|
27
|
+
f.site { Site.first || Factory(:site) }
|
28
|
+
f.section { Section.first || Factory(:section) }
|
29
|
+
f.title 'Content'
|
30
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module GlobalHelpers
|
2
|
+
def site
|
3
|
+
Site.first || raise("Could not find a site. Maybe you want to set one up in your story background?")
|
4
|
+
end
|
5
|
+
|
6
|
+
def account
|
7
|
+
Account.first || raise("Could not find a site. Maybe you want to set one up in your story background?")
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Adva::Core::Paths
|
2
|
+
def path_to(page)
|
3
|
+
case page
|
4
|
+
|
5
|
+
when /^\//
|
6
|
+
page
|
7
|
+
|
8
|
+
when /^the home\s?page$/
|
9
|
+
'/'
|
10
|
+
|
11
|
+
when /^the site installation page$/
|
12
|
+
new_installation_path
|
13
|
+
|
14
|
+
when /^the site installation confirmation page$/
|
15
|
+
installation_path(Site.last)
|
16
|
+
|
17
|
+
when /^the "([^"]*)" section page$/
|
18
|
+
section = Section.where(:name => $1).first || raise("could not find section named #{$1}")
|
19
|
+
polymorphic_path(section)
|
20
|
+
|
21
|
+
when /^the admin sites page$/
|
22
|
+
polymorphic_path([:admin, :sites])
|
23
|
+
|
24
|
+
when /^the admin dashboard page$/
|
25
|
+
site = Site.first
|
26
|
+
polymorphic_path([:admin, site])
|
27
|
+
|
28
|
+
when /^the admin dashboard page for the site on "([^"]*)"$/
|
29
|
+
site = Site.find_by_host($1) || raise("could not find site with host #{$1}")
|
30
|
+
polymorphic_path([:admin, site])
|
31
|
+
|
32
|
+
when /^the admin sections page$/
|
33
|
+
site = Site.first
|
34
|
+
polymorphic_path([:admin, site, :sections])
|
35
|
+
|
36
|
+
when /^the admin "([^"]*)" section page$/
|
37
|
+
site = Site.first
|
38
|
+
section = Section.where(:name => $1).first || raise("could not find section named #{$1}")
|
39
|
+
polymorphic_path([:admin, site, section])
|
40
|
+
|
41
|
+
when /^the admin "([^"]*)" section settings page$/
|
42
|
+
site = Site.first
|
43
|
+
section = Section.where(:name => $1).first || raise("could not find section named #{$1}")
|
44
|
+
polymorphic_path([:edit, :admin, site, section])
|
45
|
+
|
46
|
+
else
|
47
|
+
named_route_helper = page.gsub(/(\Athe )|( page\Z)/, '').gsub(/ +/, '_').downcase + '_path'
|
48
|
+
raise "Can't find mapping from \"#{page}\" to a path.\nNow, go and add a mapping in #{__FILE__}" unless respond_to?(named_route_helper)
|
49
|
+
send named_route_helper
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
World(Adva::Core::Paths)
|
@@ -0,0 +1,279 @@
|
|
1
|
+
Given 'a site' do
|
2
|
+
@site = Factory(:site)
|
3
|
+
end
|
4
|
+
|
5
|
+
# TODO what's this?
|
6
|
+
Transform /^table:name,product_name$/ do |table|
|
7
|
+
transformed_table = table.hashes.map do |row|
|
8
|
+
row.merge('product_id' => Product.find_by_name(row.delete('product_name')).id)
|
9
|
+
end
|
10
|
+
Cucumber::Ast::Table.new(transformed_table)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Examples:
|
14
|
+
# 1. Given the following products:
|
15
|
+
# Also supports namespaced models, (cnet) indicating the namespace Cnet
|
16
|
+
# 2. Given the following (cnet) products:
|
17
|
+
Given /^the following ((?:\([a-z ]+\) )?(?:[\w]+)):$/ do |type, table|
|
18
|
+
type = type.gsub(/^\(([a-z ]+)\) /, "\\1/").gsub(' ', '_').singularize
|
19
|
+
table.hashes.each do |attributes|
|
20
|
+
type = attributes.delete('type').underscore if attributes.key?('type')
|
21
|
+
attributes['site'] = site if type.classify.constantize.column_names.include?('site_id')
|
22
|
+
Factory(type, attributes)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Given /^a site with the following sections:$/ do |table|
|
27
|
+
Site.all.map(&:destroy)
|
28
|
+
@site = Factory(:site, :sections_attributes => [])
|
29
|
+
Given "the following sections:", table
|
30
|
+
end
|
31
|
+
|
32
|
+
Given /^a site with a (\w+) named "([^"]+)"$/ do |section, name|
|
33
|
+
Site.all.map(&:destroy)
|
34
|
+
@site = Factory(:site, :sections_attributes => [])
|
35
|
+
Given %(a #{section} named "#{name}")
|
36
|
+
end
|
37
|
+
|
38
|
+
# e.g. a blog named "Blog"
|
39
|
+
Given /^an? (\w+) (name|title)d "([^"]+)"$/ do |model, attribute, value|
|
40
|
+
model = model.classify.constantize
|
41
|
+
attributes = { attribute => value }
|
42
|
+
attributes[:site_id] = site.id if model.column_names.include?('site_id')
|
43
|
+
attributes[:account_id] = account.id if model.column_names.include?('account_id')
|
44
|
+
model.where(attributes).first || model.create!(attributes)
|
45
|
+
end
|
46
|
+
|
47
|
+
Given /^an? (\w+) with the following attributes:$/ do |model, table|
|
48
|
+
Factory(model, table.rows_hash)
|
49
|
+
end
|
50
|
+
|
51
|
+
# e.g. a post titled "Post" for the blog "Blog"
|
52
|
+
# e.g. a category named "Category" belonging to the blog "Blog"
|
53
|
+
Given /^an? (\w+) (name|title)d "([^"]+)" (?:for|belonging to) the (\w+) "([^"]+)"$/ do |model, attribute, value, section, name|
|
54
|
+
section = Given(%(a #{section} named "#{name}"))
|
55
|
+
collection = section.send(model.underscore.pluralize)
|
56
|
+
attributes = { attribute => value }
|
57
|
+
collection.where(attributes).first || collection.create!(attributes)
|
58
|
+
end
|
59
|
+
|
60
|
+
# e.g. a post with the title "Post" for the blog "Blog"
|
61
|
+
# e.g. a post with the title "Post" belonging to the blog "Blog"
|
62
|
+
Given /^an? (\w+) with the (\w+) "([^"]+)" (?:for|belonging to) the (\w+) "([^"]+)"$/ do |model, attribute, value, section, name|
|
63
|
+
section = Given(%(a #{section} named "#{name}"))
|
64
|
+
collection = section.send(model.underscore.pluralize)
|
65
|
+
attributes = { attribute => value }
|
66
|
+
collection.where(attributes).first || collection.create!(attributes)
|
67
|
+
end
|
68
|
+
|
69
|
+
Given /^(\w+)s with the following attributes:$/ do |model, table|
|
70
|
+
table.hashes.each do |attributes|
|
71
|
+
Factory(model, attributes)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
When /^(.+) that link$/ do |step|
|
76
|
+
raise "no last link" if @last_link.blank?
|
77
|
+
When %(#{step} "#{@last_link}")
|
78
|
+
end
|
79
|
+
|
80
|
+
When /^I (press|click) "(.*)" in the row (of the ([a-z ]+) table )?where "(.*)" is "(.*)"$/ do |press_or_click, link_or_button, _, table_id, header, cell_content|
|
81
|
+
body = Nokogiri::HTML(response.body)
|
82
|
+
table_xpath = table_id.nil? ? 'table' : "table[@id='#{table_id.gsub(/ /, '_')}']"
|
83
|
+
table_header_cells = body.xpath("//#{table_xpath}/descendant::th[normalize-space(text())='#{header}']/@id")
|
84
|
+
assert !table_header_cells.empty?, "could not find table header cell '#{header}'"
|
85
|
+
header_id = body.xpath("//#{table_xpath}/descendant::th[normalize-space(text())='#{header}']/@id").first.value
|
86
|
+
row_id = body.xpath("//#{table_xpath}/descendant::td[@headers='#{header_id}'][normalize-space(text())='#{cell_content}']/ancestor::tr/@id").first.value
|
87
|
+
within("##{row_id}") do
|
88
|
+
send({'press' => 'click_button', 'click' => 'click_link'}[press_or_click], link_or_button)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
When /^I click on the link from the email to (.*)$/ do |to|
|
93
|
+
email = ::ActionMailer::Base.deliveries.detect { |email| email.to.include?(to) }
|
94
|
+
assert email, "email to #{to} could not be found"
|
95
|
+
link = email.body.to_s =~ %r((http://[^\s"]+)) && $1
|
96
|
+
get link
|
97
|
+
end
|
98
|
+
|
99
|
+
Then /^there should be an? (\w+)$/ do |model|
|
100
|
+
assert @last_record = model.classify.constantize.first, "could not find any #{model}"
|
101
|
+
end
|
102
|
+
|
103
|
+
Then /^there should be an? (\w+) named "([^\"]+)"$/ do |model, name|
|
104
|
+
assert @last_record = model.classify.constantize.where(:name => name).first, "could not find any #{model} named #{name}"
|
105
|
+
end
|
106
|
+
|
107
|
+
Then /^there should not be an? (\w+) named "([^"]*)"$/ do |model, name|
|
108
|
+
assert !model.classify.constantize.where(:name => name).first, "expected no #{model} named #{name} exists, but found one"
|
109
|
+
end
|
110
|
+
|
111
|
+
Then /^there should be a (\w+) with the following attributes:$/ do |model, table|
|
112
|
+
assert @last_record = model.classify.constantize.where(table.rows_hash).first, "could not find a #{model} with #{table.rows_hash.inspect}"
|
113
|
+
end
|
114
|
+
|
115
|
+
Then /^there should be (\w+)s with the following attributes:$/ do |model, table|
|
116
|
+
table.hashes.each do |attributes|
|
117
|
+
assert model.classify.constantize.where(attributes).first, "could not find a #{model} with #{attributes.inspect}"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
Then /^that (\w+) should have an? (\w+) with the following attributes:$/ do |last, model, table|
|
122
|
+
assert @last_record.is_a?(last.classify.constantize), "wrong type for last #{last}"
|
123
|
+
assert @last_record.send(model.pluralize).where(table.rows_hash).first, "could not find a #{model} with #{table.rows_hash.inspect}"
|
124
|
+
end
|
125
|
+
|
126
|
+
Then /^that (\w+) should have (\w+)s with the following attributes:$/ do |last, model, table|
|
127
|
+
assert @last_record.is_a?(last.classify.constantize), "wrong type for last #{last}"
|
128
|
+
table.hashes.each do |attributes|
|
129
|
+
assert @last_record.send(model.pluralize).where(attributes).first, "could not find a #{model} with #{attributes.inspect}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
Then /^the title should be "([^"]+)"$/ do |title|
|
134
|
+
assert_select('title', title)
|
135
|
+
end
|
136
|
+
|
137
|
+
Then /^I should see a link "([^"]+)"$/ do |link|
|
138
|
+
@last_link = link
|
139
|
+
assert_select('a', link)
|
140
|
+
end
|
141
|
+
|
142
|
+
Then /^I should not see any (\w+)$/ do |type|
|
143
|
+
assert_select(".#{type.singularize}", :count => 0) # .#{type},
|
144
|
+
end
|
145
|
+
|
146
|
+
Then /^I should see an? (\w+)$/ do |type|
|
147
|
+
assert_select(".#{type}")
|
148
|
+
end
|
149
|
+
|
150
|
+
Then /^I should see an? (\w+) (?:titled|named) "([^"]+)"$/ do |type, text|
|
151
|
+
assert_select(".#{type} h2", text)
|
152
|
+
end
|
153
|
+
|
154
|
+
Then /^I should see an? (\w+) containing "([^"]+)"$/ do |type, text|
|
155
|
+
assert_select(".#{type}", /#{text}/)
|
156
|
+
end
|
157
|
+
|
158
|
+
Then /^I should see an? (\w+) list$/ do |type|
|
159
|
+
assert_select(".#{type}.list")
|
160
|
+
end
|
161
|
+
|
162
|
+
Then /^I should see a list of (\w+)$/ do |type|
|
163
|
+
assert_select(".#{type}.list")
|
164
|
+
end
|
165
|
+
|
166
|
+
Then /^I should see an? ([a-z ]+) form$/ do |type|
|
167
|
+
tokens = type.split(' ')
|
168
|
+
types = [tokens.join('_'), tokens.reverse.join('_')]
|
169
|
+
selectors = types.map { |type| "form.#{type}, form##{type}" }
|
170
|
+
assert_select(selectors.join(', '))
|
171
|
+
end
|
172
|
+
|
173
|
+
Then /^I should not see an? ([a-z ]+) form$/ do |type|
|
174
|
+
type = type.gsub(' ', '_') #.gsub(/edit_/, '')
|
175
|
+
assert_select("form.#{type}, form##{type}", :count => 0)
|
176
|
+
end
|
177
|
+
|
178
|
+
Then /^I should see an? ([a-z ]+) form with the following values:$/ do |type, table|
|
179
|
+
type = type.gsub(' ', '_') #.gsub(/edit_/, '')
|
180
|
+
assert_select("form.#{type}, form##{type}") do |form|
|
181
|
+
table.rows_hash.each do |name, value|
|
182
|
+
assert_equal value, webrat.current_scope.field_labeled(name).value
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
Then /^I should see a "(.+)" table with the following entries:$/ do |table_id, expected_table|
|
188
|
+
actual_table = table(tableish("table##{table_id} tr", 'td,th'))
|
189
|
+
begin
|
190
|
+
diff_table = expected_table.dup
|
191
|
+
diff_table.diff!(actual_table.dup)
|
192
|
+
rescue
|
193
|
+
puts "\nActual table:#{actual_table.to_s}\n"
|
194
|
+
puts "Expected table:#{expected_table.to_s}\n"
|
195
|
+
puts "Difference:#{diff_table.to_s}\n"
|
196
|
+
raise
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
Then /^I should see the "([^"]+)" page$/ do |name|
|
201
|
+
assert_select('h2', name)
|
202
|
+
end
|
203
|
+
|
204
|
+
Then(/(?:\$|eval) (.*)$/) do |code|
|
205
|
+
pp eval(code)
|
206
|
+
end
|
207
|
+
|
208
|
+
Then /^I should see a flash (error|notice|message) "(.+)"$/ do |message_type, message|
|
209
|
+
assert_match message, flash_cookie[message_type].to_s
|
210
|
+
end
|
211
|
+
|
212
|
+
Then /^I should not see a flash (error|notice) "(.+)"$/ do |message_type, message|
|
213
|
+
assert_no_match /message/, flash_cookie[message_type].to_s
|
214
|
+
end
|
215
|
+
|
216
|
+
Then /^I should (see|not see) the error "([^"]+)" for attribute "([^"]+)" of the "([^"]+)"$/ do |should_see, error_msg, attribute, model|
|
217
|
+
if should_see == 'see' # ugh ...
|
218
|
+
assert_select "*[id*=#{model.downcase.gsub(' ', '_')}_#{attribute.downcase.gsub(' ', '_')}] + span.error",
|
219
|
+
:text => error_msg
|
220
|
+
elsif should_see == 'not see'
|
221
|
+
assert_select "*[id*=#{model.downcase.gsub(' ', '_')}_#{attribute.downcase.gsub(' ', '_')}] + span.error",
|
222
|
+
:text => error_msg, :count => 0
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
Then /^the following emails should have been sent:$/ do |expected_emails|
|
227
|
+
expected_emails.hashes.each do |attributes|
|
228
|
+
assert_email_sent(attributes)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# Then /^I should see a "([^"]+)" table with the following entries:$/ do |table_id, expected_table|
|
233
|
+
# html_table = table(tableish("table##{table_id} tr", 'td,th'))
|
234
|
+
# expected_table.diff!(html_table)
|
235
|
+
# end
|
236
|
+
|
237
|
+
# TODO somehow merge this with what's in within_steps.rb
|
238
|
+
#
|
239
|
+
# Then I should see a comment within the sidebar
|
240
|
+
# Will look for '#sidebar .comment'
|
241
|
+
# Then I should see the cart within the sidebar
|
242
|
+
# Will look for '#sidebar #cart'
|
243
|
+
Then /^I should see (an?|the) ([a-z ]+) within the ([a-z ]+)$/ do |a_or_the, selector, context_selector|
|
244
|
+
within("##{context_selector}") do |context|
|
245
|
+
assert_select({'a' => '.', 'the' => '#'}[a_or_the]+selector)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
Then /^"([^"]*)" should be filled in with "([^"]*)"$/ do |field, value|
|
250
|
+
field = webrat.field_labeled(field)
|
251
|
+
assert_equal value, field.value
|
252
|
+
end
|
253
|
+
|
254
|
+
Then /^"([^"]*)" should be checked$/ do |label|
|
255
|
+
field = webrat.field_labeled(label)
|
256
|
+
assert field.checked?, "expected the checkbox #{label} to be checked"
|
257
|
+
end
|
258
|
+
|
259
|
+
Then /^"([^"]*)" should not be checked$/ do |label|
|
260
|
+
field = webrat.field_labeled(label)
|
261
|
+
assert !field.checked?, "expected the checkbox #{label} not to be checked"
|
262
|
+
end
|
263
|
+
|
264
|
+
Then /^"([^"]*)" should be selected as "([^"]*)"$/ do |value, label|
|
265
|
+
select = webrat.field_labeled(label)
|
266
|
+
assert select, "count not find a select field labeled #{label}"
|
267
|
+
selected = select.element.xpath(".//option[@selected = 'selected']").first
|
268
|
+
assert selected, "could not find a selected option"
|
269
|
+
assert_equal value, selected.text
|
270
|
+
end
|
271
|
+
|
272
|
+
Then /^I should see "([^"]*)" formatted as a "([^"]*)" tag$/ do |value, tag|
|
273
|
+
assert_select(tag, value)
|
274
|
+
end
|
275
|
+
|
276
|
+
Then "debug" do
|
277
|
+
debugger
|
278
|
+
true
|
279
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Then /^the menu should contain the following items:$/ do |menu|
|
2
|
+
menu.hashes.each do |item|
|
3
|
+
if item['url'].empty?
|
4
|
+
assert_select("#{item[:menu]} li h4", item['text'])
|
5
|
+
else
|
6
|
+
active = item[:active] == 'yes' ? '.active' : ':not(.active)'
|
7
|
+
url = item['url'].gsub('?', '\?').gsub('[', '\[').gsub(']', '\]').gsub(/\d+/, '[\d]*')
|
8
|
+
assert_select("#{item[:menu]} li#{active} a[href=?]", %r(#{url}), item['text'])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Given 'the routes are loaded' do
|
2
|
+
@routes = Rails.application.routes
|
3
|
+
end
|
4
|
+
|
5
|
+
Then 'the following routes should be recognized:' do |table|
|
6
|
+
table.hashes.each do |options|
|
7
|
+
method_and_path = options.slice('method', 'path')
|
8
|
+
expected_options = options.except('method', 'path', 'params')
|
9
|
+
expected_options.each { |name, value| expected_options.delete(name) if value.blank? }
|
10
|
+
|
11
|
+
options['params'].split(',').each do |param|
|
12
|
+
name, value = param.split(':').map(&:strip)
|
13
|
+
expected_options[name] = value
|
14
|
+
end if options['params']
|
15
|
+
|
16
|
+
assert_recognizes(expected_options.symbolize_keys, method_and_path.symbolize_keys)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# For date column cells named created_on, updated_at etc. this transforms the
|
2
|
+
# corresponding cell's value to a datetime in the current time zone (i.e. this
|
3
|
+
# works for both normal tables and row_hash tables):
|
4
|
+
timezonify = lambda do |table|
|
5
|
+
dates = table.headers.select { |header| header =~ /(_at|_on)$/ }
|
6
|
+
dates.each { |date| table.map_column!(date) { |date| DateTime.parse(date).in_time_zone } }
|
7
|
+
table.transpose
|
8
|
+
end
|
9
|
+
|
10
|
+
objectify = lambda do |table|
|
11
|
+
types = Section.types.map(&:underscore) << 'section' << 'site'
|
12
|
+
sections = table.headers.select { |header| types.include?(header) }
|
13
|
+
sections.each { |key| table.map_column!(key) { |value| key.gsub('_id', '').classify.constantize.find_by_name(value) } }
|
14
|
+
table.transpose
|
15
|
+
end
|
16
|
+
|
17
|
+
foreign_keyify = lambda do |table|
|
18
|
+
types = Section.types.map(&:underscore) << 'section' << 'site'
|
19
|
+
keys = types.map { |type| "#{type}_id" }
|
20
|
+
keys = table.headers.select { |header| keys.include?(header) }
|
21
|
+
keys.each { |key| table.map_column!(key) { |value| key.gsub('_id', '').classify.constantize.find_by_name(value).try(:id).to_s } }
|
22
|
+
table.transpose
|
23
|
+
end
|
24
|
+
|
25
|
+
# FIXME must be here because one apparently can't register multiple transforms for the
|
26
|
+
# same regex (like /^table:/) in cucumber. should really be in adva-categories though.
|
27
|
+
categoryify = lambda do |table|
|
28
|
+
if table.headers.include?('categories')
|
29
|
+
table.map_column!('categories') do |categories|
|
30
|
+
names = categories.split(',').map(&:strip)
|
31
|
+
Category.where(:name => names).all
|
32
|
+
end
|
33
|
+
end
|
34
|
+
table.transpose
|
35
|
+
end
|
36
|
+
|
37
|
+
Transform /^table:/ do |table|
|
38
|
+
table = timezonify.call(timezonify.call(table))
|
39
|
+
table = objectify.call(objectify.call(table))
|
40
|
+
table = foreign_keyify.call(foreign_keyify.call(table))
|
41
|
+
table = categoryify.call(categoryify.call(table))
|
42
|
+
table
|
43
|
+
end
|