adva-core 0.0.9 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/app/models/section.rb +0 -6
  2. data/app/views/admin/sites/index.html.rb +2 -2
  3. data/config/redirects.rb +2 -1
  4. data/lib/adva.rb +41 -0
  5. data/lib/adva/controller/internal_redirect.rb +2 -1
  6. data/lib/adva/core.rb +8 -0
  7. data/lib/adva/engine.rb +1 -0
  8. data/lib/adva/generators/app.rb +7 -8
  9. data/lib/adva/generators/templates/app/Gemfile +4 -4
  10. data/lib/adva/generators/templates/app/Thorfile +9 -0
  11. data/lib/adva/generators/templates/app/app_template.rb +4 -2
  12. data/lib/adva/generators/templates/engine/Gemfile.erb +15 -0
  13. data/lib/adva/testing.rb +9 -2
  14. data/lib/adva/testing/engine.rb +1 -0
  15. data/lib/adva/view/form.rb +4 -1
  16. data/lib/adva_core/version.rb +1 -1
  17. data/lib/bundler/repository.rb +117 -0
  18. data/lib/patches/inherited_resources.rb +4 -3
  19. data/lib/patches/rails/integretion_runner_respond_to.rb +1 -1
  20. data/lib/patches/rails/polymorphic_url_for.rb +3 -1
  21. data/lib/patches/rails/recognize_path_env.rb +33 -29
  22. data/lib/patches/rails/route_set_to_param.rb +19 -17
  23. data/lib/patches/rails/route_set_trailing_segment.rb +1 -1
  24. data/lib/patches/rails/sti_associations.rb +10 -4
  25. data/lib/patches/rails/translation_helper.rb +2 -1
  26. data/lib/patches/responders/flash_responder.rb +1 -0
  27. data/lib/patches/simple_form.rb +2 -2
  28. data/lib/testing/env.rb +19 -13
  29. data/lib/testing/factories.rb +5 -1
  30. data/lib/testing/paths.rb +4 -4
  31. data/lib/testing/selectors.rb +72 -0
  32. data/lib/testing/step_definitions/capybara_steps.rb +211 -0
  33. data/lib/testing/step_definitions/common_steps.rb +87 -98
  34. data/lib/testing/step_definitions/debug_steps.rb +11 -4
  35. data/lib/testing/step_definitions/email_steps.rb +195 -0
  36. data/lib/testing/step_definitions/menu_steps.rb +7 -2
  37. data/lib/testing/step_definitions/more_web_steps.rb +4 -0
  38. data/lib/testing/step_definitions/pickle_steps.rb +104 -0
  39. data/lib/testing/step_definitions/transforms.rb +10 -1
  40. data/lib/testing/support/pickle.rb +24 -0
  41. data/public/javascripts/adva-core/jquery/jquery.table_tree.js +5 -1
  42. metadata +340 -305
  43. data/lib/patches/rails/asset_expansion_multiple_registrations.rb +0 -21
  44. data/lib/patches/rails/template_resolver_caching.rb +0 -9
  45. data/lib/patches/webrat/links-data-method.rb +0 -15
  46. data/lib/patches/webrat/logger.rb +0 -14
  47. data/lib/patches/webrat/upload_file.rb +0 -23
  48. data/lib/patches/webrat/within_xpath.rb +0 -13
  49. data/lib/testing/step_definitions/webrat_steps.rb +0 -284
  50. data/lib/testing/step_definitions/within_steps.rb +0 -16
@@ -40,10 +40,4 @@ class Section < ActiveRecord::Base
40
40
  default << 'id' unless self.class.primary_key.eql? 'id'
41
41
  default
42
42
  end
43
-
44
- protected
45
-
46
- def _path
47
- read_attribute(:path)
48
- end
49
43
  end
@@ -1,14 +1,14 @@
1
1
  class Admin::Sites::Index < Minimal::Template
2
2
  include do
3
3
  def to_html
4
- table_for collection do |t|
4
+ table_for collection.all do |t|
5
5
  t.column :site
6
6
  t.column :actions, :class => :actions
7
7
 
8
8
  t.row do |r, site|
9
9
  r.cell link_to_site(site)
10
10
  r.cell links_to_actions([:view, :edit, :destroy], site)
