Add a spec for the new plugins controller

This commit is contained in:
Robin Ward 2015-02-10 11:18:16 -05:00
parent 0ce6524153
commit 8d46de4819
4 changed files with 28 additions and 12 deletions

View File

@ -1,6 +1,6 @@
export default Ember.Route.extend({ export default Ember.Route.extend({
model() { model() {
return Discourse.ajax("/admin/plugins.json"); return Discourse.ajax("/admin/plugins.json").then(res => res.plugins);
}, },
actions: { actions: {

View File

@ -1,8 +1,7 @@
class Admin::PluginsController < Admin::AdminController class Admin::PluginsController < Admin::AdminController
def index def index
# json = Discourse.plugins.map(&:metadata) render_serialized(Discourse.plugins, AdminPluginSerializer, root: 'plugins')
render_serialized(Discourse.plugins, AdminPluginSerializer)
end end
end end

View File

@ -85,12 +85,11 @@ module Discourse
end end
def self.disabled_plugin_names def self.disabled_plugin_names
return [] if @plugins.blank? plugins.select {|p| !p.enabled?}.map(&:name)
@plugins.select {|p| !p.enabled?}.map(&:name)
end end
def self.plugins def self.plugins
@plugins @plugins ||= []
end end
def self.assets_digest def self.assets_digest
@ -119,14 +118,12 @@ module Discourse
def self.auth_providers def self.auth_providers
providers = [] providers = []
if plugins
plugins.each do |p| plugins.each do |p|
next unless p.auth_providers next unless p.auth_providers
p.auth_providers.each do |prov| p.auth_providers.each do |prov|
providers << prov providers << prov
end end
end end
end
providers providers
end end

View File

@ -0,0 +1,20 @@
require 'spec_helper'
describe Admin::PluginsController do
it "is a subclass of AdminController" do
expect(Admin::PluginsController < Admin::AdminController).to eq(true)
end
context "while logged in as an admin" do
let!(:admin) { log_in(:admin) }
it 'should return JSON' do
xhr :get, :index
response.should be_success
::JSON.parse(response.body).has_key?('plugins').should == true
end
end
end