Permalink
Browse files

try to fix fetch/parse client-side sheet - partly fixed; still broken

  • Loading branch information...
1 parent 20442a3 commit 79795827b490196b5087aa3400413aa062aef67f @laripk committed Nov 2, 2011
@@ -19,7 +19,7 @@ class StoredSheet.Models.Column # extends Backbone.Model
return data
get: (item) ->
this[item]
- # this method is only here because I got tired of switching my tests' syntax back and forth
+ # get method is only here because I got tired of switching my tests' syntax back and forth
_.extend(StoredSheet.Models.Column.prototype, Backbone.Events)
class StoredSheet.Collections.Columns extends Backbone.Collection
@@ -14,9 +14,15 @@ class StoredSheet.Models.Sheet extends Backbone.Model
for key,val of attribs
switch key
when 'columns'
- data['columns'] = new StoredSheet.Collections.Columns(val)
+ if @columns
+ data['columns'] = @columns.parse(val)
+ else
+ data['columns'] = new StoredSheet.Collections.Columns(val)
when 'rows'
- data['rows'] = new StoredSheet.Collections.Rows(val)
+ if @rows
+ data['rows'] = @rows.parse(val)
+ else
+ data['rows'] = new StoredSheet.Collections.Rows(val)
else
data[key] = val
return data
@@ -30,7 +30,7 @@
end
describe "PUT 'update'" do
- xit "returns http success" do
+ it "returns http success" do
put :update, { id: @sheet.id, sheet: {} }
response.should be_success
end
@@ -134,6 +134,38 @@ describe "Sheet", ->
row3.set {Field1: 'froggies'}
# expect(row3.changedAttributes()).toEqual ['Field1']
+ it "should properly parse new data into existing sheet", ->
+ jsonnewvals = {
+ id : 'decaf00004',
+ sheet_name : 'Example Sheet',
+ columns : [
+ { id : 'decaf00001', name : 'A', num : 1, field : 'Field1', width : 100 },
+ { id : 'decaf00002', name : 'B', num : 2, field : 'Field2', width : 150 },
+ { id : 'decaf00003', name : 'C', num : 3, field : 'Field3', width : 100 }
+ ],
+ rows : [
+ { id : 'decaf00005', Field1 : 'kitties' },
+ { id : 'decaf00006', Field2 : 'birdies' },
+ { id : 'decaf00007', Field3 : 'froggies' }
+ ]
+ }
+ sht2 = new StoredSheet.Models.Sheet(@samplesheet)
+ expect(sht2.get('columns').at(1).get('width')).toEqual 100
+ expect(sht2.get('rows').at(1).get('Field1')?).toBeFalsy()
+ expect(sht2.get('rows').at(1).get('Field2')?).toBeFalsy()
+
+ sht2.get('columns').at(0).width = 80
+ sht2.get('rows').at(1).set {Field1: 'banana'}
+ setsuccessful = sht2.set(sht2.parse(jsonnewvals))
+
+ expect(setsuccessful).toBeTruthy()
+ expect(sht2.get('columns').at(0).get('width')).toEqual 80
+ expect(sht2.get('columns').at(1).get('width')).toEqual 150
+ expect(sht2.get('rows').at(0).get('Field1')).toEqual 'kitties'
+ expect(sht2.get('rows').at(1).get('Field1')).toEqual 'banana'
+ expect(sht2.get('rows').at(1).get('Field2')).toEqual 'birdies'
+ expect(sht2.get('rows').at(2).get('Field3')).toEqual 'froggies'
+
describe "saving & fetching", ->
beforeEach ->
jasmine.Ajax.useMock()
@@ -143,7 +143,7 @@ def fill_default_sheet sht
visit sheet_path(@sheet)
fill_in 'sheet_name', with: 'Leaping Frog Bellies'
click_button 'Save'
- page.find('.status').text.should == 'OK' # This seems to have been necessary because I think it makes the test engine wait for the save to finish; sometimes
+ page.find('.status').text.should == 'OK' # This seems to have been necessary because I think it makes the test engine wait for the save to finish; sometimes - still intermittently fails (usually when first test)
savedsheet = Sheet.find(@sheet.id)
savedsheet.sheet_name.should == 'Leaping Frog Bellies'
visit sheet_path(@sheet)
@@ -163,8 +163,7 @@ def fill_default_sheet sht
savedsheet[0,0].should == 'Apple Berries'
end
- it "should see server updates on save" do
- pending "not ready for source control/multithreading thoughts yet"
+ it "should see server updates on save (different cells)" do
visit sheet_path(@sheet)
page.find('.slick-row[row="1"] .slick-cell.l1').should have_content('eee')
cel00 = page.find('.slick-row[row="0"] .slick-cell.l0')
@@ -175,13 +174,27 @@ def fill_default_sheet sht
@sheet[1,1] = 'Frosted Flakes'
@sheet.save
click_button 'Save'
- page.find('.status').text.should == 'success'
+ page.find('.status').text.should == 'OK'
savedsheet = Sheet.find(@sheet.id)
savedsheet[0,0].should == 'Apple Berries'
savedsheet[1,1].should == 'Frosted Flakes'
page.find('.slick-row[row="1"] .slick-cell.l1').should have_content('Frosted Flakes')
end
+ it "should do something appropriate about 2 edits to same cell" do
+ visit sheet_path(@sheet)
+ cel00 = page.find('.slick-row[row="0"] .slick-cell.l0')
+ cel00.should have_content('aaa')
+ cel00.click
+ page.find('input.editor-text').set('Apple Berries')
+ page.find('.slick-row[row="0"] .slick-cell.l1').click
+ @sheet[0,0] = 'Banana Berries'
+ @sheet.save
+ click_button 'Save'
+ pending "dunno right response"
+ end
+
+
end
end

0 comments on commit 7979582

Please sign in to comment.