Skip to content

Commit

Permalink
fix: send content-type header
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirk Grappendorf committed Sep 8, 2015
1 parent ac8b903 commit 78c1dd4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion grapp-rest-resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@
_prepareHeaders: function() {
var h, key, ref, val;
h = {
'Accept': 'application/json'
'Accept': 'application/json',
'Content-Type': 'application/json'
};
ref = this.headers;
for (key in ref) {
Expand Down
2 changes: 1 addition & 1 deletion src/grapp-rest-resource.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Polymer
url

_prepareHeaders: ->
h = {'Accept': 'application/json'}
h = {'Accept': 'application/json', 'Content-Type': 'application/json'}
for key, val of @headers
h[key] = val
h['Authorization'] = @token if @token
Expand Down
14 changes: 13 additions & 1 deletion test/headers.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
</head>
<body>

<grapp-rest-resource id="element" url="http://api.example.com"></grapp-rest-resource>

<grapp-rest-resource id="element_with_headers" url="http://api.example.com"
headers='{"foo":123}'></grapp-rest-resource>

Expand All @@ -22,14 +24,24 @@

<script type="text/coffeescript">

describe 'default hedaers', ->

it 'sends accept and content type headers', ->
element = document.querySelector '#element'
xhr_request = sinon.stub().returns new Promise(->)
sinon.stub(element, '_createRequestElement').returns {send: xhr_request}
element.resource.index()
expect(xhr_request).to.have.been.calledWith sinon.match {
headers: {'Accept': 'application/json', 'Content-Type': 'application/json'}}

describe 'with defined hedaers attribute ', ->

it 'sends the custom headers', ->
element = document.querySelector '#element_with_headers'
xhr_request = sinon.stub().returns new Promise(->)
sinon.stub(element, '_createRequestElement').returns {send: xhr_request}
element.resource.index()
expect(xhr_request).to.have.been.calledWith sinon.match {headers: {Accept: 'application/json', foo: 123}}
expect(xhr_request).to.have.been.calledWith sinon.match {headers: {foo: 123}}

describe 'with defined token attribute ', ->

Expand Down

0 comments on commit 78c1dd4

Please sign in to comment.