about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorutam0k <k0ma@utam0k.jp>2017-10-04 22:16:10 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-10-04 15:16:10 +0200
commitb3af3f9f8cd5ed9c7ee06452e981b1b7734e1d89 (patch)
tree8ea106d91d77f83a1c0b368d8657203c544e7eca /spec
parentd5091387c6ddbe03b118b0cfb6d74cf821b84fb2 (diff)
Implement EmailBlackList (#5109)
* Implement BlacklistedEmailDomain

* Use Faker::Internet.domain_name

* Remove note column

* Add frozen_string_literal comment

* Delete unnecessary codes

* Sort alphabetically

* Change of wording

* Rename BlacklistedEmailDomain to EmailDomainBlock
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin/email_domain_blocks_controller_spec.rb59
-rw-r--r--spec/fabricators/email_domain_block_fabricator.rb3
-rw-r--r--spec/models/email_domain_block_spec.rb21
3 files changed, 83 insertions, 0 deletions
diff --git a/spec/controllers/admin/email_domain_blocks_controller_spec.rb b/spec/controllers/admin/email_domain_blocks_controller_spec.rb
new file mode 100644
index 000000000..295de9073
--- /dev/null
+++ b/spec/controllers/admin/email_domain_blocks_controller_spec.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Admin::EmailDomainBlocksController, type: :controller do
+  render_views
+
+  before do
+    sign_in Fabricate(:user, admin: true), scope: :user
+  end
+
+  describe 'GET #index' do
+    around do |example|
+      default_per_page = EmailDomainBlock.default_per_page
+      EmailDomainBlock.paginates_per 1
+      example.run
+      EmailDomainBlock.paginates_per default_per_page
+    end
+
+    it 'renders email blacks' do
+      2.times { Fabricate(:email_domain_block) }
+
+      get :index, params: { page: 2 }
+
+      assigned = assigns(:email_domain_blocks)
+      expect(assigned.count).to eq 1
+      expect(assigned.klass).to be EmailDomainBlock
+      expect(response).to have_http_status(:success)
+    end
+  end
+
+  describe 'GET #new' do
+    it 'assigns a new email black' do
+      get :new
+
+      expect(assigns(:email_domain_block)).to be_instance_of(EmailDomainBlock)
+      expect(response).to have_http_status(:success)
+    end
+  end
+
+  describe 'POST #create' do
+    it 'blocks the domain when succeeded to save' do
+      post :create, params: { email_domain_block: { domain: 'example.com'} }
+
+      expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.created_msg')
+      expect(response).to redirect_to(admin_email_domain_blocks_path)
+    end
+  end
+
+  describe 'DELETE #destroy' do
+    it 'unblocks the domain' do
+      email_domain_block = Fabricate(:email_domain_block)
+      delete :destroy, params: { id: email_domain_block.id } 
+
+      expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.destroyed_msg')
+      expect(response).to redirect_to(admin_email_domain_blocks_path)
+    end
+  end
+end
diff --git a/spec/fabricators/email_domain_block_fabricator.rb b/spec/fabricators/email_domain_block_fabricator.rb
new file mode 100644
index 000000000..d18af6433
--- /dev/null
+++ b/spec/fabricators/email_domain_block_fabricator.rb
@@ -0,0 +1,3 @@
+Fabricator(:email_domain_block) do
+  domain { sequence(:domain) { |i| "#{i}#{Faker::Internet.domain_name}" } }
+end
diff --git a/spec/models/email_domain_block_spec.rb b/spec/models/email_domain_block_spec.rb
new file mode 100644
index 000000000..5f5d189d9
--- /dev/null
+++ b/spec/models/email_domain_block_spec.rb
@@ -0,0 +1,21 @@
+require 'rails_helper'
+
+RSpec.describe EmailDomainBlock, type: :model do
+  describe 'validations' do
+    it 'has a valid fabricator' do
+      email_domain_block = Fabricate.build(:email_domain_block)
+      expect(email_domain_block).to be_valid
+    end
+  end
+
+  describe 'block?' do
+    it 'returns true if the domain is registed' do
+      Fabricate(:email_domain_block, domain: 'example.com')
+      expect(EmailDomainBlock.block?('nyarn@example.com')).to eq true
+    end
+    it 'returns true if the domain is not registed' do
+      Fabricate(:email_domain_block, domain: 'domain')
+      expect(EmailDomainBlock.block?('example')).to eq false
+    end
+  end
+end