card 1.19.4 → 1.19.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/01_core_extensions/module.rb +4 -0
  4. data/lib/card.rb +2 -2
  5. data/lib/card/content/diff/lcs.rb +1 -1
  6. data/lib/card/model/save_helper.rb +100 -25
  7. data/lib/card/name.rb +8 -0
  8. data/lib/card/set/event.rb +22 -42
  9. data/lib/card/set/format.rb +1 -0
  10. data/lib/card/set/inheritance.rb +30 -5
  11. data/lib/card/set/loader.rb +24 -3
  12. data/mod/account/set/self/account_links.rb +45 -21
  13. data/mod/account/set/self/signin.rb +5 -9
  14. data/mod/account/set/type/signup.rb +22 -15
  15. data/mod/account/spec/set/all/account_spec.rb +3 -1
  16. data/mod/admin/set/self/admin.rb +4 -4
  17. data/mod/admin/set/self/admin_info.rb +3 -9
  18. data/mod/admin/set/self/trash.rb +21 -14
  19. data/mod/basic_formats/set/all/base.rb +6 -7
  20. data/mod/bootstrap/set/all/bootstrap/helper.rb +4 -5
  21. data/mod/bootstrap/set/all/bootstrap/tabs.rb +3 -4
  22. data/mod/bootstrap/spec/set/all/bootstrap/form_spec.rb +2 -0
  23. data/mod/carrierwave/set/abstract/attachment/storage_type.rb +3 -0
  24. data/mod/core/chunk/link.rb +3 -3
  25. data/mod/core/chunk/uri.rb +2 -2
  26. data/mod/core/set/all/actify.rb +11 -10
  27. data/mod/core/set/all/permissions.rb +6 -7
  28. data/mod/core/spec/set/all/actify_spec.rb +2 -0
  29. data/mod/developer/set/right/debug.rb +1 -1
  30. data/mod/email/set/all/follow.rb +2 -1
  31. data/mod/email/set/right/follow.rb +19 -22
  32. data/mod/email/set/type_plus_right/user/follow.rb +1 -1
  33. data/mod/email/spec/set/all/notify_spec.rb +17 -14
  34. data/mod/history/set/all/history.rb +35 -38
  35. data/mod/machines/spec/set/abstract/machine_spec.rb +2 -0
  36. data/mod/settings/set/abstract/permission.rb +6 -9
  37. data/mod/settings/set/type/setting.rb +4 -3
  38. data/mod/solid_cache/set/abstract/solid_cache.rb +41 -20
  39. data/mod/solid_cache/spec/set/abstract/solid_cache_spec.rb +3 -1
  40. data/mod/standard/set/all/error.rb +14 -19
  41. data/mod/standard/set/all/links.rb +149 -120
  42. data/mod/standard/set/all/rich_html/content.rb +9 -19
  43. data/mod/standard/set/all/rich_html/header.rb +3 -5
  44. data/mod/standard/set/all/rich_html/menu.rb +25 -23
  45. data/mod/standard/set/all/rich_html/modal.rb +11 -9
  46. data/mod/standard/set/all/rich_html/toolbar.rb +85 -84
  47. data/mod/standard/set/rstar/rules_editor.rb +96 -79
  48. data/mod/standard/set/type/cardtype.rb +2 -1
  49. data/mod/standard/set/type/search_type.rb +2 -1
  50. data/mod/standard/set/type/set.rb +15 -19
  51. data/mod/standard/set/type/uri.rb +2 -2
  52. data/mod/standard/spec/set/all/links_spec.rb +8 -5
  53. data/spec/config/initializers/core_extensions_spec.rb +2 -0
  54. data/spec/lib/card/format/nest_spec.rb +2 -0
  55. data/spec/lib/card/migration/import_spec.rb +2 -0
  56. data/spec/lib/card/set/trait_spec.rb +2 -0
  57. data/spec/lib/card/stage_director_spec.rb +2 -0
  58. data/spec/lib/card/view_cache_spec.rb +2 -0
  59. data/spec/spec_helper.rb +11 -139
  60. data/spec/support/card_spec_helper.rb +61 -0
  61. data/spec/support/card_spec_loader.rb +83 -0
  62. data/spec/support/helper/card_helper.rb +87 -0
  63. data/spec/support/helper/event_helper.rb +80 -0
  64. data/spec/support/helper/render_helper.rb +35 -0
  65. data/spec/support/helper/save_helper.rb +26 -0
  66. data/{config → spec/support}/simplecov_helper.rb +1 -1
  67. metadata +16 -5
  68. data/spec/card_spec_helper.rb +0 -137
