-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create an lightweight ORM for saving (#3759)
* feat: create an lightweight ORM for saving * add rawget/rawset to lua global * remove previously used enums * chaining * annotations and do not run strip for extradata
- Loading branch information
Showing
3 changed files
with
233 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ std = { | |
"package", | ||
"pairs", | ||
"pcall", | ||
"rawget", | ||
"rawset", | ||
"require", | ||
"select", | ||
"setmetatable", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- Triple Comment to Enable our LLS Plugin | ||
describe('LPDB Object-Relational Mapping', function() | ||
local Lpdb = require('Module:Lpdb') | ||
|
||
describe('setting data', function() | ||
it('assign value on init', function() | ||
local match2 = Lpdb.Match2:new({bestof = 10}) | ||
assert.are_same({bestof = 10}, rawget(match2, 'fields')) | ||
end) | ||
|
||
it('__newindex', function() | ||
local match2 = Lpdb.Match2:new() | ||
match2.bestof = 7 | ||
assert.are_same({bestof = 7}, rawget(match2, 'fields')) | ||
end) | ||
|
||
it('set()', function() | ||
local match2 = Lpdb.Match2:new():set('bestof', 5) | ||
assert.are_same({bestof = 5}, rawget(match2, 'fields')) | ||
end) | ||
|
||
it('setMany()', function() | ||
local match2 = Lpdb.Match2:new():setMany{bestof = 3, game = 'r6s'} | ||
assert.are_same({bestof = 3, game = 'r6s'}, rawget(match2, 'fields')) | ||
end) | ||
|
||
it('strip html tags', function() | ||
local match2 = Lpdb.Match2:new():set('match2bracketdata', {header = '<abbr title="Best of 5">Bo5</abbr>'}) | ||
assert.are_same({match2bracketdata = {header = 'Bo5'}}, rawget(match2, 'fields')) | ||
end) | ||
end) | ||
|
||
describe('saving data', function() | ||
it('saving', function() | ||
local stub = stub(mw.ext.LiquipediaDB, 'lpdb_match2') | ||
Lpdb.Match2:new({match2id = 'Foo', match2bracketid = 'Bar', bestof = 3, game = 'r6s'}):save() | ||
assert.stub(stub).called_with('Foo', { | ||
bestof = 3, | ||
date = 0, | ||
dateexact = 0, | ||
extradata = {}, | ||
finished = 0, | ||
game = 'r6s', | ||
icon = '', | ||
icondark = '', | ||
links = {}, | ||
liquipediatier = '', | ||
liquipediatiertype = '', | ||
match2bracketdata = {}, | ||
match2bracketid = 'Bar', | ||
match2games = {}, | ||
match2id = 'Foo', | ||
match2opponents = {}, | ||
mode = '', | ||
parent = '', | ||
patch = '', | ||
publishertier = '', | ||
resulttype = '', | ||
section = '', | ||
series = '', | ||
shortname = '', | ||
stream = {}, | ||
tickername = '', | ||
tournament = '', | ||
type = '', | ||
vod = '', | ||
walkover = '', | ||
winner = '', | ||
}) | ||
stub:revert() | ||
end) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters