Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'release/1.6.0'

  • Loading branch information...
commit 9af13a05747593b77ba57d604e5edcdf1ef6822d 2 parents 05bec4e + ed0ab8f
@amalloy amalloy authored
View
3  project.clj
@@ -1,4 +1,4 @@
-(defproject foreclojure "1.5.3"
+(defproject foreclojure "1.6.0"
:description "4clojure - a website for learning Clojure"
:dependencies [[clojure "1.2.1"]
[clojure-contrib "1.2.0"]
@@ -19,7 +19,6 @@
[commons-lang "2.6"]
[org.apache.commons/commons-email "1.2"]]
:dev-dependencies [[lein-ring "0.4.5"]
- [swank-clojure "1.3.3"]
[midje "1.1.1"]]
:main foreclojure.core
:ring {:handler foreclojure.core/app
View
19 resources/error-messages.properties
@@ -0,0 +1,19 @@
+
+
+
+#######################################
+# error messages used in registration #
+# and when updating user settings #
+#######################################
+
+settings.user-exists=User already exists
+settings.uname-alphanum=Username must be alphanumeric
+settings.uname-size=Username must be 4-13 characters long
+settings.npwd-size=New password must be at least seven characters long
+settings.pwd-size=Password must be at least seven characters long
+settings.pwd-match=Passwords don't match
+settings.npwd-match=New password was not entered identically twice
+settings.pwd-incorrect=Current password incorrect
+settings.email-invalid=Please enter a valid email address
+settings.email-exists=User with this email address already exists
+
View
3  resources/public/css/style.css
@@ -419,7 +419,8 @@ div#problems-error {
float: left;
width: 50%;
height: 250px;
- overflow: hidden
+ overflow: hidden;
+ border: 1px solid #aaa;
}
table.my-table {
View
134 resources/public/script/codebox.js
@@ -0,0 +1,134 @@
+var CodeBox = {
+
+ disableJavascript: null,
+ element: null,
+ submitButtons: null,
+ editor: null,
+ editorSession: null,
+ editorElement: null,
+ cont: true,
+ high: false,
+ animationTime: 800,
+ waitTimePerItem: 500,
+ images: null,
+
+ initialize: function() {
+ this.disableJavascript = $('#disable-javascript-codebox').length > 0
+ || $.browser.mobile;
+ this.element = $("#code-box");
+ this.submitButtons = $("#run-button, #submission-button");
+
+ if(!this.disableJavascript && this.submitButtons.length > 0) {
+ this.setupEditor();
+ }
+
+ this.submitButtons.live("click", $.proxy(this.run, this));
+ },
+
+ setupEditor: function() {
+ this.element.after("<div id=\"code-div\"> <pre id=\"editor\">" +
+ this.element.val() + "</pre></div>");
+
+ this.element.hide();
+ this.editorElement = $("#editor");
+
+ this.editor = ace.edit("editor");
+ this.editor.setTheme("ace/theme/textmate");
+ this.editor.setShowPrintMargin(false);
+
+ var ClojureMode = require("ace/mode/clojure").Mode;
+ this.editorSession = this.editor.getSession();
+ this.editorSession.setMode(new ClojureMode());
+ this.editorSession.setUseSoftTabs(true);
+ this.editorSession.setTabSize(2);
+ this.editorElement.css("font-size", "13px");
+ },
+
+ getCode: function() {
+ if(this.disableJavascript)
+ return $("#code-box").val();
+ else
+ return this.editorSession.getValue();
+ },
+
+ toggle: function() {
+ if(this.disableJavascript)
+ $("#code-box").toggle('fast');
+ else
+ $("#code-div").toggle('fast');
+ },
+
+ run: function(e) {
+ e.preventDefault();
+
+ var text = this.getCode(),
+ id = $('#id').attr("value");
+
+ this.images = $(".testcases").find("img"),
+
+ $.ajax({
+ type: "POST",
+ url: "/rest/problem/"+id,
+ dataType: "json",
+ data: { id: id, code: text, },
+ timeout: 20000, // default clojail timeout is 10000
+ beforeSend: $.proxy(this.beforeSendCallback, this),
+ success: $.proxy(this.successCallback, this),
+ error: function(data, str, error) {
+ $("#message-text").text("An Error occured: "+error);
+ }});
+ },
+
+ beforeSendCallback: function() {
+ var anim = function() {
+ if(this.cont) {
+ this.images.animate({
+ opacity: this.high ? 1.0 : 0.1,
+ }, this.animationTime);
+ this.high = !this.high;
+ setTimeout(anim,this.animationTime);
+ }
+ };
+
+ $("#message-text").text("Executing unit tests...");
+ $("#error-message-text").text("");
+ this.images.each( function(index, element) {
+ setIconColor(element, "blue");
+ });
+ setTimeout(changeToCodeView,0);
+ setTimeout($.proxy(anim, this),0);
+ },
+
+ successCallback: function(data) {
+ var waitTime = this.waitTimePerItem;
+
+ var failingTest = data.failingTest,
+ getColorFor = function(index) {
+ return index === failingTest ? "red" : "green";
+ },
+ testWasExecuted = function(index) {
+ return index <= failingTest;
+ },
+ setColor = function(index,element) {
+ var color = getColorFor(index);
+ waitTime = CodeBox.waitTimePerItem * (index+1);
+ setIconColor(element, color, waitTime);
+ },
+ setMessages = function() {
+ $("#message-text").html(data.message);
+ $("#error-message-text").html(data.error);
+ $("#golfgraph").html(data.golfChart);
+ $("#golfscore").html(data.golfScore);
+ configureGolf();
+ },
+ stopAnimation = function() {
+ this.cont = false;
+ this.images.stop(true);
+ this.images.css({ opacity: 1.0, });
+ };
+
+ setTimeout($.proxy(stopAnimation, this), waitTime);
+ this.images.filter( testWasExecuted ).each(setColor);
+ setTimeout(setMessages, waitTime);
+ },
+}
View
121 resources/public/script/foreclojure.js
@@ -3,7 +3,7 @@ var updateProblemCountDelay = 4000; // milliseconds
$(document).ready(function() {
configureDataTables();
- configureCodeBox();
+ CodeBox.initialize();
configureGolf();
if($("#totalcount").length > 0)
@@ -150,7 +150,7 @@ function configureDataTables(){
]
} );
-
+
$('#server-user-table').dataTable( {
"aoColumns": [
null,
@@ -178,126 +178,11 @@ function changeToCodeView() {
$('#graph-link').html("View Chart");
}
-function configureCodeBox(){
- //For no javascript version we have the code-box text area
- //If we have javascript on then we remove it and replace it with
- //the proper div
- var oldBox = $('#code-box');
- var disableJavaScriptCodeBox = $('#disable-javascript-codebox');
- if (disableJavaScriptCodeBox.length){
- return;
- }
- var hiddenCodeInput = "<input type=\"hidden\" value=\"blank\" name=\"code\" id=\"code\">";
- oldBox.replaceWith("<div id=\"code-div\"> <pre id=\"editor\">" + oldBox.val() + "</pre></div>"+hiddenCodeInput);
-
- if ($("#run-button").length || $("#submission-button").length){
- var editor = ace.edit("editor");
- editor.setTheme("ace/theme/textmate");
-
- var ClojureMode = require("ace/mode/clojure").Mode;
- var session = editor.getSession();
-
- var clickHandler = function() {
- var text = session.getValue(),
- id = $('#id').attr("value"),
- images = $(".testcases").find("img"),
- cont = true,
- high = false,
- animationTime = 800,
- waitTimePerItem = 500,
- waitTime = waitTimePerItem,
-
- beforeSendCallback = function(data) {
- var anim = function() {
- if(cont) {
- images.animate({
- opacity: high ? 1.0 : 0.1,
- }, animationTime);
- high = !high;
- setTimeout(anim,animationTime);
- }
- };
-
- $("#message-text").text("Executing unit tests...");
- $("#error-message-text").text("");
- images.each( function(index, element) {
- setIconColor(element, "blue");
- });
- setTimeout(changeToCodeView,0);
- setTimeout(anim,0);
- },
- successCallback = function(data) {
- var failingTest = data.failingTest,
- getColorFor = function(index) {
- return index === failingTest ? "red" : "green";
- },
- testWasExecuted = function(index) {
- return index <= failingTest;
- },
- setColor = function(index,element) {
- var color = getColorFor(index);
- waitTime = waitTimePerItem * (index+1);
- setIconColor(element, color, waitTime);
- },
- setMessages = function() {
- $("#message-text").html(data.message);
- $("#error-message-text").html(data.error);
- $("#golfgraph").html(data.golfChart);
- $("#golfscore").html(data.golfScore);
- configureGolf();
- },
- stopAnimation = function() {
- cont = false;
- images.stop(true);
- images.css({ opacity: 1.0, });
- };
-
- setTimeout(stopAnimation, waitTime);
- images.filter( testWasExecuted ).
- each(setColor);
- setTimeout (setMessages, waitTime);
- };
-
- $.ajax({type: "POST",
- url: "/rest/problem/"+id,
- dataType: "json",
- data: { id: id, code: text, },
- timout: 20000, // default clojail timeout is 10000
- beforeSend: beforeSendCallback,
- success: successCallback,
- error: function(data, str, error) {
- $("#message-text").text("An Error occured: "+error);
- },
- });
- return false;
- };
-
- $("#run-button").click(clickHandler);
-
- session.setMode(new ClojureMode());
- session.setUseSoftTabs(true);
- session.setTabSize(2);
-
- document.getElementById('editor').style.fontSize='13px';
- $("#run-button").click(function(){
- var text = editor.getSession().getValue();
- $('#code').val(text);
- });
-
- $("#submission-button").click(function(){
- var text = editor.getSession().getValue();
- $('#code').val(text);
- });
- }
-}
-
function configureGolf(){
$('#graph-link').show();
$('#golfgraph').hide();
$('#graph-link').click(function() {
- $('#code-div').toggle('fast', function() {
- // Animation complete.
- });
+ CodeBox.toggle();
$('#golfgraph').toggle('fast', function() {
// Animation complete.
});
View
7 resources/public/vendor/script/detectmobilebrowser.js
@@ -0,0 +1,7 @@
+/**
+ * jQuery.browser.mobile (http://detectmobilebrowser.com/)
+ *
+ * jQuery.browser.mobile will be true if the browser is a mobile device
+ *
+ **/
+(function(a){jQuery.browser.mobile=/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);
View
9 src/foreclojure/messages.clj
@@ -0,0 +1,9 @@
+(ns foreclojure.messages)
+
+(defn load-props [file]
+ (into {} (doto (java.util.Properties.)
+ (.load (-> (Thread/currentThread)
+ (.getContextClassLoader)
+ (.getResourceAsStream file))))))
+
+(def err-msgs (load-props "error-messages.properties"))
View
15 src/foreclojure/register.clj
@@ -6,6 +6,7 @@
[compojure.core :only [defroutes GET POST]]
[foreclojure.utils :only [form-row assuming flash-error plausible-email?]]
[foreclojure.template :only [def-page]]
+ [foreclojure.messages :only [err-msgs]]
[somnium.congomongo :only [insert! fetch-one]]))
(def-page register-page []
@@ -26,20 +27,20 @@
(defn do-register [user pwd repeat-pwd email]
(let [lower-user (.toLowerCase user)]
(assuming [(nil? (fetch-one :users :where {:user lower-user}))
- "User already exists",
+ (err-msgs "settings.user-exists"),
(< 3 (.length lower-user) 14)
- "Username must be 4-13 characters long",
+ (err-msgs "settings.uname-size"),
(= lower-user
(first (re-seq #"[A-Za-z0-9_]+" lower-user)))
- "Username must be alphanumeric"
+ (err-msgs "settings.uname-alphanum")
(< 6 (.length pwd))
- "Password must be at least seven characters long",
+ (err-msgs "settings.pwd-size"),
(= pwd repeat-pwd)
- "Passwords don't match",
+ (err-msgs "settings.pwd-match"),
(plausible-email? email)
- "Please enter a valid email address"
+ (err-msgs "settings.email-invalid")
(nil? (fetch-one :users :where {:email email}))
- "User with this email address already exists"]
+ (err-msgs "settings.email-exists")]
(do
(insert! :users
{:user lower-user
View
24 src/foreclojure/settings.clj
@@ -6,6 +6,7 @@
[foreclojure.utils :only [from-mongo flash-error flash-msg with-user form-row assuming send-email login-url plausible-email?]]
[foreclojure.template :only [def-page content-page]]
[foreclojure.users :only [disable-codebox? hide-solutions? gravatar-img]]
+ [foreclojure.messages :only [err-msgs]]
[compojure.core :only [defroutes GET POST]]
[useful.map :only [keyed]]
[clojail.core :only [thunk-timeout]]
@@ -70,27 +71,30 @@
new-pwd-hash (.encryptPassword encryptor new-pwd)
new-lower-user (.toLowerCase new-username)]
(assuming [(or (= new-lower-user user) (nil? (fetch-one :users :where {:user new-lower-user})))
- "User already exists",
+ (err-msgs "settings.user-exists"),
(< 3 (.length new-lower-user) 14)
- "Username must be 4-13 characters long",
+ (err-msgs "settings.uname-size"),
(= new-lower-user
(first (re-seq #"[A-Za-z0-9_]+" new-lower-user)))
- "Username must be alphanumeric"
+ (err-msgs "settings.uname-alphanum")
(or (empty? new-pwd) (< 6 (.length new-pwd)))
- "New password must be at least seven characters long",
+ (err-msgs "settings.npwd-size"),
(= new-pwd repeat-pwd)
- "New password was not entered identically twice"
+ (err-msgs "settings.npwd-match")
(or (empty? new-pwd)
(.checkPassword encryptor old-pwd pwd))
- "Current password incorrect"
+ (err-msgs "settings.pwd-incorrect")
(plausible-email? email)
- "Please enter a valid email address"
+ (err-msgs "settings.email-invalid")
(nil? (fetch-one :users :where {:email email :user {:$ne user}}))
- "User with this email address already exists"]
+ (err-msgs "settings.email-exists")]
(do
(update! :users {:user user}
- {:$set {:pwd (if (not-empty new-pwd) new-pwd-hash pwd) :user new-lower-user :email email
- :disable-code-box (boolean disable-codebox) :hide-solutions (boolean hide-solutions)}}
+ {:$set {:pwd (if (seq new-pwd) new-pwd-hash pwd)
+ :user new-lower-user
+ :email email
+ :disable-code-box (boolean disable-codebox)
+ :hide-solutions (boolean hide-solutions)}}
:upsert false)
(session/session-put! :user new-lower-user)
(flash-msg "/problems"
View
3  src/foreclojure/template.clj
@@ -22,9 +22,10 @@
".syntaxhighlighter { overflow-y: hidden !important; }"]
(css "css/style.css" "css/demo_table.css" "css/shCore.css" "css/shThemeDefault.css")
(js "vendor/script/jquery-1.5.2.min.js" "vendor/script/jquery.dataTables.min.js" "vendor/script/jquery.flipCounter.1.1.pack.js" "vendor/script/jquery.easing.1.3.js")
- (js "script/foreclojure.js")
+ (js "script/codebox.js" "script/foreclojure.js")
(js "vendor/script/xregexp.js" "vendor/script/shCore.js" "vendor/script/shBrushClojure.js")
(js "vendor/script/ace/ace.js" "vendor/script/ace/mode-clojure.js")
+ (js "vendor/script/detectmobilebrowser.js")
[:script {:type "text/javascript"} "SyntaxHighlighter.all()"]]
[:body
(when (:fork-banner attrs)
View
64 test/foreclojure/test/register.clj
@@ -0,0 +1,64 @@
+(ns foreclojure.test.register
+ (:require [sandbar.stateful-session :as session]
+ [ring.util.response :as response])
+ (:use [foreclojure.register])
+ (:use [foreclojure.messages :only [err-msgs]])
+ (:use [clojure.test])
+ (:use [midje.sweet])
+ (:use [foreclojure.utils :only [form-row assuming flash-error]])
+ (:use [somnium.congomongo :only [insert! fetch-one]]))
+
+
+
+
+(deftest test-do-register
+ (let [uname "username"
+ lngname "thisisalongusername"
+ bname "$#%^$djc"
+ pwd "password"
+ shpwd "pass"
+ email "test@test.com"
+ bemail "testing.com"]
+ (against-background [(fetch-one :users :where {:user lngname}) => nil
+ (fetch-one :users :where {:user bname}) => nil
+ (fetch-one :users :where {:user uname}) => nil
+ (fetch-one :users :where {:email email}) => nil
+ (insert! :users anything) => nil
+ (session/session-put! :user anything) => nil
+ (session/flash-put! :user anything) => nil
+ (session/flash-put! :email anything) => nil]
+ (fact "about do-register - good inputs"
+ (do-register uname pwd pwd email) => truthy
+ (provided
+ (response/redirect "/") => 1))
+ (fact "about do-register - userexists"
+ (do-register uname pwd pwd email) => truthy
+ (provided
+ (fetch-one :users :where {:user uname}) => {:user "username"}
+ (flash-error "/register" (err-msgs "settings.user-exists")) => 1))
+ (fact "about do-register - username too long"
+ (do-register lngname pwd pwd email) => truthy
+ (provided
+ (flash-error "/register" (err-msgs "settings.uname-size")) => 1))
+ (fact "about do-register - username not alphanumeric"
+ (do-register bname pwd pwd email) => truthy
+ (provided
+ (flash-error "/register" (err-msgs "settings.uname-alphanum")) => 1))
+ (fact "about do-register - short password"
+ (do-register uname shpwd shpwd email) => truthy
+ (provided
+ (flash-error "/register" (err-msgs "settings.pwd-size")) => 1))
+ (fact "about do-register - passwords don't match"
+ (do-register uname pwd shpwd email) => truthy
+ (provided
+ (flash-error "/register" (err-msgs "settings.pwd-match")) => 1))
+ (fact "about do-register - bad email"
+ (do-register uname pwd pwd bemail) => truthy
+ (provided
+ (flash-error "/register" (err-msgs "settings.email-invalid")) => 1))
+ (fact "about do-register - email exists"
+ (do-register uname pwd pwd email) => truthy
+ (provided
+ (fetch-one :users :where {:user uname}) => nil
+ (fetch-one :users :where {:email email}) => {:user "username"}
+ (flash-error "/register" (err-msgs "settings.email-exists")) => 1)))))
View
77 test/foreclojure/test/settings.clj
@@ -0,0 +1,77 @@
+(ns foreclojure.test.settings
+ (:require [sandbar.stateful-session :as session]
+ [ring.util.response :as response])
+ (:import [org.jasypt.util.password StrongPasswordEncryptor])
+ (:use [foreclojure.settings])
+ (:use [foreclojure.messages :only [err-msgs]])
+ (:use [clojure.test])
+ (:use [midje.sweet])
+ (:use [foreclojure.utils :only [get-user assuming flash-error flash-msg]])
+ (:use [somnium.congomongo :only [update! fetch-one]]))
+
+
+
+
+(deftest test-do-update-settings
+ "This test covers the control flow and validation of updating user settings"
+ (let [old-name "username"
+ new-name "usernamenew"
+ old-pwd "oldpasswd"
+ new-pwd "password"
+ or (StrongPasswordEncryptor.)
+ enpwd (.encryptPassword or old-pwd)
+ lngname "thisisalongusername"
+ bname "$#%^$djc"
+ short-pwd "pass"
+ email "test@test.com"
+ bad-email "testing.com"]
+ ;setting up defaults for function mocking
+ (against-background [(fetch-one :users :where {:user lngname}) => nil
+ (fetch-one :users :where {:user bname}) => nil
+ (fetch-one :users :where {:user new-name}) => nil
+ (fetch-one :users :where {:email email :user {:$ne old-name}}) => nil
+ (update! :users anything anything :upsert false) => nil
+ (session/session-put! :user anything) => nil
+ (session/session-get :user) => old-name
+ (get-user old-name) => {:user old-name :pwd enpwd}]
+ (fact "about do-update-settings! - good inputs"
+ (do-update-settings! new-name old-pwd new-pwd new-pwd email false false) => truthy
+ (provided
+ (flash-msg "/problems" anything) => 1))
+ (fact "about do-update-settings! - userexists"
+ (do-update-settings! new-name old-pwd new-pwd new-pwd email false false) => truthy
+ (provided
+ (fetch-one :users :where {:user new-name}) => {:user "username-new"}
+ (flash-error "/settings" (err-msgs "settings.user-exists")) => 1))
+ (fact "about do-update-settings! - username too long"
+ (do-update-settings! lngname old-pwd new-pwd new-pwd email false false) => truthy
+ (provided
+ (flash-error "/settings" (err-msgs "settings.uname-size")) => 1))
+ (fact "about do-update-settings! - username not alphanumeric"
+ (do-update-settings! bname old-pwd new-pwd new-pwd email false false) => truthy
+ (provided
+ (flash-error "/settings" (err-msgs "settings.uname-alphanum")) => 1))
+ (fact "about do-update-settings! - short password"
+ (do-update-settings! new-name old-pwd short-pwd short-pwd email false false) => truthy
+ (provided
+ (flash-error "/settings" (err-msgs "settings.npwd-size")) => 1))
+ (fact "about do-update-settings! - passwords don't match"
+ (do-update-settings! new-name old-pwd new-pwd old-pwd email false false) => truthy
+ (provided
+ (flash-error "/settings" (err-msgs "settings.npwd-match")) => 1))
+ (fact "about do-update-settings! - old password doesn't match"
+ (do-update-settings! new-name new-pwd new-pwd new-pwd email false false) => truthy
+ (provided
+ (flash-error "/settings" (err-msgs "settings.pwd-incorrect")) => 1))
+ (fact "about do-update-settings! - bad email"
+ (do-update-settings! new-name old-pwd new-pwd new-pwd bad-email false false) => truthy
+ (provided
+ (flash-error "/settings" (err-msgs "settings.email-invalid")) => 1))
+ (fact "about do-update-settings! - email exists"
+ (do-update-settings! new-name old-pwd new-pwd new-pwd email false false) => truthy
+ (provided
+ ;you have to specify both because midje can't tell them apart
+ (fetch-one :users :where {:user new-name}) => nil
+ (fetch-one :users :where {:email email :user {:$ne old-name}}) => {:user old-name}
+ (flash-error "/settings" (err-msgs "settings.email-exists")) => 1)))))
+
View
35 test/foreclojure/test/users.clj
@@ -1,11 +1,11 @@
(ns foreclojure.test.users
- (:use [foreclojure.users] :reload)
+ (:use [foreclojure.users])
(:use [clojure.test])
(:use [midje.sweet]))
(def users [{:user "user1", :solved [1 2 3 4] :rank 1}
{:user "user2", :solved [1 2 3] :rank 2}
- {:user "user3", :sovled [1 2] :rank 3}
+ {:user "user3", :solved [1 2] :rank 3}
{:user "user4", :solved [1] :rank 4}
{:user "user5", :solved [1] :rank 5}
{:user "user6", :solved [1] :rank 6}
@@ -18,31 +18,30 @@
(deftest user-datatables-paging
(facts "about datatable-paging"
- (count (datatable-paging users 0 10)) => 10
- (count (datatable-paging users 8 10)) => 2
- (count (datatable-paging users 2 5))) => 5
- (:user (first (datatable-paging users 2 5))) => "user3"
- (:user (last (datatable-paging users 2 5))) => "user7")
+ (count (datatable-paging 0 10 users)) => 10
+ (count (datatable-paging 8 10 users)) => 2
+ (count (datatable-paging 2 5 users))) => 5
+ (:user (first (datatable-paging 2 5 users))) => "user3"
+ (:user (last (datatable-paging 2 5 users))) => "user7")
(deftest user-datatables-sort-cols
(facts "about datatable sorting by columns"
- (:user (first (datatable-sort-cols users 0))) => "user1"
- (:user (second (datatable-sort-cols users 1))) => "user10"
- (:user (first (datatable-sort-cols users 2))) => "user1"
- (:user (first (datatable-sort-cols users 3))) => "user1"))
+ (:user (first (datatable-sort-cols 0 users))) => "user1"
+ (:user (second (datatable-sort-cols 1 users))) => "user10"
+ (:user (last (datatable-sort-cols 2 users))) => "user1"))
(deftest user-datatables-sort-dir
(facts "about datatable sort direction"
- (:user (first (datatable-sort-dir users "asc"))) => "user1"
- (:user (first (datatable-sort-dir users "desc"))) => "user10"))
+ (:user (first (datatable-sort-dir "asc" users))) => "user1"
+ (:user (first (datatable-sort-dir "desc" users))) => "user10"))
(deftest user-datatables-sort
(facts "about sorting by column and direction combined"
- (:user (first (datatable-sort users 1 "asc"))) => "user1"
- (:user (first (datatable-sort users 1 "desc"))) => "user9"))
+ (:user (first (datatable-sort 1 "asc" users))) => "user1"
+ (:user (first (datatable-sort 1 "desc" users))) => "user9"))
(deftest user-datatables-filter
(facts "about filtering the username by text"
- (:user (first (datatable-filter users "4"))) => "user4"
- (:user (second (datatable-filter users "1"))) => "user10"
- (count (datatable-filter users nil)) => 10))
+ (:user (first (datatable-filter "4" users))) => "user4"
+ (:user (second (datatable-filter "1" users))) => "user10"
+ (count (datatable-filter nil users)) => 10))
Please sign in to comment.
Something went wrong with that request. Please try again.