card 1.101.3 → 1.101.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/02_patches/active_record.rb +1 -1
  4. data/config/locales/en.yml +155 -378
  5. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +1 -1
  6. data/lib/card.rb +15 -2
  7. data/lib/card/auth.rb +5 -2
  8. data/lib/card/auth/current.rb +39 -100
  9. data/lib/card/auth/proxy.rb +36 -16
  10. data/lib/card/auth/token.rb +6 -0
  11. data/lib/card/cache/all.rb +83 -0
  12. data/lib/card/cache/card_class.rb +41 -0
  13. data/lib/card/cache/persistent.rb +3 -34
  14. data/lib/card/cache/persistent_class.rb +28 -0
  15. data/lib/card/codename.rb +1 -1
  16. data/lib/card/content.rb +16 -2
  17. data/lib/card/content/all.rb +59 -0
  18. data/lib/card/director/act_direction.rb +4 -0
  19. data/lib/card/director/all.rb +61 -0
  20. data/lib/card/director/card_class.rb +18 -0
  21. data/lib/card/director/phases.rb +0 -1
  22. data/lib/card/dirty.rb +13 -3
  23. data/lib/card/env/success.rb +14 -14
  24. data/lib/card/env/success/target.rb +9 -11
  25. data/lib/card/error.rb +1 -1
  26. data/lib/card/fetch/all.rb +32 -0
  27. data/lib/card/fetch/card_class.rb +147 -0
  28. data/lib/card/format.rb +1 -1
  29. data/lib/card/format/error.rb +3 -3
  30. data/lib/card/format/nest.rb +1 -1
  31. data/lib/card/format/nest/fetch.rb +1 -1
  32. data/lib/card/lexicon.rb +2 -2
  33. data/lib/card/name/all.rb +8 -0
  34. data/lib/card/name/all/descendants.rb +6 -3
  35. data/lib/card/name/card_class.rb +26 -0
  36. data/lib/card/reference/all.rb +131 -0
  37. data/lib/card/rule/all.rb +75 -0
  38. data/lib/card/set/event/all.rb +95 -0
  39. data/lib/card/set/event/skip_and_trigger.rb +89 -0
  40. data/lib/card/set/pattern/all.rb +63 -0
  41. data/lib/card/subcards/all.rb +103 -0
  42. data/lib/cardio/migration/import.rb +1 -1
  43. data/lib/cardio/utils.rb +5 -3
  44. data/mod/admin/set/self/admin_info.rb +3 -5
  45. data/mod/admin/set/self/trash.rb +2 -2
  46. data/mod/core/set/all/autoname.rb +17 -0
  47. data/mod/core/set/all/codename.rb +2 -2
  48. data/mod/core/set/all/content.rb +52 -97
  49. data/mod/core/set/all/name_events.rb +69 -58
  50. data/mod/core/set/all/reference_events.rb +67 -0
  51. data/mod/core/set/all/states.rb +2 -2
  52. data/mod/core/set/all/subcards.rb +0 -100
  53. data/mod/core/set/all/trash.rb +11 -13
  54. data/mod/core/set/all/type.rb +7 -9
  55. data/mod/core/set/all/utils.rb +3 -0
  56. data/mod/core/set/type/cardtype.rb +3 -3
  57. data/mod/core/set_pattern/06_rule.rb +1 -1
  58. data/mod/core/spec/set/all/{rules2_spec.rb → clean_me_spec.rb} +0 -0
  59. data/mod/core/spec/set/all/name_events_spec.rb +204 -0
  60. metadata +30 -37
  61. data/lib/card/mod_inflector.rb +0 -16
  62. data/lib/card/name/all/class_methods.rb +0 -28
  63. data/mod/core/set/all/actify.rb +0 -68
  64. data/mod/core/set/all/cache.rb +0 -109
  65. data/mod/core/set/all/event_conditions.rb +0 -172
  66. data/mod/core/set/all/fetch.rb +0 -122
  67. data/mod/core/set/all/fetch_helper.rb +0 -35
  68. data/mod/core/set/all/i18n.rb +0 -9
  69. data/mod/core/set/all/pattern.rb +0 -54
  70. data/mod/core/set/all/references.rb +0 -191
  71. data/mod/core/set/all/rename.rb +0 -33
  72. data/mod/core/set/all/rules.rb +0 -81
  73. data/mod/core/spec/set/all/actify_spec.rb +0 -58
  74. data/mod/core/spec/set/all/content_spec.rb +0 -15
  75. data/mod/core/spec/set/all/event_conditions_spec.rb +0 -217
  76. data/mod/core/spec/set/all/fetch_helper_spec.rb +0 -65
  77. data/mod/core/spec/set/all/fetch_spec.rb +0 -338
  78. data/mod/core/spec/set/all/i18n_spec.rb +0 -17
  79. data/mod/core/spec/set/all/pattern_spec.rb +0 -101
  80. data/mod/core/spec/set/all/permissions/reader_rules_spec.rb +0 -166
  81. data/mod/core/spec/set/all/references_spec.rb +0 -62
  82. data/mod/core/spec/set/all/rename_spec.rb +0 -189
  83. data/mod/core/spec/set/all/rules_spec.rb +0 -100
  84. data/mod/core/spec/set/all/subcards_spec.rb +0 -102
