Patch #13468

REST API for News

Added by C. X. over 6 years ago. Updated about 1 month ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:REST API
Target version:4.1.0

Description

Some small changes for supporting news creation over REST.

news.patch Magnifier (1.32 KB) C. X., 2013-03-13 18:52

news-creating-via-api.patch Magnifier (7.1 KB) Takenori TAKAKI, 2019-03-29 07:33

0002-news-getting-via-api.patch Magnifier (4.71 KB) Takenori TAKAKI, 2019-04-04 17:07

0001-news-creating-via-api.patch Magnifier (7.48 KB) Takenori TAKAKI, 2019-04-04 17:07

0003-news-deleting-via-api.patch Magnifier (2.08 KB) Takenori TAKAKI, 2019-04-04 17:07

0004-news-updating-via-api.patch Magnifier (5.65 KB) Takenori TAKAKI, 2019-04-04 17:07


Related issues

Related to Redmine - Feature #26653: REST API - Add full CRUD support for News Closed

Associated revisions

Revision 18440
Added by Go MAEDA about 1 month ago

REST API for creating news (#13468).

Patch by Takenori TAKAKI.

Revision 18441
Added by Go MAEDA about 1 month ago

REST API for retrieving news (#13468).

Patch by Takenori TAKAKI.

Revision 18442
Added by Go MAEDA about 1 month ago

REST API for deleting news (#13468).

Patch by Takenori TAKAKI.

Revision 18443
Added by Go MAEDA about 1 month ago

REST API for updating news (#13468).

Patch by Takenori TAKAKI.

Revision 18445
Added by Go MAEDA about 1 month ago

Fix that Redmine::ApiTest::NewsTest fails when config.time_zone is set (#13468).

Patch by Yuichi HARADA.

Revision 18455
Added by Go MAEDA about 1 month ago

Add missing fixture (#13468).

History

#1 Updated by Mischa The Evil over 6 years ago

  • Category set to REST API

#2 Updated by Go MAEDA about 2 years ago

  • Related to Feature #26653: REST API - Add full CRUD support for News added

#3 Updated by Jesse Hopkins over 1 year ago

+1

#4 Updated by Guillaume Masclet over 1 year ago

Hi, is this patch planned to be merged in an upcoming release ?
This would be great as I have to make a few dozen announcements each month on some of the projects I manage with Redmine. This is really tedious without automation.

#5 Updated by Takenori TAKAKI 7 months ago

I made a patch with small changes and tests to the C. X.'s patch.
I'm looking forward to using this feature in future Redmine.

#6 Updated by Go MAEDA 7 months ago

  • Target version set to Candidate for next major release

#7 Updated by Go MAEDA 7 months ago

It looks a bit awkward to me to implement POST only without implementing GET, PUT, and DELETE. I think that GET should be implemented at least.

With the current patch implemented, users can create news but they don't have the means to retrieve the news using an id.

#8 Updated by Takenori TAKAKI 7 months ago

Go MAEDA wrote:

It looks a bit awkward to me to implement POST only without implementing GET, PUT, and DELETE. I think that GET should be implemented at least.

Certainly, that is more beautiful as an API design.
I made a patch so that POST, GET, DELETE and PUT functions can be added gradually.

#9 Updated by Go MAEDA 6 months ago

  • Target version changed from Candidate for next major release to 4.1.0

#10 Updated by Go MAEDA 6 months ago

  • Target version deleted (4.1.0)

#11 Updated by Go MAEDA 4 months ago

  • Target version set to 4.1.0

#12 Updated by vzvu 3k6k about 1 month ago

+1, Takaki's patches look good to me.

#13 Updated by Go MAEDA about 1 month ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the patches. Thank you for your contribution. And vzvu 3k6k, thank you for reviewing the patches. Your review is very helpful to me.

#14 Updated by Go MAEDA about 1 month ago

  • Subject changed from News creation over REST to REST API for News

#15 Updated by Yuichi HARADA about 1 month ago

Redmine::ApiTest::NewsTest#test_GET_/news/:id.xml fails if config.time_zone is set.

Set config.time_zone in config/additional_environment.rb.

config.time_zone = 'Tokyo'

The tests suppose that time in API response is always in UTC, but it varies depending on the value of config.time_zone is set.

$ RAILS_ENV=test bundle exec rake test TEST=test/integration/api_test/news_test.rb
Run options: --seed 35340

# Running:

...................F

Failure:
Redmine::ApiTest::NewsTest#test_GET_/news/:id.xml [test/integration/api_test/news_test.rb:69]:
<(?-mix:^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$)> expected but was
<2006-07-20T05:40:26+09:00>..
Expected 0 to be >= 1.

bin/rails test test/integration/api_test/news_test.rb:65

...

Finished in 1.647332s, 13.9620 runs/s, 75.2732 assertions/s.
23 runs, 124 assertions, 1 failures, 0 errors, 0 skips

The following patch will solve it.

diff --git a/test/integration/api_test/news_test.rb b/test/integration/api_test/news_test.rb
index a6ca416a8..a7fccf9b6 100644
--- a/test/integration/api_test/news_test.rb
+++ b/test/integration/api_test/news_test.rb
@@ -73,8 +73,7 @@ class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
       assert_select 'title', 'eCookbook first release !'
       assert_select 'summary', 'First version was released...'
       assert_select 'description', "eCookbook 1.0 has been released.\n\nVisit http://ecookbook.somenet.foo/" 
-      iso_date = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/
-      assert_select 'news>created_on', :text => iso_date
+      assert_select 'created_on', News.find(1).created_on.iso8601
     end
   end

#16 Updated by Go MAEDA about 1 month ago

Yuichi HARADA wrote:

Redmine::ApiTest::NewsTest#test_GET_/news/:id.xml fails if config.time_zone is set.

Committed the fix in r18445. Thank you for reporting and fixing it.

#17 Updated by vzvu 3k6k about 1 month ago

Sorry, I should have run tests locally before commenting.
Thanks for fixing.

#18 Updated by Go MAEDA about 1 month ago

  • Status changed from Closed to Reopened

The test fails due to a missing fixture.

$ RAILS_ENV=test bin/rake db:reset
$ bin/rails test test/integration/api_test/news_test.rb:88
Run options: --seed 61590

# Running:

E

Error:
Redmine::ApiTest::NewsTest#test_GET_/news/:id.xml_with_attachments:
NoMethodError: undefined method `container=' for nil:NilClass
Did you mean?  concern
    test/integration/api_test/news_test.rb:91:in `block in <class:NewsTest>'

It can be fixed with the following patch.

Index: test/integration/api_test/news_test.rb
===================================================================
--- test/integration/api_test/news_test.rb    (リビジョン 18453)
+++ test/integration/api_test/news_test.rb    (作業コピー)
@@ -28,7 +28,8 @@
            :members,
            :enabled_modules,
            :news,
-           :comments
+           :comments,
+           :attachments

   test "GET /news.xml should return news" do
     get '/news.xml'

#19 Updated by Go MAEDA about 1 month ago

  • Status changed from Reopened to Closed

Go MAEDA wrote:

The test fails due to a missing fixture.

Committed in r18455.

Also available in: Atom PDF