From 0aa521e50238b8d322cc67c7ad6edfedd4ab4009 Mon Sep 17 00:00:00 2001 From: Jesse Stuart Date: Mon, 17 Sep 2012 10:03:41 -0400 Subject: [PATCH] POST /posts & PUT /posts/:id can set Post#views --- lib/tentd/api/posts.rb | 2 +- lib/tentd/model/post.rb | 2 +- spec/integration/api/posts_spec.rb | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/tentd/api/posts.rb b/lib/tentd/api/posts.rb index 79a38a4..dbb2c84 100644 --- a/lib/tentd/api/posts.rb +++ b/lib/tentd/api/posts.rb @@ -193,7 +193,7 @@ def action(env) authorize_env!(env, :write_posts) if post = TentD::Model::Post.first(:id => env.params.post_id) version = post.latest_version(:fields => [:id]) - post.update(env.params.data.slice(:content, :licenses, :mentions)) + post.update(env.params.data.slice(:content, :licenses, :mentions, :views)) if env.params.attachments.kind_of?(Array) Model::PostAttachment.all(:post_id => post.id).update(:post_id => nil, :post_version_id => version.id) diff --git a/lib/tentd/model/post.rb b/lib/tentd/model/post.rb index ce1d97f..fcd4774 100644 --- a/lib/tentd/model/post.rb +++ b/lib/tentd/model/post.rb @@ -127,7 +127,7 @@ def self.public_attributes end def self.write_attributes - public_attributes + [:known_entity, :original, :public, :mentions] + public_attributes + [:known_entity, :original, :public, :mentions, :views] end def can_notify?(app_or_follow) diff --git a/spec/integration/api/posts_spec.rb b/spec/integration/api/posts_spec.rb index f4e085e..b8964fd 100644 --- a/spec/integration/api/posts_spec.rb +++ b/spec/integration/api/posts_spec.rb @@ -454,6 +454,27 @@ def authorize!(*scopes) expect(body['app']).to eq('url' => application.url, 'name' => application.name) end + it 'should create post with views' do + post_attributes = p.attributes + post_attributes.delete(:id) + post_attributes[:type] = p.type.uri + post_attributes[:views] = { + 'mini' => { + 'content' => ['mini_text', 'title'] + } + } + + expect(lambda { + expect(lambda { + json_post "/posts", post_attributes, env + expect(last_response.status).to eq(200) + }).to change(TentD::Model::Post, :count).by(1) + }).to change(TentD::Model::PostVersion, :count).by(1) + post = TentD::Model::Post.last + + expect(post.views).to eq(post_attributes[:views]) + end + it 'should create post with mentions' do post_attributes = Hashie::Mash.new(p.attributes) post_attributes.delete(:id) @@ -688,6 +709,9 @@ def authorize!(*scopes) :content => { "text" => "Foo Bar Baz" }, + :views => { + 'mini' => { 'content' => ['mini_text'] } + }, :entity => "#{post.entity}/foo/bar", :public => !post.public, :licenses => post.licenses.to_a + ['https://license.example.org'] @@ -702,6 +726,7 @@ def authorize!(*scopes) post.reload expect(post.content).to eq(post_attributes[:content]) expect(post.licenses).to eq(post_attributes[:licenses]) + expect(post.views).to eq(post_attributes[:views]) expect(post.public).to_not eq(post_attributes[:public]) expect(post.entity).to_not eq(post_attributes[:entity]) }).to change(post.versions, :count).by(1)