mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-22 05:22:33 -05:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
57 lines
1.6 KiB
Ruby
57 lines
1.6 KiB
Ruby
require 'rails_helper'
|
|
require_dependency 'post_enqueuer'
|
|
|
|
describe UserActionsController do
|
|
context 'index' do
|
|
|
|
it 'fails if username is not specified' do
|
|
expect { xhr :get, :index }.to raise_error
|
|
end
|
|
|
|
it 'renders list correctly' do
|
|
ActiveRecord::Base.observers.enable :all
|
|
post = Fabricate(:post)
|
|
|
|
xhr :get, :index, username: post.user.username
|
|
|
|
expect(response.status).to eq(200)
|
|
parsed = JSON.parse(response.body)
|
|
actions = parsed["user_actions"]
|
|
expect(actions.length).to eq(1)
|
|
action = actions[0]
|
|
expect(action["acting_name"]).to eq(post.user.name)
|
|
expect(action["email"]).to eq(nil)
|
|
expect(action["post_number"]).to eq(1)
|
|
end
|
|
|
|
context "queued posts" do
|
|
context "without access" do
|
|
let(:user) { Fabricate(:user) }
|
|
it "raises an exception" do
|
|
xhr :get, :index, username: user.username, filter: UserAction::PENDING
|
|
expect(response).to_not be_success
|
|
|
|
end
|
|
end
|
|
|
|
context "with access" do
|
|
let(:user) { log_in }
|
|
|
|
it 'finds queued posts' do
|
|
queued_post = PostEnqueuer.new(user, 'default').enqueue(raw: 'this is the raw enqueued content')
|
|
|
|
xhr :get, :index, username: user.username, filter: UserAction::PENDING
|
|
|
|
expect(response.status).to eq(200)
|
|
parsed = JSON.parse(response.body)
|
|
actions = parsed["user_actions"]
|
|
expect(actions.length).to eq(1)
|
|
|
|
action = actions.first
|
|
expect(action['username']).to eq(user.username)
|
|
expect(action['excerpt']).to be_present
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|