11
- end unless collection.empty?
11
+ end unless collection.count == 0
12
12
  end
13
13
  end
14
14
 
@@ -4,5 +4,6 @@ Adva::Registry.set :redirect, {
4
4
 
5
5
  'admin/sites#update' => lambda { |c| c.edit_url },
6
6
  'admin/pages#update' => lambda { |c| c.show_url },
7
- 'admin/pages#destroy' => lambda { |c| c.index_url }
7
+ 'admin/pages#destroy' => lambda { |c| c.index_url },
8
+ 'admin/sections#destroy' => lambda { |c| c.index_url }
8
9
  }
@@ -34,6 +34,47 @@ module Adva
34
34
  engine_names.include?(name)
35
35
  end
36
36
  alias :installed? :engine?
37
+
38
+ # Helps you slice and dice your addons to adva-cms
39
+ #
40
+ # load and slice (patch) the class +Existing::Stuff+
41
+ # in 'ur/engine/existing/stuff_slice.rb'
42
+ # Adva.slice 'existing/stuff' do
43
+ # include do
44
+ # def fn0rd
45
+ # 23 + 42
46
+ # end
47
+ # end
48
+ # attr_accessor :things
49
+ # end
50
+ def slice(path_with_namespace, &block)
51
+ raise ArgumentError, 'must give block to slice and dice' unless block_given?
52
+ if path_with_namespace =~ /^([^#]+)#([^#]+)$/
53
+ path, namespace = $1, $2
54
+ else
55
+ raise ArgumentError, "first argument must be class_to_slice#your_slice_identifier"
56
+ end
57
+ unless loaded_slices.include?(path_with_namespace)
58
+ class_name = path.sub(/\.\w+$/,'').pluralize.classify # cut out extension for minimal templates
59
+ begin
60
+ class_name.constantize.class_eval(&block)
61
+ rescue NameError => e
62
+ if e.message.include?(class_name)
63
+ require_dependency(path)
64
+ else
65
+ raise e
66
+ end
67
+ ensure
68
+ loaded_slices << path_with_namespace
69
+ end
70
+ else
71
+ Rails.logger.debug { "Adva.slice: already loaded #{path_with_namespace}, skipping" }
72
+ end
73
+ end
74
+
75
+ def loaded_slices
76
+ @loaded_slices ||= Set.new
77
+ end
37
78
  end
38
79
  end
39
80
 
@@ -13,6 +13,7 @@ module Adva
13
13
  params = yield(params) if block_given?
14
14
 
15
15
  rack_endpoint = "#{controller}_controller".classify.constantize.action(action)
16
+ Rails.logger.debug { "redirecting internally to #{controller}##{action}" }
16
17
  env['action_dispatch.request.parameters'] = params
17
18
  response = rack_endpoint.call(env)
18
19
 
@@ -23,4 +24,4 @@ module Adva
23
24
  end
24
25
  end
25
26
  end
26
- end
27
+ end
@@ -90,5 +90,13 @@ module Adva
90
90
  adva-core/admin/lists )
91
91
  )
92
92
  end
93
+
94
+ if Rails.env.development?
95
+ initializer 'adva-core.schedule_slice_clearing' do
96
+ config.to_prepare do
97
+ Adva.loaded_slices.clear
98
+ end
99
+ end
100
+ end
93
101
  end
94
102
  end
@@ -1,5 +1,6 @@
1
1
  # Common behaviour that we want included in all adva engines
2
2
 
3
+ require 'active_support/concern'
3
4
  module Adva
4
5
  module Engine
5
6
  extend ActiveSupport::Concern
@@ -11,7 +11,7 @@ module Adva
11
11
  module Generators
12
12
  class App
13
13
  DEFAULT_OPTIONS = {
14
- :source => File.expand_path('../../../../..', __FILE__),
14
+ :core_dir => File.expand_path('../../../..', __FILE__),
15
15
  :target => File.expand_path('.'),
16
16
  :template => File.expand_path('../templates/app/app_template.rb', __FILE__),
17
17
  :engines => [:all],
@@ -21,13 +21,13 @@ module Adva
21
21
  :force => false
22
22
  }
23
23
 
24
- def initialize(name, options = {}, &block)
24
+ def initialize(name, options = {})
25
25
  @options = options.reverse_merge!(DEFAULT_OPTIONS)
