- Test host name extraction (#183)

  • Test host name extraction (#183)
diff --git a/spec/discourse_api/api/api_key_spec.rb b/spec/discourse_api/api/api_key_spec.rb
index 4046bd1..c3cc710 100644
--- a/spec/discourse_api/api/api_key_spec.rb
+++ b/spec/discourse_api/api/api_key_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
 describe DiscourseApi::API::ApiKey do
   subject {
     DiscourseApi::Client.new(
-      "http://localhost:3000",
+      "#{host}",
       "test_d7fd0429940",
       "test_user"
     )
@@ -11,14 +11,14 @@ describe DiscourseApi::API::ApiKey do
 
   describe "#api" do
     before do
-      url = "http://localhost:3000/admin/api.json"
+      url = "#{host}/admin/api.json"
       stub_get(url).to_return(body: fixture("api.json"),
                               headers: { content_type: "application/json" })
     end
 
     it "requests the correct resource" do
       subject.api
-      url = "http://localhost:3000/admin/api.json"
+      url = "#{host}/admin/api.json"
       expect(a_get(url)).to have_been_made
     end
 
@@ -32,7 +32,7 @@ describe DiscourseApi::API::ApiKey do
 
   describe "#generate_user_api_key" do
     before do
-      url = "http://localhost:3000/admin/users/2/generate_api_key.json"
+      url = "#{host}/admin/users/2/generate_api_key.json"
       stub_post(url).to_return(body: fixture("generate_api_key.json"),
                                headers: { content_type: "application/json" })
     end
@@ -46,7 +46,7 @@ describe DiscourseApi::API::ApiKey do
 
   describe "#revoke_user_api_key" do
     before do
-      url = "http://localhost:3000/admin/users/2/revoke_api_key.json"
+      url = "#{host}/admin/users/2/revoke_api_key.json"
       stub_delete(url).to_return(body: "",
       headers: { content_type: "application/json" })
     end
@@ -59,7 +59,7 @@ describe DiscourseApi::API::ApiKey do
 
   describe "#generate_master_key" do
     before do
-      url = "http://localhost:3000/admin/api/key"
+      url = "#{host}/admin/api/key"
       stub_post(url).to_return(body: fixture("generate_master_key.json"),
                                headers: { content_type: "application/json" })
     end
@@ -74,14 +74,14 @@ describe DiscourseApi::API::ApiKey do
 
   describe "#revoke_api_key" do
     before do
-      url = "http://localhost:3000/admin/api/key?id=10"
+      url = "#{host}/admin/api/key?id=10"
       stub_delete(url).to_return(body: "",
                                  headers: { content_type: "application/json" })
     end
 
     it "requests the correct resource" do
       subject.revoke_api_key(10)
-      url = "http://localhost:3000/admin/api/key?id=10"
+      url = "#{host}/admin/api/key?id=10"
       expect(a_delete(url)).to have_been_made
     end
 
@@ -93,14 +93,14 @@ describe DiscourseApi::API::ApiKey do
 
   describe "#regenerate_api_key" do
     before do
-      url = "http://localhost:3000/admin/api/key"
+      url = "#{host}/admin/api/key"
       stub_put(url).to_return(body: fixture("regenerate_api_key.json"),
                                  headers: { content_type: "application/json" })
     end
 
     it "requests the correct resource" do
       subject.regenerate_api_key(10)
-      url = "http://localhost:3000/admin/api/key"
+      url = "#{host}/admin/api/key"
       expect(a_put(url)).to have_been_made
     end
 
diff --git a/spec/discourse_api/api/backups_spec.rb b/spec/discourse_api/api/backups_spec.rb
index f6509ee..5b0f658 100644
--- a/spec/discourse_api/api/backups_spec.rb
+++ b/spec/discourse_api/api/backups_spec.rb
@@ -1,16 +1,16 @@
 require 'spec_helper'
 
 describe DiscourseApi::API::Backups do
-  subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
+  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
 
   describe "#backups" do
     before do
-      stub_get("http://localhost:3000/admin/backups.json").to_return(body: fixture("backups.json"), headers: { content_type: "application/json" })
+      stub_get("#{host}/admin/backups.json").to_return(body: fixture("backups.json"), headers: { content_type: "application/json" })
     end
 
     it "requests the correct resource" do
       subject.backups
-      expect(a_get("http://localhost:3000/admin/backups.json")).to have_been_made
+      expect(a_get("#{host}/admin/backups.json")).to have_been_made
     end
 
     it "returns the requested backups" do
diff --git a/spec/discourse_api/api/badges_spec.rb b/spec/discourse_api/api/badges_spec.rb
index a256988..45ba708 100644
--- a/spec/discourse_api/api/badges_spec.rb
+++ b/spec/discourse_api/api/badges_spec.rb
@@ -1,16 +1,16 @@
 require 'spec_helper'
 
 describe DiscourseApi::API::Badges do
-  subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
+  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
 
   describe "#badges" do
     before do
-      stub_get("http://localhost:3000/admin/badges.json").to_return(body: fixture("badges.json"), headers: { content_type: "application/json" })
+      stub_get("#{host}/admin/badges.json").to_return(body: fixture("badges.json"), headers: { content_type: "application/json" })
     end
 
     it "requests the correct resource" do
       subject.badges
-      expect(a_get("http://localhost:3000/admin/badges.json")).to have_been_made
+      expect(a_get("#{host}/admin/badges.json")).to have_been_made
     end
 
     it "returns the requested badges" do
@@ -22,12 +22,12 @@ describe DiscourseApi::API::Badges do
 
   describe "#user-badges" do
     before do
-      stub_get("http://localhost:3000/user-badges/test_user.json").to_return(body: fixture("user_badges.json"), headers: { content_type: "application/json" })
+      stub_get("#{host}/user-badges/test_user.json").to_return(body: fixture("user_badges.json"), headers: { content_type: "application/json" })
     end
 
     it "requests the correct resource" do
       subject.user_badges('test_user')
-      expect(a_get("http://localhost:3000/user-badges/test_user.json")).to have_been_made
+      expect(a_get("#{host}/user-badges/test_user.json")).to have_been_made
     end
 
     it "returns the requested user badges" do
diff --git a/spec/discourse_api/api/categories_spec.rb b/spec/discourse_api/api/categories_spec.rb
index e8344ff..2fc6e93 100644
--- a/spec/discourse_api/api/categories_spec.rb
+++ b/spec/discourse_api/api/categories_spec.rb
@@ -1,17 +1,17 @@
 require 'spec_helper'
 
 describe DiscourseApi::API::Categories do
-  subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
+  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
 
   describe "#categories" do
     before do
-      stub_get("http://localhost:3000/categories.json")
+      stub_get("#{host}/categories.json")
         .to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
     end
 
     it "requests the correct resource" do
       subject.categories
-      expect(a_get("http://localhost:3000/categories.json")).to have_been_made
+      expect(a_get("#{host}/categories.json")).to have_been_made
     end
 
     it "returns the requested categories" do
@@ -29,7 +29,7 @@ describe DiscourseApi::API::Categories do
 
   describe '#category_latest_topics' do
     before do
-      stub_get("http://localhost:3000/c/category-slug/l/latest.json")
+      stub_get("#{host}/c/category-slug/l/latest.json")
         .to_return(body: fixture("category_latest_topics.json"), headers: { content_type: "application/json" })
     end
 
@@ -41,7 +41,7 @@ describe DiscourseApi::API::Categories do
 
   describe '#category_top_topics' do
     before do
-      stub_get("http://localhost:3000/c/category-slug/l/top.json")
+      stub_get("#{host}/c/category-slug/l/top.json")
       .to_return(
         body: fixture("category_topics.json"), 
         headers: { content_type: "application/json" }
@@ -56,7 +56,7 @@ describe DiscourseApi::API::Categories do
 
   describe '#category_new_topics' do
     before do

[... diff too long, it was truncated ...]

GitHub sha: b6eded41

2 Likes