@@ -0,0 +1,61 @@
1
+ helper_path = File.expand_path "../helper/*.rb", __FILE__
2
+ Dir[helper_path].each { |f| require f }
3
+
4
+ class Card
5
+ # to be included in RSpec::Core::ExampleGroup
6
+ module SpecHelper
7
+ include RenderHelper
8
+ include EventHelper
9
+ include SaveHelper
10
+
11
+ # ~~~~~~~~~ HELPER METHODS ~~~~~~~~~~~~~~~#
12
+ include Rails::Dom::Testing::Assertions::SelectorAssertions
13
+
14
+ def login_as user
15
+ Card::Auth.current_id = (uc = Card[user.to_s]) && uc.id
16
+ return unless @request
17
+ @request.session[:user] = Card::Auth.current_id
18
+ # warn "(ath)login_as #{user.inspect}, #{Card::Auth.current_id}, "\
19
+ # "#{@request.session[:user]}"
20
+ end
21
+
22
+ def assert_view_select view_html, *args, &block
23
+ node = Nokogiri::HTML::Document.parse(view_html).root
24
+ if block_given?
25
+ assert_select node, *args, &block
26
+ else
27
+ assert_select node, *args
28
+ end
29
+ end
30
+
31
+ def debug_assert_view_select view_html, *args, &block
32
+ Rails.logger.rspec <<-HTML
33
+ #{CodeRay.scan(Nokogiri::XML(view_html, &:noblanks).to_s, :html).div}
34
+ <style>
35
+ .CodeRay {
36
+ background-color: #FFF;
37
+ border: 1px solid #CCC;
38
+ padding: 1em 0px 1em 1em;
39
+ }
40
+ .CodeRay .code pre { overflow: auto }
41
+ </style>
42
+ HTML
43
+ assert_view_select view_html, *args, &block
44
+ end
45
+
46
+ def users
47
+ SharedData::USERS.sort
48
+ end
49
+
50
+ def bucket_credentials key
51
+ @buckets ||= bucket_credentials_from_yml_file || {}
52
+ @buckets[key]
53
+ end
54
+
55
+ def bucket_credentials_from_yml_file
56
+ yml_file = ENV["BUCKET_CREDENTIALS_PATH"] ||
57
+ File.expand_path("../bucket_credentials.yml", __FILE__)
58
+ File.exist?(yml_file) && YAML.load_file(yml_file).deep_symbolize_keys
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,83 @@
1
+ class CardSpecLoader
2
+ class << self
3
+ def init
4
+ require "spork"
5
+ ENV["RAILS_ENV"] = "test"
6
+ require "timecop"
7
+ end
8
+
9
+ def prefork
10
+ Spork.prefork do
11
+ unless ENV["RAILS_ROOT"]
12
+ raise Card::Error, "No RAILS_ROOT given. Can't load environment."
13
+ end
14
+ require File.join ENV["RAILS_ROOT"], "config/environment"
15
+ load_shared_examples
16
+ require File.expand_path("../simplecov_helper.rb", __FILE__)
17
+
18
+ # Requires supporting ruby files with custom matchers and macros, etc,
19
+ # in spec/support/ and its subdirectories.
20
+ # Dir[File.join(Cardio.gem_root, "spec/support/**/*.rb")].each do |f|
21
+ # require f
22
+ # end
23
+ yield if block_given?
24
+ end
25
+ end
26
+
27
+ def each_run
28
+ # This code will be run each time you run your specs.
29
+ yield if block_given?
30
+ end
31
+
32
+ def rspec_config
33
+ require "rspec/rails"
34
+
35
+ @@joe_user_id = Card["joe_user"].id
36
+ RSpec.configure do |config|
37
+ config.include RSpec::Rails::Matchers::RoutingMatchers,
38
+ file_path: %r{\bspec/controllers/}
39
+ config.include RSpecHtmlMatchers
40
+ # format_index = ARGV.find_index {|arg| arg =~ /--format|-f/ }
41
+ # formatter = format_index ? ARGV[ format_index + 1 ] : 'documentation'
42
+ # config.default_formatter=formatter
43
+
44
+ config.infer_spec_type_from_file_location!
45
+ # config.include CustomMatchers
46
+ # config.include ControllerMacros, type: :controllers
47
+
48
+ # == Mock Framework
49
+ # If you prefer to mock with mocha, flexmock or RR,
50
+ # uncomment the appropriate symbol:
51
+ # :mocha, :flexmock, :rr
52
+
53
+ config.use_transactional_fixtures = true
54
+ config.use_instantiated_fixtures = false
55
+
56
+ config.before(:each) do
57
+ Delayed::Worker.delay_jobs = false
58
+ Card::Auth.current_id = @@joe_user_id
59
+ Card::Cache.restore
60
+ Card::Env.reset
61
+ end
62
+
63
+ config.after(:each) do
64
+ Timecop.return
65
+ end
66
+ yield config if block_given?
67
+ end
68
+ end
69
+
70
+ def helper
71
+ require File.expand_path "../card_spec_helper.rb", __FILE__
72
+ RSpec::Core::ExampleGroup.send :include, Card::SpecHelper
73
+ Card.send :include, Card::SpecHelper::CardHelper
74
+ Card.send :extend, Card::SpecHelper::CardHelper::ClassMethods
75
+ end
76
+
77
+ def load_shared_examples
78
+ Card::Mod::Loader.mod_dirs.each "spec/shared_examples" do |shared_ex_dir|
79
+ Dir["#{shared_ex_dir}/**/*.rb"].sort.each { |f| require f }
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,87 @@
1
+ class Card
2
+ module SpecHelper
3
+ # to be included in Card
4
+ module CardHelper
5
+ module ClassMethods
6
+ def gimme! name, args={}
7
+ Card::Auth.as_bot do
8
+ c = Card.fetch(name, new: args)
9
+ c.putty args
10
+ Card.fetch name
11
+ end
12
+ end
13
+
14
+ def gimme name, args={}
15
+ Card::Auth.as_bot do
16
+ c = Card.fetch(name, new: args)
17
+ if args[:content] && c.content != args[:content]
18
+ c.putty args
19
+ c = Card.fetch name
20
+ end
21
+ c
22
+ end
23
+ end
24
+
25
+ cattr_accessor :rspec_binding
26
+ end
27
+
28
+ def putty args={}
29
+ Card::Auth.as_bot do
30
+ if args.present?
31
+ update_attributes! args
32
+ else
33
+ save!
34
+ end
35
+ end
36
+ end
37
+
38
+ # rubocop:disable Lint/Eval
39
+ def method_missing m, *args, &block
40
+ return super unless Card.rspec_binding
41
+ suppress_name_error do
42
+ method = eval("method(%s)" % m.inspect, Card.rspec_binding)
43
+ return method.call(*args, &block)
44
+ end
45
+ suppress_name_error do
46
+ return eval(m.to_s, Card.rspec_binding)
47
+ end
48
+ super
49
+ end
50
+ # rubocop:enable Lint/Eval
51
+
52
+ def suppress_name_error
53
+ yield
54
+ rescue NameError
55
+ end
56
+
57
+ def format_with_set set, format_type=:base
58
+ set = include_set_in_test_set(set) if set.abstract_set?
59
+
60
+ singleton_class.send :include, set
61
+ format = format format_type
62
+ format.singleton_class.send :include, set_format_class(set, format_type)
63
+ yield format
64
+ end
65
+
66
+ def set_format_class set, format_type
67
+ format_class = Card::Format.format_class_name format_type
68
+ set.const_get format_class
69
+ end
70
+
71
+ def include_set_in_test_set set
72
+ # rubocop:disable Lint/Eval
73
+ ::Card::Set::Self.const_remove_if_defined :TestSet
74
+ eval <<-RUBY
75
+ class ::Card::Set::Self
76
+ module TestSet
77
+ extend Card::Set
78
+ include_set #{set}
79
+ end
80
+ end
81
+ RUBY
82
+ ::Card::Set::Self::TestSet
83
+ # rubocop:enable Lint/Eval
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,80 @@
1
+ class Card
2
+ module SpecHelper
3
+ module EventHelper
4
+ # Make expectations in the event phase.
5
+ # Takes a stage and registers the event_block in this stage as an event.
6
+ # Unknown methods in the event_block are executed in the rspec context
7
+ # instead of the card's context.
8
+ # An additionally :trigger block in opts is expected that is called
9
+ # to start the event phase.
10
+ # You can restrict the event to a specific card by passing a name
11
+ # with :for options.
12
+ # That's for example necessary if you create a card in a event.
13
+ # Otherwise you get a loop of card creations.
14
+ # @example
15
+ # in_stage :initialize,
16
+ # for: "my test card",
17
+ # trigger: -> { test_card.update_attributes! content: '' } do
18
+ # expect(item_names).to eq []
19
+ # end
20
+ def in_stage stage, opts={}, &event_block
21
+ Card.rspec_binding = binding
22
+ add_test_event stage, :in_stage_test, opts, &event_block
23
+ trigger =
24
+ if opts[:trigger].is_a?(Symbol)
25
+ method(opts[:trigger])
26
+ else
27
+ opts[:trigger]
28
+ end
29
+ trigger.call
30
+ ensure
31
+ remove_test_event stage, :in_stage_test
32
+ end
33
+
34
+ # if you need more then one test event (otherwise use #in_stage)
35
+ # @example
36
+ # with_test_events do
37
+ # test_event :store, for: "my card" do
38
+ # Card.create name: "other card"
39
+ # end
40
+ # test_event :finalize, for: "other card" do
41
+ # expect(content).to be_empty
42
+ # end
43
+ # end
44
+ def with_test_events
45
+ @events = []
46
+ Card.rspec_binding = binding
47
+ yield
48
+ ensure
49
+ @events.each do |stage, name|
50
+ remove_test_event stage, name
51
+ end
52
+ Card.rspec_binding = false
53
+ end
54
+
55
+ def test_event stage, opts={}, &block
56
+ event_name = :"test_event_#{@events.size}"
57
+ @events << [stage, event_name]
58
+ add_test_event stage, event_name, opts, &block
59
+ end
60
+
61
+ def add_test_event stage, name, opts={}, &event_block
62
+ # use random set module that is always included so that the
63
+ # event applies to all cards
64
+ opts[:set] ||= Card::Set::All::Event
65
+ if (only_for_card = opts.delete(:for))
66
+ opts[:when] = proc { |c| c.name == only_for_card }
67
+ end
68
+ Card.class_eval do
69
+ extend Card::Set::Event
70
+ event name, stage, opts, &event_block
71
+ end
72
+ end
73
+
74
+ def remove_test_event stage, name
75
+ stage_sym = :"#{stage}_stage"
76
+ Card.skip_callback stage_sym, :after, name
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,35 @@
1
+ class Card
2
+ module SpecHelper
3
+ module RenderHelper
4
+ def render_editor type
5
+ card = Card.create(name: "my favority #{type} + #{rand(4)}", type: type)
6
+ card.format.render(:edit)
7
+ end
8
+
9
+ def render_content content, format_args={}
10
+ render_content_with_args content, format_args
11
+ end
12
+
13
+ def render_content_with_args content, format_args={}, view_args={}
14
+ @card ||= Card.new name: "Tempo Rary 2"
15
+ @card.content = content
16
+ @card.format(format_args)._render :core, view_args
17
+ end
18
+
19
+ def render_card view, card_args={}, format_args={}
20
+ render_card_with_args view, card_args, format_args
21
+ end
22
+
23
+ def render_card_with_args view, card_args={}, format_args={}, view_args={}
24
+ card = begin
25
+ if card_args[:name]
26
+ Card.fetch card_args[:name], new: card_args
27
+ else
28
+ Card.new card_args.merge(name: "Tempo Rary")
29
+ end
30
+ end
31
+ card.format(format_args)._render(view, view_args)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ class Card
2
+ module SpecHelper
3
+ module SaveHelper
4
+ include Card::Model::SaveHelper
5
+ def create! name, content=""
6
+ Card.create! name: name, content: content
7
+ end
8
+
9
+ def create name_or_args, content_or_args=nil
10
+ Card::Auth.as_bot { super }
11
+ end
12
+
13
+ def create_or_update name_or_args, content_or_args=nil
14
+ Card::Auth.as_bot { super }
15
+ end
16
+
17
+ def update name_or_args, content_or_args={}
18
+ Card::Auth.as_bot { super }
19
+ end
20
+
21
+ def delete name
22
+ Card::Auth.as_bot { Card[name].delete! }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -48,7 +48,7 @@ end
48
48
  def card_core_dev_simplecov_filters
49
49
  filters.clear # This will remove the :root_filter that comes via simplecov's defaults
50
50
  add_filter do |src|
51
- !(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /card/
51
+ !(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /card|wagn/
52
52
  end
53
53
 
54
54
  add_filter "/spec/"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.4
4
+ version: 1.19.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-09-14 00:00:00.000000000 Z
14
+ date: 2016-09-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: smartname
@@ -254,7 +254,6 @@ files:
254
254
  - config/initializers/uuid_state_file.rb
255
255
  - config/locales/de.yml
256
256
  - config/locales/en.yml
257
- - config/simplecov_helper.rb
258
257
  - db/migrate/20110511221913_require_earlier_migrations.rb
259
258
  - db/migrate/20120105203350_require_1_8_migrations.rb
260
259
  - db/migrate/20121111025347_require_1_10_migrations.rb
@@ -1089,7 +1088,6 @@ files:
1089
1088
  - mod/tinymce_editor/set/abstract/tinymce_editor.rb
1090
1089
  - mod/tinymce_editor/set/self/script_tinymce.rb
1091
1090
  - mod/tinymce_editor/set/self/script_tinymce_config.rb
1092
- - spec/card_spec_helper.rb
1093
1091
  - spec/config/initializers/core_extensions_spec.rb
1094
1092
  - spec/lib/card/action_spec.rb
1095
1093
  - spec/lib/card/auth_spec.rb
@@ -1123,6 +1121,13 @@ files:
1123
1121
  - spec/models/card/validation_spec.rb
1124
1122
  - spec/models/card_spec.rb
1125
1123
  - spec/spec_helper.rb
1124
+ - spec/support/card_spec_helper.rb
1125
+ - spec/support/card_spec_loader.rb
1126
+ - spec/support/helper/card_helper.rb
1127
+ - spec/support/helper/event_helper.rb
1128
+ - spec/support/helper/render_helper.rb
1129
+ - spec/support/helper/save_helper.rb
1130
+ - spec/support/simplecov_helper.rb
1126
1131
  - tmpsets/set/mod001-core/abstract/code_file.rb
1127
1132
  - tmpsets/set/mod001-core/all/actify.rb
1128
1133
  - tmpsets/set/mod001-core/all/active_card.rb
@@ -1354,7 +1359,6 @@ signing_key:
1354
1359
  specification_version: 4
1355
1360
  summary: an atomic, set-driven content engine
1356
1361
  test_files:
1357
- - spec/card_spec_helper.rb
1358
1362
  - spec/config/initializers/core_extensions_spec.rb
1359
1363
  - spec/lib/card/action_spec.rb
1360
1364
  - spec/lib/card/auth_spec.rb
@@ -1388,3 +1392,10 @@ test_files:
1388
1392
  - spec/models/card/validation_spec.rb
1389
1393
  - spec/models/card_spec.rb
1390
1394
  - spec/spec_helper.rb
1395
+ - spec/support/card_spec_helper.rb
1396
+ - spec/support/card_spec_loader.rb
1397
+ - spec/support/helper/card_helper.rb
1398
+ - spec/support/helper/event_helper.rb
1399
+ - spec/support/helper/render_helper.rb
1400
+ - spec/support/helper/save_helper.rb
1401
+ - spec/support/simplecov_helper.rb