Skip to content

Commit

Permalink
try to fix fetch/parse client-side sheet - partly fixed; still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
laripk committed Nov 2, 2011
1 parent 20442a3 commit 7979582
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/backbone/models/column.js.coffee
Expand Up @@ -19,7 +19,7 @@ class StoredSheet.Models.Column # extends Backbone.Model
return data return data
get: (item) -> get: (item) ->
this[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) _.extend(StoredSheet.Models.Column.prototype, Backbone.Events)


class StoredSheet.Collections.Columns extends Backbone.Collection class StoredSheet.Collections.Columns extends Backbone.Collection
Expand Down
10 changes: 8 additions & 2 deletions app/assets/javascripts/backbone/models/sheet.js.coffee
Expand Up @@ -14,9 +14,15 @@ class StoredSheet.Models.Sheet extends Backbone.Model
for key,val of attribs for key,val of attribs
switch key switch key
when 'columns' 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' 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 else
data[key] = val data[key] = val
return data return data
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/sheets_controller_spec.rb
Expand Up @@ -30,7 +30,7 @@
end end


describe "PUT 'update'" do describe "PUT 'update'" do
xit "returns http success" do it "returns http success" do
put :update, { id: @sheet.id, sheet: {} } put :update, { id: @sheet.id, sheet: {} }
response.should be_success response.should be_success
end end
Expand Down
32 changes: 32 additions & 0 deletions spec/javascripts/backbone/models/sheet_spec.js.coffee
Expand Up @@ -134,6 +134,38 @@ describe "Sheet", ->
row3.set {Field1: 'froggies'} row3.set {Field1: 'froggies'}
# expect(row3.changedAttributes()).toEqual ['Field1'] # 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", -> describe "saving & fetching", ->
beforeEach -> beforeEach ->
jasmine.Ajax.useMock() jasmine.Ajax.useMock()
Expand Down
21 changes: 17 additions & 4 deletions spec/requests/sheets_spec.rb
Expand Up @@ -143,7 +143,7 @@ def fill_default_sheet sht
visit sheet_path(@sheet) visit sheet_path(@sheet)
fill_in 'sheet_name', with: 'Leaping Frog Bellies' fill_in 'sheet_name', with: 'Leaping Frog Bellies'
click_button 'Save' 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.find(@sheet.id)
savedsheet.sheet_name.should == 'Leaping Frog Bellies' savedsheet.sheet_name.should == 'Leaping Frog Bellies'
visit sheet_path(@sheet) visit sheet_path(@sheet)
Expand All @@ -163,8 +163,7 @@ def fill_default_sheet sht
savedsheet[0,0].should == 'Apple Berries' savedsheet[0,0].should == 'Apple Berries'
end end


it "should see server updates on save" do it "should see server updates on save (different cells)" do
pending "not ready for source control/multithreading thoughts yet"
visit sheet_path(@sheet) visit sheet_path(@sheet)
page.find('.slick-row[row="1"] .slick-cell.l1').should have_content('eee') page.find('.slick-row[row="1"] .slick-cell.l1').should have_content('eee')
cel00 = page.find('.slick-row[row="0"] .slick-cell.l0') cel00 = page.find('.slick-row[row="0"] .slick-cell.l0')
Expand All @@ -175,13 +174,27 @@ def fill_default_sheet sht
@sheet[1,1] = 'Frosted Flakes' @sheet[1,1] = 'Frosted Flakes'
@sheet.save @sheet.save
click_button 'Save' click_button 'Save'
page.find('.status').text.should == 'success' page.find('.status').text.should == 'OK'
savedsheet = Sheet.find(@sheet.id) savedsheet = Sheet.find(@sheet.id)
savedsheet[0,0].should == 'Apple Berries' savedsheet[0,0].should == 'Apple Berries'
savedsheet[1,1].should == 'Frosted Flakes' savedsheet[1,1].should == 'Frosted Flakes'
page.find('.slick-row[row="1"] .slick-cell.l1').should have_content('Frosted Flakes') page.find('.slick-row[row="1"] .slick-cell.l1').should have_content('Frosted Flakes')
end 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


end end
Expand Down

0 comments on commit 7979582

Please sign in to comment.