26
- @name = name || File.basename(source)
27
- raise ArgumentError, "#{source.inspect} is not a directory" unless File.directory?(source)
26
+ @name = name || File.basename( File.expand_path('../', core_dir) )
27
+ raise ArgumentError, "#{core_dir.inspect} is not a directory" unless File.directory?(core_dir)
28
28
  end
29
29
 
30
- def invoke
30
+ def invoke(&block)
31
31
  if force? || build?
32
32
  build
33
33
  generate_resources if generate_resources?
@@ -44,7 +44,7 @@ module Adva
44
44
  protected
45
45
 
46
46
  attr_reader :name
47
- option_reader :source, :target, :template, :engines, :resources, :migrate, :bundle, :force
47
+ option_reader :core_dir, :target, :template, :engines, :resources, :migrate, :bundle, :force
48
48
 
49
49
  def root
50
50
  "#{target}/#{name}"
@@ -57,8 +57,7 @@ module Adva
57
57
  options = force? || ENV.key?('REGENERATE_APP') ? ['-f'] : []
58
58
  generator = Rails::Generators::AppGenerator.new([root], options, :shell => shell)
59
59
  generator.invoke_all
60
- generator.apply(template, :source => Pathname.new(source))
61
- FileUtils.cp("#{source}/Thorfile", "#{root}/Thorfile")
60
+ generator.apply(template, :adva_core => Pathname.new(core_dir))
62
61
  end
63
62
  end
64
63
 
@@ -10,15 +10,15 @@ gem 'adva-markup'
10
10
 
11
11
  group :test do
12
12
  gem 'sqlite3-ruby', '1.2.5'
13
- gem 'cucumber', '0.9.4'
14
- gem 'cucumber-rails', '0.3.2'
15
- gem 'webrat', '0.7.2'
13
+ gem "capybara", ">= 0.4.1.1"
14
+ gem 'cucumber', '~> 0.10.2'
15
+ gem 'cucumber-rails', '~> 0.4.1'
16
16
  gem 'thor'
17
17
  gem 'ruby-debug'
18
18
  gem 'mocha'
19
19
  gem 'fakefs', :require => 'fakefs/safe'
20
20
  gem 'test_declarative'
21
- gem 'database_cleaner', '0.5.2'
21
+ gem 'database_cleaner', ' ~> 0.6.7'
22
22
  gem 'launchy'
23
23
  gem 'factory_girl', '1.3.2'
24
24
  end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup
5
+ Bundler.require(:default)
6
+
7
+ $0 = 'thor'
8
+
9
+ Adva.engines.each { |engine| engine.new.load_tasks }
@@ -1,3 +1,5 @@
1
- copy_file config[:source].join('lib/bundler/repository.rb'), "#{app_path}/lib/bundler/repository.rb"
2
- copy_file config[:source].join('adva-core/lib/adva/generators/templates/app/Gemfile'), "#{app_path}/Gemfile"
1
+ copy_file config[:adva_core].join('lib/bundler/repository.rb'), "#{app_path}/lib/bundler/repository.rb"
2
+ copy_file config[:adva_core].join('lib/adva/generators/templates/app/Thorfile'), "#{app_path}/Thorfile"
3
+ remove_file 'Gemfile' # we do not want to confirm overwriting the Gemfile
4
+ copy_file config[:adva_core].join('lib/adva/generators/templates/app/Gemfile'), "#{app_path}/Gemfile"
3
5
  remove_file 'public/index.html'
@@ -1,3 +1,18 @@
1
1
  source :rubygems
2
2
 
3
3
  gemspec
4
+
5
+ group :test do
6
+ gem 'sqlite3-ruby', '1.2.5'
7
+ gem "capybara", ">= 0.4.1.1"
8
+ gem 'cucumber', '~> 0.10.2'
9
+ gem 'cucumber-rails', '~> 0.4.1'
10
+ gem 'thor'
11
+ gem 'ruby-debug'
12
+ gem 'mocha'
13
+ gem 'fakefs', :require => 'fakefs/safe'
14
+ gem 'test_declarative'
15
+ gem 'database_cleaner', ' ~> 0.6.7'
16
+ gem 'launchy'
17
+ gem 'factory_girl', '1.3.2'
18
+ end
@@ -6,6 +6,10 @@ module Adva
6
6
 
