Permalink
Browse files

use Storage instead of localStorage and load js in html head

    phantomjs not defined localStorage, but defined Storage.
    load all js files in runner.html because dynamic load in js failed
    Storage tests.
  • Loading branch information...
1 parent 317a377 commit 44eede770d3d52c9d1f3b838cb7fad93e1e02077 @natsumesou committed Apr 4, 2012
Showing with 38 additions and 34 deletions.
  1. +3 −3 collections/schedule.js
  2. +8 −23 models/storage.js
  3. +4 −2 spec/collections/schedule_spec.js
  4. +3 −3 spec/models/storage_spec.js
  5. +17 −0 spec/runner.html
  6. +3 −3 spec/spec.js
View
@@ -14,9 +14,9 @@ schedules[i].id = RegExp.$1
}else{
schedules[i].id = new Date().getTime();
}
- schedules[i].enddate = new Date(schedules[i].enddate);
- schedules[i].startdate = new Date(schedules[i].startdate);
- schedules[i].updated = new Date(schedules[i].updated);
+ schedules[i].enddate = new Date(schedules[i].enddate.replace('-', '/'));
+ schedules[i].startdate = new Date(schedules[i].startdate.replace('-', '/'));
+ schedules[i].updated = new Date(schedules[i].updated.replace('-', '/'));
schedules[i].new = true;
schedules[i].isUpcomingNotified = false;
}
View
@@ -1,36 +1,21 @@
garoon.Models.Storage = Backbone.Model.extend({
load: function() {
- var string = window.localStorage['schedules'];
- var schedules = [];
- if(string !== undefined){
- try{
- schedules = JSON.parse(string);
- }catch(error){
- schedules = new garoon.Collections.Schedule();
- console.warn("WARN: load schedules from localStorage is not formatted: %s", string);
- console.warn(error);
- }
- }
+ var schedules = Storage['schedules'] || new garoon.Collections.Schedule();
this.set({
- domain: window.localStorage['domain'],
- username: window.localStorage['username'],
- password: window.localStorage['password'],
+ domain: Storage['domain'],
+ username: Storage['username'],
+ password: Storage['password'],
schedules: schedules
});
return this;
},
save: function() {
- window.localStorage['domain'] = this.get('domain');
- window.localStorage['username'] = this.get('username');
- window.localStorage['password'] = this.get('password');
- var schedules = this.get('schedules');
- if(typeof schedules === 'object'){
- window.localStorage['schedules'] = JSON.stringify(schedules);
- }else{
- window.localStorage['schedules'] = schedules;
- }
+ Storage['domain'] = this.get('domain');
+ Storage['username'] = this.get('username');
+ Storage['password'] = this.get('password');
+ Storage['schedules'] = this.get('schedules');
return this;
},
@@ -51,10 +51,12 @@ describe("garoon.Collections.Schedule", function() {
});
describe("clearPastSchedules", function() {
- var schedule;
beforeEach(function() {
- schedule = new garoon.Models.Schedule({startdate: new Date("3000-04-01 13:30:00")});
+ schedules = new garoon.Collections.Schedule();
+ var schedule = new garoon.Models.Schedule({startdate: new Date("3000/04/01 13:30:00")});
schedules.add(schedule);
+ var oldSchedule = new garoon.Models.Schedule({startdate: new Date("2000/04/01 13:30:00")});
+ schedules.add(oldSchedule);
});
it("delete old schedules", function() {
expect(schedules.clearPastSchedules(schedules).length).toBe(1);
@@ -66,7 +66,7 @@ describe("garoon.Models.Storage", function() {
describe("load", function(){
beforeEach(function() {
- window.localStorage['domain'] = 'test'
+ Storage['domain'] = 'test'
storage = new garoon.Models.Storage();
});
@@ -83,11 +83,11 @@ describe("garoon.Models.Storage", function() {
it("data to loadStorage", function() {
storage.domain('hoge.jp');
storage.save();
- expect(window.localStorage['domain']).toBe('hoge.jp');
+ expect(Storage['domain']).toBe('hoge.jp');
});
});
afterEach(function() {
- window.localStorage['domain'] = '';
+ Storage['domain'] = undefined;
});
});
View
@@ -3,6 +3,23 @@
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="./lib/jasmine-1.1.0/jasmine.css">
+ <script type="text/javascript" charset="utf-9" src="./lib/jasmine-1.1.0/jasmine.js"></script>
+ <script type="text/javascript" charset="utf-8" src="./lib/jasmine-1.1.0/jasmine-html.js"></script>
+ <script type="text/javascript" charset="utf-8" src="./lib/mock-ajax.js"></script>
+ <script type="text/javascript" charset="utf-8" src="./lib/jasmine.junit_reporter.js"></script>
+ <script type="text/javascript" charset="utf-8" src="./mock/schedule.js"></script>
+
+ <script type="text/javascript" charset="utf-8" src="../libs/jquery-1.7.2.min.js"></script>
+ <script type="text/javascript" charset="utf-8" src="../libs/jquery.xml2json.js"></script>
+ <script type="text/javascript" charset="utf-8" src="../libs/underscore-min.js"></script>
+ <script type="text/javascript" charset="utf-8" src="../libs/backbone-min.js"></script>
+ <script type="text/javascript" charset="utf-8" src="../init.js"></script>
+ <script type="text/javascript" charset="utf-8" src="../models/storage.js"></script>
+ <script type="text/javascript" charset="utf-8" src="../models/schedule.js"></script>
+ <script type="text/javascript" charset="utf-8" src="./models/storage_spec.js"></script>
+ <script type="text/javascript" charset="utf-8" src="../collections/schedule.js"></script>
+ <script type="text/javascript" charset="utf-8" src="./models/schedule_spec.js"></script>
+ <script type="text/javascript" charset="utf-8" src="./collections/schedule_spec.js"></script>
</head>
<body>
<script type="text/javascript">
View
@@ -5,9 +5,9 @@ var setupPageFn = function(p, k) {
return function() {
overloadPageEvaluate(p);
setupWriteFileFunction(p, k);
- loadLibraries(p);
- loadFiles(p);
- loadSpecs(p);
+ //loadLibraries(p);
+ //loadFiles(p);
+ //loadSpecs(p);
};
};

0 comments on commit 44eede7

Please sign in to comment.