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({
model() {
return Discourse.ajax("/admin/plugins.json");
return Discourse.ajax("/admin/plugins.json").then(res => res.plugins);
},
actions: {

View File

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

View File

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

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