7
7
  class << self
8
8
  def setup(options = {})
9
+ options = {
10
+ :migrate => true
11
+ }.merge(options)
12
+
9
13
  Adva.out = StringIO.new('')
10
14
  setup_logging(options)
11
15
  setup_active_record
@@ -14,7 +18,10 @@ module Adva
14
18
  ActiveSupport::Slices.register
15
19
 
16
20
  each_engine { |e| e.new.require_patches }
17
- each_engine { |e| e.migrate }
21
+
22
+ if options[:migrate]
23
+ each_engine { |e| e.migrate }
24
+ end
18
25
 
19
26
  load_assertions
20
27
  load_factories
@@ -43,7 +50,7 @@ module Adva
43
50
  def setup_logging(options)
44
51
  if log = options[:log]
45
52
  FileUtils.touch(log) unless File.exists?(log)
46
- ActiveRecord::Base.logger = Logger.new(log)
53
+ Rails.logger = Logger.new(log)
47
54
  ActiveRecord::LogSubscriber.attach_to(:active_record)
48
55
  end
49
56
  end
@@ -19,6 +19,7 @@ module Adva
19
19
  end
20
20
 
21
21
  def load_cucumber_support
22
+ load_all('lib/testing/support')
22
23
  load_all('lib/testing/step_definitions')
23
24
  load_all('lib/testing/paths')
24
25
  end
@@ -37,7 +37,10 @@ module Adva
37
37
  end
38
38
 
39
39
  def pass_return_to
40
- hidden_field_tag :return_to, params[:return_to]
40
+ hidden_field_tag :return_to, params[:return_to] if params[:return_to].present?
41
+ end
42
+
43
+ def fields
41
44
  end
42
45
  end
43
46
  end
@@ -1,3 +1,3 @@
1
1
  module AdvaCore
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -0,0 +1,117 @@
1
+ require 'pathname'
2
+
3
+ # Bundler gemfile support for local/remote workspaces/repositories for work in
4
+ # development teams.
5
+ #
6
+ # Usage:
7
+ #
8
+ # # define paths to be searched for repositories:
9
+ # workspace '~/.projects ~/Development/{projects,work}'
10
+ #
11
+ # # define developer preferences for using local or remote repositories (uses ENV['user']):
12
+ # developer :sven, :prefer => :local
13
+ #
14
+ # # define repositories to be used for particular gems:
15
+ # adva_cms = repository('adva-cms2', :git => 'git@github.com:svenfuchs/adva-cms2.git', :ref => 'c2af0de')
16
+ # adva_shop = repository('adva-shop', :source => :local)
17
+ #
18
+ # # now use repositories to define gems:
19
+ # adva_cms.gem 'adva-core'
20
+ # adva_shop.gem 'adva-catalog'
21
+ #
22
+ # # The gem definition will now be proxied to Bundler with arguments according
23
+ # # to the setup defined earlier. E.g. as:
24
+ #
25
+ # gem 'adva-core', :path => 'Development/projects/adva-cms2' # for developer 'sven'
26
+ # gem 'adva-core', :git => 'git@github.com:svenfuchs/adva-cms2.git', :ref => 'c2af0de' # for other developers
27
+ # gem 'adva-catalog', :path => 'Development/projects/adva-shop' # for all developers
28
+ #
29
+ # One can also set an environment variable FORCE_REMOTE which will force remote
30
+ # repositories to be used *except* when a repository was defined with :source => :local
31
+ # which always forces the local repository to be used.
32
+ #
33
+ class Repository
34
+ class << self
35
+ def paths
36
+ @paths ||= []
37
+ end
38
+
39
+ def path(*paths)
40
+ paths.join(' ').split(' ').each do |path|
41
+ self.paths.concat(Pathname.glob(File.expand_path(path)))
42
+ end
43
+ end
44
+
45
+ def developer(name, preferences)
46
+ developers[name] = preferences
47
+ workspaces(preferences[:workspace])
48
+ end
49
+
50
+ def current_developer
51
+ developers[ENV['USER'].to_sym] || {}
52
+ end
53
+
54
+ def developers(developers = nil)
55
+ @developers ||= {}
56
+ end
57
+ end
58
+
59
+ class Gem < Array
60
+ def initialize(name, repository)
61
+ if repository.local?
62
+ super([name, { :path => repository.path.to_s }])
63
+ else
64
+ super([name, repository.options.dup])
65
+ end
66
+ end
67
+ end
68
+
69
+ attr_reader :bundler, :name, :options, :source
70
+
71
+ def initialize(bundler, name, options)
72
+ @bundler = bundler
73
+ @name = name
74
+ @source = options.delete(:source)
75
+ @options = options
76
+ end
77
+
78
+ def gem(name)
79
+ bundler.gem(*Gem.new(name, self))
80
+ end
81
+
82
+ def local?
83
+ source == :local # && path
84
+ end
85
+
86
+ def source
87
+ @source ||= forced_source || preferred_source || :remote
88
+ end
89
+
90
+ def forced_source
91
+ :remote if ENV['FORCE_REMOTE']
92
+ end
93
+
94
+ def preferred_source
95
+ self.class.current_developer[:prefer] || self.class.current_developer[name.to_sym]
96
+ end
97
+
98
+ def path
99
+ @path ||= begin
100
+ path = self.class.paths.detect { |path| path.join(name).exist? }
101
+ path ? path.join(name) : Pathname.new('.')
102
+ end
103
+ end
104
+ end
105
+
106
+ def workspace(*paths)
107
+ Repository.path(*paths)
108
+ end
109
+ alias :workspaces :workspace
110
+
111
+ def developer(name, preferences)
112
+ Repository.developer(name, preferences)
113
+ end
114
+
115
+ def repository(*args)
116
+ Repository.new(self, *args)
117
+ end
@@ -1,7 +1,9 @@
1
1
  require 'gem-patching'