@@ -1,15 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- describe Card::Set::All::Content do
4
- describe "save_content_draft" do
5
- it "stores a draft revision" do
6
- @card = Card.create! name: "mango", content: "foo"
7
- @card.save_content_draft("bar")
8
- expect(@card.drafts.length).to eq 1
9
- @card.save_content_draft("booboo")
10
- @card.reload
11
- expect(@card.drafts.length).to eq 1
12
- expect(@card.drafts[0].value(:db_content)).to eq "booboo"
13
- end
14
- end
15
- end
@@ -1,217 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- RSpec.describe Card::Set::All::EventConditions do
4
- let(:create_card) {Card.create!(name: "main card")}
5
- let(:create_card_with_subcards) do
6
- Card.create name: "main card",
7
- subcards: {
8
- "11" => { subcards: { "111" => "A" } },
9
- "12" => { subcards: { "121" => "A" } }
10
- }
11
- end
12
-
13
- context "restricted to changed content:" do
14
- STAGES = [:validate, :store, :finalize, :integrate]
15
-
16
- def add_to_log entry
17
- @log << entry
18
- end
19
-
20
- def change_content
21
- Card["A"].update! content: "changed content"
22
- end
23
-
24
- before do
25
- @log = []
26
- end
27
-
28
- it "is executed when content changed" do
29
- with_test_events do
30
- STAGES.each do |stage|
31
- test_event stage, on: :update, changed: :content, for: "A" do
32
- # can't access instance variables here but methods are fine
33
- add_to_log stage
34
- end
35
- end
36
- change_content
37
- expect(@log).to contain_exactly(*STAGES)
38
- end
39
- end
40
-
41
- specify "content change is accessible in all stages" do
42
- with_test_events do
43
- STAGES.each do |stage|
44
- test_event stage, on: :update, changed: :content, for: "A" do
45
- add_to_log db_content_before_act
46
- end
47
- end
48
- content_before_change = [Card["A"].db_content] * STAGES.size
49
- change_content
50
- expect(@log).to contain_exactly(*content_before_change)
51
- end
52
- end
53
-
54
- context "when changing type" do
55
- def update_type
56
- Card::Auth.as_bot do
57
- Card["Sample Pointer"].update! type: "Search"
58
- end
59
- end
60
-
61
- it "does NOT run update events from sets that no longer apply after change" do
62
- with_test_events do
63
- test_event :validate, on: :update, set: Card::Set::Type::Pointer do
64
- add_to_log "NO to run"
65
- end
66
- update_type
67
- expect(@log).to be_empty
68
- end
69
- end
70
-
71
- it "does run update events from old sets when `changing` value present" do
72
- with_test_events do
73
- test_event :validate,
74
- on: :update, set: Card::Set::Type::Pointer, changing: :type do
75
- add_to_log "YES to run"
76
- end
77
- update_type
78
- expect(@log).to contain_exactly("YES to run")
79
- end
80
- end
81
-
82
- it "does run update events from sets that apply after change" do
83
- with_test_events do
84
- test_event :validate, on: :update, set: Card::Set::Type::SearchType do
85
- add_to_log "YES to run"
86
- end
87
- update_type
88
- expect(@log).to contain_exactly("YES to run")
89
- end
90
- end
91
-
92
- # following does not yet work, because old card has both old sets and new sets
93
- # when conditions are tested.
94
- xit "does NOT run update events from new sets when `changing` value present" do
95
- with_test_events do
96
- test_event :validate,
97
- on: :update, set: Card::Set::Type::SearchType, changing: :type do
98
- add_to_log "NO to run"
99
- end
100
- update_type
101
- expect(@log).to be_empty
102
- end
103
- end
104
- end
105
-
106
- context "when changing name" do
107
- def update_name
108
- Card::Auth.as_bot do
109
- Card["Cardtype B+*type+*create"].update! name: "B+*update"
110
- end
111
- end
112
-
113
- it "does NOT run update events from sets that no longer apply after change" do
114
- with_test_events do
115
- test_event :validate, on: :update, set: Card::Set::Right::Create do
116
- add_to_log "NO to run"
117
- end
118
- update_name
119
- expect(@log).to be_empty
120
- end
121
- end
122
-
123
- it "does run update events from old sets when `changing` value present" do
124
- with_test_events do
125
- test_event :validate,
126
- on: :update, set: Card::Set::Right::Create, changing: :name do
127
- add_to_log "YES to run"
128
- end
129
- update_name
130
- expect(@log).to contain_exactly("YES to run")
131
- end
132
- end
133
-
134
- it "does run update events from sets that apply after change" do
135
- with_test_events do
136
- test_event :validate, on: :update, set: Card::Set::Right::Update do
137
- add_to_log "YES to run"
138
- end
139
- update_name
140
- expect(@log).to contain_exactly("YES to run")
141
- end
142
- end
143
- end
144
-
145
- describe "trigger option" do
146
- specify "trigger for whole act" do
147
- with_test_events do
148
- test_event :validate, on: :update, trigger: :required, for: "A" do
149
- add_to_log "triggered"
150
- end
151
- Card["A"].update! content: "changed content"
152
-
153
- aggregate_failures do
154
- expect(@log).to be_empty
155
- Card["A"].update! content: "changed content", trigger: :test_event_0
156
- expect(@log).to contain_exactly "triggered"
157
- end
158
- end
159
- end
160
- end
161
-
162
- describe "skip option" do
163
- def expect_skipping changes, log1, log2,
164
- for_name: nil, skip_key: :skip, allowed: :allowed, force: false
165
- with_test_events do
166
- add_logging_test_event allowed, for_name
167
- update_with_skip force, changes, skip_key
168
-
169
- aggregate_failures do
170
- expect(@log).to eq(log1) # logging with skip
171
- Card["A"].update! changes # update without skip
172
- expect(@log).to contain_exactly(*log2) # logging without skip
173
- end
174
- end
175
- end
176
-
177
- def add_logging_test_event allowed, for_name
178
- event_args = { on: :update, skip: allowed }
179
- event_args[:for] = for_name if for_name
180
- test_event(:validate, event_args) do
181
- add_to_log "#{name} executed"
182
- end
183
- end
184
-
185
- def update_with_skip force, changes, skip_key
186
- skip_card = Card["A"]
187
- if force
188
- skip_card.skip_event! :test_event_0
189
- skip_card.update! changes
190
- else
191
- skip_card.update! changes.merge(skip_key => :test_event_0)
192
- end
193
- end
194
-
195
- specify "skip condition" do
196
- expect_skipping({ content: "changed" }, [], "A executed", for_name: "A")
197
- end
198
-
199
- specify "skip condition in subcard" do
200
- expect_skipping({ content: "changed", subcards: { "+B" => "changed +B" } },
201
- [], "A+B executed", for_name: "A+B")
202
- end
203
-
204
- specify "skip_in_action condition" do
205
- expect_skipping({ content: "changed", subcards: { "+B" => "changed +B" } },
206
- ["A+B executed"],
207
- ["A executed", "A+B executed", "A+B executed"],
208
- skip_key: :skip_in_action)
209
- end
210
-
211
- specify "force skip" do
212
- expect_skipping({ content: "changed" }, [], "A executed",
213
- force: true, for_name: "A")
214
- end
215
- end
216
- end
217
- end
@@ -1,65 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- RSpec.describe Card::Set::All::FetchHelper do
4
- let(:retrieve) { test_retrieve_existing }
5
- let(:retrieve_from_trash) { test_retrieve_existing look_in_trash: true }
6
-
7
- def fetch_object opts={}
8
- if @fetch_object
9
- @fetch_object.opts.merge! opts
10
- @fetch_object
11
- else
12
- @fetch_object = Card::Fetch.new("A".to_name, opts)
13
- end
14
- end
15
-
16
- def test_retrieve_existing opts={}
17
- fetch_object(opts)&.retrieve_existing
18
- end
19
-
20
- describe "#controller fetch" do
21
- it "removes underscores from new card names" do
22
- expect(Card.controller_fetch(mark: "no_un_der_score").name).to eq("no un der score")
23
- end
24
- end
25
-
26
- describe "retrieve_existing" do
27
- it "looks for non-cached card in database" do
28
- # expect_db_retrieval_with(:key, "a", nil) { retrieve }
29
- expect_db_retrieval { retrieve }
30
- end
31
-
32
- it "doesn't look in db for cached cards(real)" do
33
- Card.cache.write "a", Card["B"]
34
- expect_no_db_retrieval { retrieve }
35
- end
36
-
37
- it "doesn't look in db for cached cards (new)" do
38
- Card.cache.write "a", Card.new
39
- expect_no_db_retrieval { retrieve }
40
- end
41
-
42
- it "doesn't look in db for cached cards (real) if 'look_in_trash' option used" do
43
- Card.cache.write "a", Card["B"]
44
- expect_no_db_retrieval { retrieve_from_trash }
45
- end
46
-
47
- it "looks in db for cached cards (new) if 'look_in_trash' option used" do
48
- Card.cache.write "a", Card.new
49
- # expect_db_retrieval_with(:key, "a", true) { retrieve_from_trash }
50
- expect_db_retrieval { retrieve_from_trash }
51
- end
52
-
53
- def expect_no_db_retrieval
54
- allow(fetch_object).to receive(:retrieve_from_db)
55
- yield
56
- expect(fetch_object).not_to have_received(:retrieve_from_db)
57
- end
58
-
59
- def expect_db_retrieval
60
- allow(fetch_object).to receive(:retrieve_from_db)
61
- yield
62
- expect(fetch_object).to have_received(:retrieve_from_db) # .with(*args)
63
- end
64
- end
65
- end
@@ -1,338 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- RSpec.describe Card::Set::All::Fetch do
4
- describe "#fetch" do
5
- it "returns and caches existing cards" do
6
- card_double = class_double("Card")
7
- expect(Card.fetch("A")).to be_instance_of(Card)
8
- expect(Card.cache.read("a")).to be_instance_of(Card)
9
- expect(card_double).not_to receive(:find_by_key)
10
- expect(Card.fetch("A")).to be_instance_of(Card)
11
- end
12
-
13
- it "returns nil and caches missing cards" do
14
- expect(Card.fetch("Zork")).to be_nil
15
- expect(Card.cache.read("zork").new_card?).to be_truthy
16
- expect(Card.fetch("Zork")).to be_nil
17
- end
18
-
19
- it "returns nil and caches trash cards" do
20
- Card::Auth.as_bot do
21
- card_double = class_double("Card")
22
- Card.fetch("A").delete!
23
- expect(Card.fetch("A")).to be_nil
24
- expect(card_double).not_to receive(:find_by_key_and_trash)
25
- expect(Card.fetch("A")).to be_nil
26
- end
27
- end
28
-
29
- it "returns and caches builtin cards" do
30
- expect(Card.fetch("*head")).to be_instance_of(Card)
31
- expect(Card.cache.read("*head")).not_to be_nil
32
- end
33
-
34
- it "returns virtual cards and caches them as missing" do
35
- Card::Auth.as_bot do
36
- card = Card.fetch("Joe User+*email")
37
- expect(card).to be_a(Card).and have_name "Joe User+*email"
38
- expect(card.format.render_raw).to eq("joe@user.com")
39
- end
40
- # card.content.should == 'joe@user.com'
41
- # cached_card = Card.cache.read('joe_user+*email')
42
- # cached_card.missing?.should be_true
43
- # cached_card.virtual?.should be_true
44
- end
45
-
46
- it "fetches virtual cards after skipping them" do
47
- expect(Card["A+*self"]).to be_nil
48
- expect(Card.fetch("A+*self")).not_to be_nil
49
- end
50
-
51
- it "fetches newly virtual cards", as_bot: true do
52
- expect(Card.fetch("A+virtual")).to be_nil
53
- create "virtual+*right+*structure"
54
- expect(Card.fetch("A+virtual")).not_to be_nil
55
- end
56
-
57
- it "fetches virtual set cards" do
58
- aself = Card.fetch("A+*self")
59
- Card::Cache.reset_all
60
- Card.fetch "A+*self"
61
-
62
- expect(aself.set_names).to include("Set+*type")
63
- end
64
-
65
- it "fetches structured cards" do
66
- Card::Auth.as_bot do
67
- Card.create! name: "y+*right+*structure", content: "Formatted Content"
68
- Card.create! name: "a+y", content: "DB Content"
69
- end
70
- card = Card.fetch("a+y")
71
- expect(card).to be_real.and have_content("Formatted Content").and have_db_content("DB Content")
72
- end
73
-
74
- it "handles name variants of cached cards" do
75
- expect(Card.fetch("yomama+*self").name).to eq("yomama+*self")
76
- expect(Card.fetch("YOMAMA+*self").name).to eq("YOMAMA+*self")
77
- expect(Card.fetch("yomama", new: {}).name).to eq("yomama")
78
- expect(Card.fetch("YOMAMA", new: {}).name).to eq("YOMAMA")
79
- expect(Card.fetch("yomama!", new: { name: "Yomama" }).name)
80
- .to eq("Yomama")
81
- end
82
-
83
- it "fetches junction of names" do
84
- card = Card.fetch "A", "B"
85
- expect(card).to be_instance_of(Card)
86
- expect(card.name).to eq "A+B"
87
- end
88
-
89
- it "fetches junction of string, id, and codename" do
90
- card = Card.fetch "Book", Card.fetch_id(:type), :structure
91
- expect(card).to be_instance_of(Card)
92
- expect(card.name).to eq "Book+*type+*structure"
93
- end
94
-
95
- it "fetches junction of name, card object, and codename" do
96
- card = Card.fetch "Book".to_name, Card.fetch(:type), :structure
97
- expect(card).to be_instance_of(Card)
98
- expect(card.name).to eq "Book+*type+*structure"
99
- end
100
-
101
- it "does not recurse infinitely on template templates" do
102
- expect(Card.fetch("*structure+*right+*structure")).to be_nil
103
- end
104
-
105
- it "expires card and dependencies on save" do
106
- # Card.cache.dump # should be empty
107
- Card.cache.soft.reset
108
- expect(Card.cache.soft.store.keys).to eq([])
109
-
110
- Card::Auth.as_bot do
111
- a = Card.fetch("A")
112
- expect(a).to be_instance_of(Card)
113
-
114
- # expires the saved card
115
- expect(a).to receive(:expire).and_call_original
116
- # expect().to receive(:delete).with('a#SUBCARDS#').and_call_original
117
- # expires plus cards
118
- # expect(Card.cache).to receive(:delete).with('c+a')
119
- # expect(Card.cache).to receive(:delete).with('d+a')
120
- # expect(Card.cache).to receive(:delete).with('f+a')
121
- # expect(Card.cache).to receive(:delete).with('a+b')
122
- # expect(Card.cache).to receive(:delete).with('a+c')
123
- # expect(Card.cache).to receive(:delete).with('a+d')
124
- # expect(Card.cache).to receive(:delete).with('a+e')
125
- # expect(Card.cache).to receive(:delete).with('a+b+c')
126
-
127
- # expired including? cards
128
- # expect(Card.cache).to receive(:delete).with('x').exactly(2).times
129
- # expect(Card.cache).to receive(:delete).with('y').exactly(2).times
130
- a.save!
131
- end
132
- end
133
-
134
- describe "default option" do
135
- context "when card doesn't exist" do
136
- it "initializes new cards" do
137
- card = Card.fetch "non-existent",
138
- new: { default_content: "default content" }
139
- expect(card.db_content).to eq "default content"
140
- end
141
- end
142
- context "when new card exist" do
143
- it "doesn't change anything" do
144
- Card.new name: "new card",
145
- "+sub" => { content: "some content" }
146
- card = Card.fetch "new card+sub",
147
- new: { default_content: "new content" }
148
- expect(card.db_content).to eq "some content"
149
- end
150
- end
151
- end
152
-
153
- describe "preferences" do
154
- before do
155
- Card::Auth.signin Card::WagnBotID
156
- end
157
-
158
- it "prefers db cards to pattern virtual cards" do
159
- Card.create! name: "y+*right+*structure",
160
- content: "Formatted Content"
161
- Card.create! name: "a+y", content: "DB Content"
162
- card = Card.fetch("a+y")
163
- expect(card).to be_not_virtual.and have_db_content "DB Content"
164
- expect(card.rule(:structure)).to eq("Formatted Content")
165
- end
166
-
167
- it "prefers a pattern virtual card to trash cards" do
168
- Card.create!(name: "y+*right+*structure", content: "Formatted Content")
169
- Card.create!(name: "a+y", content: "DB Content")
170
- Card.fetch("a+y").delete!
171
-
172
- card = Card.fetch("a+y")
173
- expect(card).to be_virtual.and have_content "Formatted Content"
174
- end
175
-
176
- it "recognizes pattern overrides" do
177
- # ~~~ create right rule
178
- Card.create!(name: "y+*right+*structure", content: "Right Content")
179
- card = Card.fetch("a+y")
180
- expect(card).to be_virtual.and have_content "Right Content"
181
-
182
- # warn 'creating template'
183
- tpr = Card.create! name: "RichText+y+*type plus right+*structure",
184
- content: "Type Plus Right Content"
185
- card = Card.fetch("a+y")
186
- expect(card).to be_virtual.and have_content "Type Plus Right Content"
187
-
188
- # ~~~ delete type plus right rule
189
- tpr.delete!
190
- card = Card.fetch("a+y")
191
- expect(card).to be_virtual.and have_content "Right Content"
192
- end
193
-
194
- it "does not hit the database for every fetch_virtual lookup" do
195
- card_double = class_double("Card")
196
- Card.create!(name: "y+*right+*structure", content: "Formatted Content")
197
- Card.fetch("a+y")
198
- expect(card_double).not_to receive(:find_by_key)
199
- Card.fetch("a+y")
200
- end
201
-
202
- it "does not be a new_record after being saved" do
203
- Card.create!(name: "growing up")
204
- card = Card.fetch("growing up")
205
- expect(card.new_record?).to be_falsey
206
- end
207
- end
208
-
209
- describe "default_content option" do
210
- context "when card doesn't exist" do
211
- it "initializes card with default content" do
212
- card = Card.fetch "non-existent",
213
- new: { default_content: "default content" }
214
- expect(card).to have_db_content "default content"
215
- end
216
- end
217
- context "when new card exist" do
218
- it "doesn't change content" do
219
- Card.new name: "new card", "+sub" => { content: "some content" }
220
- card = Card.fetch "new card+sub", new: { default_content: "new content" }
221
- expect(card).to have_db_content "some content"
222
- end
223
- end
224
- end
225
- end
226
-
227
- describe "#fetch new: { ... }" do
228
- it "returns a new card if it doesn't find one" do
229
- new_card = Card.fetch "Never Seen Me Before", new: {}
230
- expect(new_card).to be_a(Card).and be_a_new_record
231
- expect { new_card.save! }.to increase_card_count.by(1)
232
- end
233
-
234
- it "returns a card if it finds one" do
235
- new_card = Card.fetch "A+B", new: {}
236
- expect(new_card).to be_a(Card).and be_real
237
- expect { new_card.save! }.not_to increase_card_count
238
- end
239
-
240
- it "takes a second hash of options as new card options" do
241
- new_card = Card.fetch "Never Before", new: { type: "Image" }
242
- expect(new_card).to be_a(Card).and be_a_new_record
243
- .and have_type(:image)
244
- expect(Card.fetch("Never Before", new: {})).to have_type(:basic)
245
- end
246
- end
247
-
248
- describe "#fetch_virtual" do
249
- before do
250
- Card::Auth.as_bot do
251
- Card.create! name: "testsearch+*right+*structure",
252
- content: '{"plus":"_self"}', type: "Search"
253
- end
254
- end
255
- it "finds cards with *right+*structure specified" do
256
- expect(Card.fetch("A+testsearch".to_name))
257
- .to be_virtual.and have_type(:search_type)
258
- .and have_content '{"plus":"_self"}'
259
- end
260
- context "fetched virtual card with new args" do
261
- it "fetchs the virtual card with type set in patterns" do
262
- Card.fetch "+testsearch", new: { name: "+testsearch",
263
- supercard: Card["home"] }
264
-
265
- c = Card.fetch("Home+testsearch".to_name)
266
- expect(c).to be_virtual.and have_type(:search_type)
267
- .and have_content('{"plus":"_self"}')
268
-
269
- patterns = c.instance_variable_get("@patterns").map(&:to_s)
270
- expect(patterns).to include("Search+*type")
271
- end
272
- end
273
- end
274
-
275
- describe "#id" do
276
- it "handles integer args" do
277
- expect(Card.id(1234)).to eq(1234)
278
- end
279
-
280
- it "handles card args" do
281
- a = Card["A"]
282
- expect(Card.id(a)).to eq(a.id)
283
- end
284
-
285
- it "handles symbols" do
286
- expect(Card.id(:structure)).to eq(Card::StructureID)
287
- end
288
- end
289
-
290
- describe "#exists?" do
291
- it "is true for cards that are there" do
292
- expect(Card.exists?("A")).to eq(true)
293
- end
294
-
295
- it "is false for cards that aren't" do
296
- expect(Card.exists?("Mumblefunk is gone")).to eq(false)
297
- end
298
- end
299
-
300
- describe "#fetch_name" do
301
- example "symbol" do
302
- expect(Card.fetch_name(:all)).to eq "*all"
303
- end
304
-
305
- example "string" do
306
- expect(Card.fetch_name("home")).to eq "Home"
307
- end
308
-
309
- example "id" do
310
- expect(Card.fetch_name(Card::BasicID)).to eq "RichText"
311
- end
312
-
313
- example "invalid id" do
314
- expect(Card.fetch_name("~1836/[[/assets/fonts")).to be_nil
315
- end
316
-
317
- example "array" do
318
- expect(Card.fetch_name(%w[a b])).to eq "A+B"
319
- end
320
-
321
- example "param list" do
322
- expect(Card.fetch_name("fruit", :type, "*create")).to eq "Fruit+*type+*create"
323
- end
324
-
325
- example "name doesn't exist" do
326
- expect(Card.fetch_name("unknown_name")).to eq nil
327
- end
328
-
329
- example "fallback policy" do
330
- name = Card.fetch_name("unknown_name") { "Unknown Name" }
331
- expect(name).to eq "Unknown Name"
332
- end
333
-
334
- it "doesn't fetch virtual names" do
335
- expect(Card.fetch_name(:all, :self, :create)).to eq nil
336
- end
337
- end
338
- end