Commit bf8b50ac1b74a12afcc31213cc0e8b0bab643a5e

Authored by Ábner Oliveira
1 parent 428991c1

fixed article creation

src/app/cms/cms.component.spec.ts
... ... @@ -22,7 +22,7 @@ describe("Components", () => {
22 22 $state = jasmine.createSpyObj("$state", ["transitionTo"]);
23 23 notification = jasmine.createSpyObj("notification", ["success"]);
24 24 profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile"]);
25   - articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["create"]);
  25 + articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["createInProfile"]);
26 26  
27 27 let getCurrentProfileResponse = $q.defer();
28 28 getCurrentProfileResponse.resolve(profile);
... ... @@ -31,7 +31,7 @@ describe("Components", () => {
31 31 articleCreate.resolve({ data: { path: "path", profile: { identifier: "profile" } }});
32 32  
33 33 profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise);
34   - articleServiceMock.create = jasmine.createSpy("create").and.returnValue(articleCreate.promise);
  34 + articleServiceMock.createInProfile = jasmine.createSpy("createInProfile").and.returnValue(articleCreate.promise);
35 35 });
36 36  
37 37 it("create an article in the current profile when save", done => {
... ... @@ -39,7 +39,7 @@ describe("Components", () => {
39 39 component.save();
40 40 $rootScope.$apply();
41 41 expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled();
42   - expect(articleServiceMock.create).toHaveBeenCalledWith(component.article, profile);
  42 + expect(articleServiceMock.createInProfile).toHaveBeenCalledWith(profile, component.article);
43 43 done();
44 44 });
45 45  
... ...
src/app/cms/cms.component.ts
... ... @@ -24,7 +24,7 @@ export class Cms {
24 24  
25 25 save() {
26 26 this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
27   - return this.articleService.create(this.article, profile);
  27 + return this.articleService.createInProfile(profile, this.article);
28 28 }).then((response: noosfero.RestResult<noosfero.Article>) => {
29 29 let article = (<noosfero.Article>response.data);
30 30 this.$state.transitionTo('main.profile.page', { page: article.path, profile: article.profile.identifier });
... ...
src/lib/ng-noosfero-api/http/article.service.ts
... ... @@ -26,8 +26,10 @@ export class ArticleService extends RestangularService&lt;noosfero.Article&gt; {
26 26 createInProfile(profile: noosfero.Profile, article: noosfero.Article): ng.IPromise<noosfero.RestResult<noosfero.Article>> {
27 27 let profileElement = this.profileService.get(<number>profile.id);
28 28 (<any>profileElement).id = profile.id;
29   - debugger;
30   - return this.create(article, <noosfero.RestModel>profileElement);
  29 + let headers = {
  30 + 'Content-Type': 'application/json'
  31 + }
  32 + return this.create(article, <noosfero.RestModel>profileElement, null, headers);
31 33 }
32 34  
33 35  
... ...