Skip to content
This repository has been archived by the owner on Feb 16, 2018. It is now read-only.

Commit

Permalink
POST /posts & PUT /posts/:id can set Post#views
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Stuart committed Sep 17, 2012
1 parent d06915c commit 0aa521e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/tentd/api/posts.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/tentd/model/post.rb
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions spec/integration/api/posts_spec.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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']
Expand All @@ -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)
Expand Down

0 comments on commit 0aa521e

Please sign in to comment.