2
2
  require 'inherited_resources'
3
3
 
4
- Gem.patching('inherited_resources', '1.1.2') do
4
+ # FIXME is any of this still neccessary?
5
+
6
+ Gem.patching('inherited_resources', '1.2.2') do
5
7
  InheritedResources::Actions.module_eval do
6
8
  module Actions
7
9
  def index(options={}, &block)
@@ -15,14 +17,13 @@ Gem.patching('inherited_resources', '1.1.2') do
15
17
  def collection
16
18
  get_collection_ivar || begin
17
19
  collection = end_of_association_chain
18
- collection = collection.find(:all) unless collection.respond_to?(:each)
19
20
  set_collection_ivar(collection)
20
21
  end
21
22
  end
22
23
 
23
24
  def build_resource
24
25
  get_resource_ivar || begin
25
- resource = end_of_association_chain.send(method_for_build, params[resource_instance_name] || {})
26
+ resource = end_of_association_chain.send(method_for_build, resource_params)
26
27
  # check if resource is included to prevent deleting from a relation
27
28
  if method_for_build == :build && end_of_association_chain.include?(resource)
28
29
  end_of_association_chain.delete(resource)
@@ -4,7 +4,7 @@ require 'gem-patching'
4
4
  # respond_to? method. It thus doesn't respond_to? to named route url helpers even
5
5
  # though it actually responds to them. Happens with the PolymorphicRoutes patch
6
6
  # above, so this patch is here as well.
7
- Gem.patching('rails', '3.0.3') do
7
+ Gem.patching('rails', '3.0.9') do
8
8
  ActionDispatch::Integration::Runner.module_eval do
9
9
  def respond_to?(method, include_private = false)
10
10
  @integration_session.respond_to?(method, include_private) || super
@@ -1,7 +1,9 @@
1
1
  # Walks up the inheritance chain for given records if the generated named route
2
2
  # helper does not exist. Caches resulting method names.
3
3
  # see https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2986-polymorphic_url-should-handle-sti-better
4
- Gem.patching('rails', '3.0.3') do
4
+ #
5
+ # FIXME: this should not blindly overwrite ActionDispatch::Routing::PolymorphicRoutes.build_named_route_call
6
+ Gem.patching('rails', '3.0.9') do
5
7
  require 'action_dispatch/routing/polymorphic_routes'
6
8
 
7
9
  ActionDispatch::Routing::PolymorphicRoutes.module_eval do