How to test inserts to a model?

29 views
Skip to first unread message

till haxor

unread,
Feb 5, 2014, 8:32:25 PM2/5/14
to chica...@googlegroups.com
hi, i'm using CB to create a new project, i like erlang, and CB is the best framework to build a great webapp in this language, i need some help

how can i test 500 insert to a model?

for example, a table with 2 columns (name, other), how can i insert 500 rows into this table using CB test's?

excuse me, i'm new in erlang, i'm a python developer :)

Evgeny M

unread,
Feb 7, 2014, 6:27:43 AM2/7/14
to chica...@googlegroups.com
lists:foreach(fun(I) -> M = yourmodel:new(id, integer_to_list(I), undefined), M:save() end, lists:seq(1, 500))
Pretty sure this code can be used in tests too.
It's very similar to python

четверг, 6 февраля 2014 г., 5:32:25 UTC+4 пользователь till haxor написал:

David Welton

unread,
Feb 7, 2014, 6:34:18 AM2/7/14
to chica...@googlegroups.com
Something I was recently introduced to is the PropEr testing system.
You should definitely look at that for testing your models, and
generating fake data.

You can get an instance of student by doing proper_gen:pick(student()).

student() ->
boss_record:new(student, [{name, name()}]).

arabic_name() ->
?LET(Name, list(weighted_union([{1, choose(16#0620, 16#064a)},
{1, choose(16#0671, 16#06d5)}])),
unicode:characters_to_binary(Name)).

cyrillic_name() ->
?LET(Name, list(weighted_union([{1, choose(16#0400, 16#04ff)}])),
unicode:characters_to_binary(Name)).


sinhala_name() ->
list(oneof([<<"අ">>,<<"ආ">>,<<"ඇ">>,<<"ඈ">>,<<"ඉ">>,<<"ඊ">>,<<"උ">>,<<"ඌ">>,<<"ඍ">>,<<"ඎ">>,<<"ඏ">>,<<"ඐ">>,<<"එ">>,<<"ඒ">>,<<"ඓ">>,<<"ඔ">>,<<"ඕ">>,<<"ඖ">>,<<"ක">>,<<"ඛ">>,<<"ග">>,<<"ඝ">>,<<"ඞ">>,<<"ඟ">>,<<"ච">>,<<"ඡ">>,<<"ජ">>,<<"ඣ">>,<<"ඤ">>,<<"ඥ">>,<<"ඦ">>,<<"ට">>,<<"ඨ">>,<<"ඩ">>,<<"ඪ">>,<<"ණ">>,<<"ඬ">>,<<"ත">>,<<"ථ">>,<<"ද">>,<<"ධ">>,<<"න">>,<<"ඳ">>,<<"ප">>,<<"ඵ">>,<<"බ">>,<<"භ">>,<<"ම">>,<<"ඹ">>,<<"ය">>,<<"ර">>,<<"ල">>,<<"ව">>,<<"ශ">>,<<"ෂ">>,<<"ස">>,<<"හ">>,<<"ළ">>,<<"ෆ">>,<<"්">>,<<"ා">>,<<"ැ">>,<<"ෑ">>,<<"ි">>,<<"ී">>,<<"ු">>,<<"ූ">>,<<"ෘ">>,<<"ෙ">>,<<"ේ">>,<<"ෛ">>,<<"ො">>,<<"ෝ">>,<<"ෞ">>,<<"ෟ">>])).

kanji_name() ->
?LET(Name, list(weighted_union([{1, choose(16#4e00, 16#9faf)}])),
unicode:characters_to_binary(Name)).

hangul_name() ->
?LET(Name, list(weighted_union([{1, choose(16#ac00, 16#d7af)}])),
unicode:characters_to_binary(Name)).

western_europe_name() ->
?LET(Name,
non_empty([choose($A, $Z) |
list(weighted_union([{20, choose($a, $z)},
{10, choose(16#c0, 16#ff)},
{1, $'},
{1, $-},
{1, $.},
{1, $ }]
))]),
unicode:characters_to_binary(Name)).

ascii_name() ->
non_empty([choose($A, $Z) |
list(weighted_union([{20, choose($a, $z)},
{1, $'},
{1, $-},
{1, $.},
{1, $ }]
))]).

name() ->
oneof([ascii_name(), western_europe_name(), hangul_name(),
kanji_name(), sinhala_name(), arabic_name(), cyrillic_name()]).

gender() ->
oneof(["male", "female", undefined]).
> --
> You received this message because you are subscribed to the Google Groups
> "ChicagoBoss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to chicagoboss...@googlegroups.com.
> Visit this group at http://groups.google.com/group/chicagoboss.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/chicagoboss/498a776a-78c4-4061-aded-3afcc8b609a9%40googlegroups.com.
>
> For more options, visit https://groups.google.com/groups/opt_out.



--
David N. Welton

http://www.welton.it/davidw/

http://www.dedasys.com/
Reply all
Reply to author
Forward
0 new messages