card 1.93.3 → 1.93.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/db/migrate/20170908114452_increase_text_size_for_delayed_jobs.rb +9 -0
  4. data/db/migrate_core_cards/data/cards/*header +2 -2
  5. data/lib/card/format/nest.rb +12 -5
  6. data/lib/card/format/nest/fetch.rb +1 -2
  7. data/lib/card/format/render.rb +2 -2
  8. data/lib/card/model/save_helper.rb +1 -1
  9. data/lib/card/set/format/haml_views.rb +7 -3
  10. data/lib/card/subcards.rb +27 -228
  11. data/lib/card/subcards/add.rb +121 -0
  12. data/lib/card/subcards/relate.rb +27 -0
  13. data/lib/card/subcards/remove.rb +42 -0
  14. data/lib/card/tasks/card/create.rake +35 -132
  15. data/lib/card/tasks/card/file_card_creator.rb +25 -0
  16. data/lib/card/tasks/card/file_card_creator/abstract_file_card.rb +44 -0
  17. data/lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb +49 -0
  18. data/lib/card/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb +30 -0
  19. data/lib/card/tasks/card/file_card_creator/abstract_file_card/source_file.rb +36 -0
  20. data/lib/card/tasks/card/file_card_creator/haml_card.rb +42 -0
  21. data/lib/card/tasks/card/file_card_creator/output_helper.rb +50 -0
  22. data/lib/card/tasks/card/file_card_creator/script_card.rb +33 -0
  23. data/lib/card/tasks/card/file_card_creator/style_card.rb +25 -0
  24. data/lib/generators/card/template/template_generator.rb +1 -1
  25. data/mod/account/set/self/account_links.rb +1 -1
  26. data/mod/basic_formats/set/all/all_csv.rb +63 -0
  27. data/mod/basic_formats/set/all/json.rb +4 -1
  28. data/mod/bootstrap/db/migrate_cards/20170719163733_update_bootswatch_themes_to_4_beta.rb +5 -2
  29. data/mod/carrierwave/set/abstract/attachment.rb +1 -2
  30. data/mod/core/set/abstract/haml_file.rb +20 -0
  31. data/mod/core/set/all/chunk.rb +125 -0
  32. data/mod/core/set/all/collection.rb +2 -351
  33. data/mod/core/set/all/content.rb +26 -7
  34. data/mod/core/set/all/extended.rb +45 -0
  35. data/mod/core/set/all/haml.rb +3 -7
  36. data/mod/core/set/all/item.rb +92 -0
  37. data/mod/core/set/all/name.rb +36 -0
  38. data/mod/core/set/all/subcards.rb +21 -12
  39. data/mod/core/set/all/tabs.rb +50 -0
  40. data/mod/core/set/all/trash.rb +4 -0
  41. data/mod/core/spec/set/all/chunk_spec.rb +45 -0
  42. data/mod/core/spec/set/all/collection_spec.rb +6 -6
  43. data/mod/history/set/all/action_view.rb +1 -1
  44. data/mod/machines/lib/javascript/decko.js.coffee +3 -0
  45. data/mod/pointer/set/abstract/02_pointer/edit.rb +0 -2
  46. data/mod/search/set/abstract/search.rb +1 -1
  47. data/mod/search/set/all/filter.rb +0 -2
  48. data/mod/search/template/all/filter/_filter_input.haml +1 -1
  49. data/mod/search/template/all/filter/filter_form.haml +1 -1
  50. data/mod/standard/set/all/rich_html/editing.rb +1 -1
  51. data/mod/standard/set/all/rich_html/form.rb +6 -7
  52. data/mod/standard/set/all/rich_html/menu.rb +2 -3
  53. data/mod/standard/set/all/rich_html/toolbar.rb +3 -4
  54. data/mod/standard/set/type/cardtype.rb +1 -1
  55. data/mod/standard/spec/set/all/rich_html/editing_spec.rb +15 -4
  56. data/mod/tinymce_editor/db/migrate_cards/{20171113233150_update_tinymce_config.rb → 20171113233151_update_tinymce_config.rb} +1 -0
  57. metadata +25 -161
  58. data/.rspec +0 -4
  59. data/card.gemspec +0 -87
  60. data/db/seed/test/fixtures/.gitkeep +0 -0
  61. data/mod/bootstrap/vendor/bootstrap/.babelrc.js +0 -16
  62. data/mod/bootstrap/vendor/bootstrap/.editorconfig +0 -17
  63. data/mod/bootstrap/vendor/bootstrap/.eslintignore +0 -3
  64. data/mod/bootstrap/vendor/bootstrap/.gitattributes +0 -16
  65. data/mod/bootstrap/vendor/bootstrap/.github/CONTRIBUTING.md +0 -252
  66. data/mod/bootstrap/vendor/bootstrap/.github/ISSUE_TEMPLATE.md +0 -22
  67. data/mod/bootstrap/vendor/bootstrap/.gitignore +0 -46
  68. data/mod/bootstrap/vendor/bootstrap/.hound.yml +0 -19
  69. data/mod/bootstrap/vendor/bootstrap/.houndignore +0 -4
  70. data/mod/bootstrap/vendor/bootstrap/.travis.yml +0 -32
  71. data/mod/bootstrap/vendor/bootstrap/build/.htmllintrc +0 -19
  72. data/mod/bootstrap/vendor/bootstrap/build/.stylelintrc +0 -248
  73. data/mod/bootstrap/vendor/bootstrap/docs/4.0/examples/.stylelintrc +0 -12
  74. data/mod/bootstrap/vendor/bootstrap/js/.eslintrc.json +0 -240
  75. data/mod/bootstrap/vendor/bootstrap/js/tests/.eslintrc.json +0 -46
  76. data/mod/bootstrap/vendor/bootswatch/.gitignore +0 -7
  77. data/mod/bootstrap/vendor/bootswatch/.npmignore +0 -12
  78. data/mod/bootstrap/vendor/bootswatch/.travis.yml +0 -21
  79. data/mod/bootstrap/vendor/bootswatch/docs/.nojekyll +0 -0
  80. data/mod/bootstrap/vendor/bootswatch/docs/2/.travis.yml +0 -15
  81. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/.bower.json +0 -20
  82. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/.gitignore +0 -37
  83. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/.travis.yml +0 -3
  84. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/js/.jshintrc +0 -12
  85. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/jquery/.bower.json +0 -20
  86. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/jquery/.gitignore +0 -1
  87. data/mod/bootstrap/vendor/bootswatch/docs/2/swatchmaker/.gitignore +0 -1
  88. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap-sass-official/.bower.json +0 -45
  89. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/.bower.json +0 -44
  90. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/grunt/.jshintrc +0 -7
  91. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/js/.jscsrc +0 -42
  92. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/js/.jshintrc +0 -15
  93. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/less/.csscomb.json +0 -304
  94. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/less/.csslintrc +0 -19
  95. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/font-awesome/.bower.json +0 -14
  96. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/font-awesome/.gitignore +0 -32
  97. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/html5shiv/.bower.json +0 -25
  98. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/jquery/.bower.json +0 -38
  99. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/respond/.bower.json +0 -20
  100. data/mod/bootstrap/vendor/select2/.editorconfig +0 -6
  101. data/mod/bootstrap/vendor/select2/.github/CONTRIBUTING.md +0 -204
  102. data/mod/bootstrap/vendor/select2/.github/ISSUE_TEMPLATE.md +0 -46
  103. data/mod/bootstrap/vendor/select2/.github/PULL_REQUEST_TEMPLATE.md +0 -13
  104. data/mod/bootstrap/vendor/select2/.gitignore +0 -3
  105. data/mod/bootstrap/vendor/select2/.jshintignore +0 -4
  106. data/mod/bootstrap/vendor/select2/.jshintrc +0 -25
  107. data/mod/bootstrap/vendor/select2/.travis.yml +0 -22
  108. data/script/fetch_bootswatch_themes.rb +0 -38
  109. data/spec/config/initializers/core_extensions_spec.rb +0 -47
  110. data/spec/config/initializers/patches/active_job_spec.rb +0 -7
  111. data/spec/lib/card/action_spec.rb +0 -15
  112. data/spec/lib/card/auth_spec.rb +0 -58
  113. data/spec/lib/card/cache_spec.rb +0 -116
  114. data/spec/lib/card/chunk_spec.rb +0 -18
  115. data/spec/lib/card/codename_spec.rb +0 -66
  116. data/spec/lib/card/content_spec.rb +0 -428
  117. data/spec/lib/card/diff_spec.rb +0 -208
  118. data/spec/lib/card/format/nest_spec.rb +0 -13
  119. data/spec/lib/card/format/render_spec.rb +0 -26
  120. data/spec/lib/card/format_spec.rb +0 -117
  121. data/spec/lib/card/i18n_spec.rb +0 -24
  122. data/spec/lib/card/loader/Modfile +0 -2
  123. data/spec/lib/card/loader_spec.rb +0 -98
  124. data/spec/lib/card/migration/import_spec.rb +0 -80
  125. data/spec/lib/card/mod/loader/mod_dirs.rb +0 -8
  126. data/spec/lib/card/mod/loader/set_loader_spec.rb +0 -19
  127. data/spec/lib/card/mod/loader/set_pattern_loader_spec.rb +0 -19
  128. data/spec/lib/card/name/fields_and_traits_spec.rb +0 -18
  129. data/spec/lib/card/name_spec.rb +0 -70
  130. data/spec/lib/card/query/sorting_spec.rb +0 -68
  131. data/spec/lib/card/query_spec.rb +0 -574
  132. data/spec/lib/card/reference_spec.rb +0 -212
  133. data/spec/lib/card/set/event_spec.rb +0 -22
  134. data/spec/lib/card/set/trait_spec.rb +0 -80
  135. data/spec/lib/card/set_pattern_spec.rb +0 -59
  136. data/spec/lib/card/set_spec.rb +0 -89
  137. data/spec/lib/card/stage_director_spec.rb +0 -482
  138. data/spec/lib/card/subcards_spec.rb +0 -177
  139. data/spec/lib/card/success_spec.rb +0 -148
  140. data/spec/lib/card/view_cache_spec.rb +0 -27
  141. data/spec/mailers/mailer_spec.rb +0 -62
  142. data/spec/models/card/create_spec.rb +0 -119
  143. data/spec/models/card/trash_spec.rb +0 -189
  144. data/spec/models/card_spec.rb +0 -136
  145. data/spec/spec_helper.rb +0 -45
  146. data/spec/support/card_spec_helper.rb +0 -74
  147. data/spec/support/card_spec_loader.rb +0 -112
  148. data/spec/support/helper/card_helper.rb +0 -58
  149. data/spec/support/helper/event_helper.rb +0 -94
  150. data/spec/support/helper/render_helper.rb +0 -44
  151. data/spec/support/helper/save_helper.rb +0 -30
  152. data/spec/support/helper/set_helper.rb +0 -80
  153. data/spec/support/matchers/card_matchers.rb +0 -160
  154. data/spec/support/matchers/expectations.rb +0 -5
  155. data/spec/support/matchers/file_matchers.rb +0 -71
  156. data/spec/support/matchers/html_matchers.rb +0 -29
  157. data/spec/support/matchers/negated_matchers.rb +0 -2
  158. data/spec/support/simplecov_helper.rb +0 -70
  159. data/spec/support/test_mods/mod1/set/all/test_set.rb +0 -3
  160. data/spec/support/test_mods/mod2/set_pattern/test_pattern.rb +0 -0
@@ -1,58 +0,0 @@
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
- end
57
- end
58
- end
@@ -1,94 +0,0 @@
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::Fetch
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
-
79
- # Turn delayed jobs on and run jobs after the given block.
80
- # If count is given check if it matches the number of created jobs.
81
- def with_delayed_jobs count=nil
82
- Delayed::Worker.delay_jobs = true
83
- expect(Delayed::Job.count).to eq(0), "expected delayed job to start with an empty queue"
84
- yield
85
- if count
86
- expect(Delayed::Job.count).to eq(count)
87
- end
88
- Delayed::Worker.new.work_off
89
- expect(Delayed::Job.count).to eq(0), "not all delayed jobs were executed"
90
- Delayed::Worker.delay_jobs = false
91
- end
92
- end
93
- end
94
- end
@@ -1,44 +0,0 @@
1
- class Card
2
- module SpecHelper
3
- module RenderHelper
4
- def view view_name, card: { name: "test card", type: :basic }, format: :html
5
- render_card_with_args view_name, card, format: format
6
- end
7
-
8
- def render_editor type
9
- card = Card.create(name: "my favority #{type} + #{rand(4)}", type: type)
10
- card.format.render!(:edit)
11
- end
12
-
13
- def render_content content, format_args={}
14
- render_content_with_args content, format_args
15
- end
16
-
17
- def render_content_with_args content, format_args={}, view_args={}
18
- @card ||= Card.new name: "Tempo Rary 2"
19
- @card.content = content
20
- @card.format(format_args)._render :core, view_args
21
- end
22
-
23
- def render_card view, card_args={}, format_args={}
24
- render_card_with_args view, card_args, format_args
25
- end
26
-
27
- alias_method :render_view, :render_card
28
-
29
- def render_card_with_args view, card_args={}, format_args={}, view_args={}
30
- card =
31
- if card_args.is_a?(Card)
32
- card_args
33
- elsif card_args.is_a?(Symbol) || card_args.is_a?(String)
34
- Card.fetch card_args
35
- elsif card_args[:name]
36
- Card.fetch card_args[:name], new: card_args
37
- else
38
- Card.new card_args.merge(name: "Tempo Rary")
39
- end
40
- card.format(format_args)._render(view, view_args)
41
- end
42
- end
43
- end
44
- end
@@ -1,30 +0,0 @@
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 update! name_or_args, content_or_args={}
22
- update_card name_or_args, content_or_args
23
- end
24
-
25
- def delete name
26
- Card::Auth.as_bot { Card[name].delete! }
27
- end
28
- end
29
- end
30
- end
@@ -1,80 +0,0 @@
1
- class Card
2
- module SpecHelper
3
- # To be included in Card.
4
- # Defines helper to change card sets and formats
5
- module SetHelper
6
- # define dynamically views (or other things) on format objects
7
- # @return format object
8
- # @example add a view to a card's html format
9
- # format =
10
- # Card["A"].format_with(:html) do
11
- # view :my_test_view do
12
- # card.name
13
- # end
14
- # end
15
- # format.render :my_test_view # => "A"
16
- def format_with format_type=:html, &block
17
- dynamic_set =
18
- create_dynamic_set do
19
- format(format_type, &block)
20
- end
21
- format_with_set dynamic_set, format_type
22
- #::Card::Set::Self::DynamicSet, :html
23
- end
24
-
25
- # define dynamically sets on card objects
26
- # @return card object
27
- def set_with &block
28
- with_set create_dynamic_set(&block)
29
- end
30
-
31
- # load set into card object
32
- def with_set set
33
- set = include_set_in_test_set(set) if set.abstract_set?
34
- singleton_class.send :include, set
35
- yield set if block_given?
36
- self
37
- end
38
-
39
- # load set into a card's format object
40
- def format_with_set set, format_type=:base
41
- format = format format_type
42
- with_set set do |extended_set|
43
- format_class = set_format_class(extended_set, format_type)
44
- format.singleton_class.send :include, format_class
45
- end
46
- block_given? ? yield(format) : format
47
- end
48
-
49
- def set_format_class set, format_type
50
- format_class = Card::Format.format_class_name format_type
51
- set.const_get format_class
52
- end
53
-
54
- def include_set_in_test_set set
55
- # rubocop:disable Lint/Eval
56
- ::Card::Set::Self.const_remove_if_defined :TestSet
57
- eval <<-RUBY
58
- class ::Card::Set::Self
59
- module TestSet
60
- extend Card::Set
61
- include_set #{set}
62
- end
63
- end
64
- RUBY
65
- ::Card::Set::Self::TestSet
66
- # rubocop:enable Lint/Eval
67
- end
68
-
69
- private
70
-
71
- def create_dynamic_set &block
72
- ::Card::Set::Self.const_remove_if_defined :DynamicSet
73
- ::Card::Set::Self.const_set :DynamicSet, Module.new
74
- ::Card::Set::Self::DynamicSet.extend Card::Set
75
- ::Card::Set::Self::DynamicSet.module_eval &block
76
- ::Card::Set::Self::DynamicSet
77
- end
78
- end
79
- end
80
- end
@@ -1,160 +0,0 @@
1
- #TODO: is this global namespace? module?
2
- def expect_card *marks
3
- expect Card.cardish(marks)
4
- end
5
-
6
- RSpec::Matchers.define :exist do
7
- match do |card|
8
- should_be_true =
9
- case card
10
- when String
11
- Card.exists? card
12
- when Card
13
- card.real?
14
- else
15
- card.present?
16
- end
17
- values_match? true, should_be_true
18
- end
19
-
20
- failure_message do |actual|
21
- case actual
22
- when String
23
- "card '#{actual}' doesn't exist"
24
- when Card
25
- "#{actual.name} doesn't exist"
26
- else
27
- "#{actual} doesn't exist"
28
- end
29
- end
30
- end
31
-
32
- RSpec::Matchers.define :be_valid do
33
- match do |card|
34
- values_match?(true, card.errors.empty?)
35
- end
36
- end
37
-
38
- [:name, :codename, :db_content, :type_id].each do |field|
39
- RSpec::Matchers.define "have_#{field}".to_sym do |name|
40
- match do |card|
41
- values_match?(name, card.send(field))
42
- end
43
-
44
- failure_message do |card|
45
- super() + ", but was #{card.send(field)}"
46
- end
47
- end
48
- end
49
-
50
- RSpec::Matchers.define :have_a_field do |field_key|
51
- chain(:with_content) do |content|
52
- @content = content
53
- end
54
-
55
- chain(:pointing_to) do |pointing_to|
56
- @pointing_to = pointing_to
57
- end
58
-
59
- match do |card|
60
- return unless card.is_a?(Card)
61
- return unless (@field = card.fetch(trait: field_key))
62
- if @content
63
- values_match?(@content, @field.content)
64
- elsif @pointing_to
65
- values_match?(:pointer, @field.type_code) &&
66
- @field.content.include?("[[#{@pointing_to}]]")
67
- else
68
- values_match(Card, @field.class)
69
- end
70
- end
71
-
72
- failure_message do |card|
73
- return super() unless @field
74
- if @content
75
- "expected #{card} to have a field '#{field_key}' with content '#{@content}',
76
- but content is #{@field.content.present? ? @field.content : "empty" }"
77
- elsif @pointing_to
78
- "expected #{card} to have a field #{field_key} pointing to #{@pointing_to} but
79
- content is #{@field.content}"
80
- end
81
- end
82
- end
83
-
84
- RSpec::Matchers.define :have_type do |type|
85
- match do |card|
86
- case type
87
- when Symbol
88
- values_match?(type, card.type_code)
89
- when Integer
90
- values_match?(type, card.type_id)
91
- when String
92
- values_match?(type, card.type_name)
93
- end
94
- end
95
- end
96
-
97
- RSpec::Matchers.define :have_content do |content|
98
- match do |card|
99
- values_match?(content, card.content)
100
- end
101
- end
102
-
103
- RSpec::Matchers.define :increase_card_count do
104
- chain(:by) do |diff|
105
- @diff = diff
106
- end
107
-
108
- match do |card_creation|
109
- count = Card.count
110
- card_creation.call
111
- if @diff
112
- values_match?(count + @diff, Card.count)
113
- else
114
- Card.count > count
115
- end
116
- end
117
-
118
- supports_block_expectations
119
- end
120
-
121
- RSpec::Matchers.define :be_a_new_card do
122
- match do |card|
123
- card.is_a?(Card) && card.new_record?
124
- end
125
- end
126
-
127
- RSpec::Matchers.define :be_invalid do
128
- match do |card|
129
- # valid? clears errors
130
- # For a new card we have to call valid? to create the errors.
131
- # For a updated card we have to check errors because with valid? we would
132
- # loose the errors.
133
- @valid = card.errors.empty? && card.valid?
134
- # card.errors returns an array, hence we need an extra include matcher
135
- values_match?(false, @valid) &&
136
- values_match?(include(@error_msg), card.errors[@error_key])
137
- end
138
-
139
- description do
140
- "be invalid #{"because of #{@error_key} #{@error_msg}" if @error_key}"
141
- end
142
-
143
- chain(:because_of) do |reason|
144
- @error_key, @error_msg = reason.to_a.first
145
- end
146
-
147
- failure_message do |actual|
148
- super() + fail_reason(actual)
149
- end
150
-
151
- def fail_reason actual
152
- if @valid
153
- "but file is valid"
154
- else
155
- "but it is invalid because of #{actual.errors.messages}"
156
- end
157
- end
158
- end
159
-
160
-