pugin 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+ require 'pugin/feature/bandiera'
3
+
4
+ describe 'The bandiera client' do
5
+
6
+ context 'when checking if Parliament is in dissolution' do
7
+ context 'when the feature exists in Bandiera' do
8
+
9
+ before :each do
10
+ Pugin::Feature::Bandiera.instance_variable_set(:@features, {'show-dissolution' => true})
11
+ end
12
+
13
+ it "returns the value of show-dissolution in the Bandiera database if it exists" do
14
+ expect(Pugin::Feature::Bandiera.dissolution?).to equal(true)
15
+ end
16
+ end
17
+
18
+ context 'when the feature does not exist in Bandiera' do
19
+
20
+ before :each do
21
+ Pugin::Feature::Bandiera.instance_variable_set(:@features, {})
22
+ end
23
+
24
+ it "returns false because the feature value is nil" do
25
+ expect(Pugin::Feature::Bandiera.dissolution?).to equal(false)
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'when checking if you can still register to vote' do
31
+ context 'when the feature exists in Bandiera' do
32
+
33
+ before :each do
34
+ Pugin::Feature::Bandiera.instance_variable_set(:@features, {'show-register' => true})
35
+ end
36
+
37
+ it "returns the value of show-dissolution in the Bandiera database if it exists" do
38
+ expect(Pugin::Feature::Bandiera.register_to_vote?).to equal(true)
39
+ end
40
+ end
41
+
42
+ context 'when the feature does not exist in Bandiera' do
43
+
44
+ before :each do
45
+ Pugin::Feature::Bandiera.instance_variable_set(:@features, {})
46
+ end
47
+
48
+ it "returns false because the feature value is nil" do
49
+ expect(Pugin::Feature::Bandiera.register_to_vote?).to equal(false)
50
+ end
51
+ end
52
+ end
53
+
54
+ context 'when trying to reset the @features instance variable' do
55
+
56
+ before :each do
57
+ Pugin::Feature::Bandiera.instance_variable_set(:@features, {'show-register' => true})
58
+ end
59
+
60
+ it 'resets the @features instance variable back to nil' do
61
+ Pugin::Feature::Bandiera.reset
62
+ expect(@features).to equal(nil)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Pugin simple feature' do
4
+
5
+ before :example do
6
+ Pugin::Feature::SimpleFeature.disable
7
+ end
8
+
9
+ after :example do
10
+ Pugin::Feature::SimpleFeature.disable
11
+ end
12
+
13
+ it 'is initially disabled' do
14
+ expect(Pugin::Feature::SimpleFeature.enabled?).to equal(false)
15
+ end
16
+
17
+ context 'without being altered' do
18
+ it "returns false when checked if it's enabled" do
19
+ expect(Pugin::Feature::SimpleFeature.enabled?).to equal(false)
20
+ end
21
+ it "returns true when checked if it's disabled" do
22
+ expect(Pugin::Feature::SimpleFeature.disabled?).to equal(true)
23
+ end
24
+ end
25
+
26
+ context 'when being enabled' do
27
+
28
+ before :each do
29
+ Pugin::Feature::SimpleFeature.enable
30
+ end
31
+
32
+ it "returns true when checked if it's enabled" do
33
+ expect(Pugin::Feature::SimpleFeature.enabled?).to equal(true)
34
+ end
35
+ it "returns false when checked if it's disabled" do
36
+ expect(Pugin::Feature::SimpleFeature.disabled?).to equal(false)
37
+ end
38
+ end
39
+
40
+ context 'when being disabled' do
41
+
42
+ before :each do
43
+ Pugin::Feature::SimpleFeature.disable
44
+ end
45
+
46
+ it "returns false when checked if it's enabled" do
47
+ expect(Pugin::Feature::SimpleFeature.enabled?).to equal(false)
48
+ end
49
+ it "returns true when checked if it's disabled" do
50
+ expect(Pugin::Feature::SimpleFeature.disabled?).to equal(true)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Pugin status banner' do
4
+
5
+ before :example do
6
+ Pugin::Feature::StatusBanner.disable
7
+ end
8
+
9
+ after :example do
10
+ Pugin::Feature::StatusBanner.disable
11
+ end
12
+
13
+ it 'is initially disabled' do
14
+ expect(Pugin::Feature::StatusBanner.enabled?).to equal(false)
15
+ end
16
+
17
+ context 'without being altered' do
18
+ it "returns false when checked if it's enabled" do
19
+ expect(Pugin::Feature::StatusBanner.enabled?).to equal(false)
20
+ end
21
+ it "returns true when checked if it's disabled" do
22
+ expect(Pugin::Feature::StatusBanner.disabled?).to equal(true)
23
+ end
24
+ end
25
+
26
+ context 'when being enabled' do
27
+
28
+ before :each do
29
+ Pugin::Feature::StatusBanner.enable
30
+ end
31
+
32
+ it "returns true when checked if it's enabled" do
33
+ expect(Pugin::Feature::StatusBanner.enabled?).to equal(true)
34
+ end
35
+ it "returns false when checked if it's disabled" do
36
+ expect(Pugin::Feature::StatusBanner.disabled?).to equal(false)
37
+ end
38
+ end
39
+
40
+ context 'when being disabled' do
41
+
42
+ before :each do
43
+ Pugin::Feature::StatusBanner.disable
44
+ end
45
+
46
+ it "returns false when checked if it's enabled" do
47
+ expect(Pugin::Feature::StatusBanner.enabled?).to equal(false)
48
+ end
49
+ it "returns true when checked if it's disabled" do
50
+ expect(Pugin::Feature::StatusBanner.disabled?).to equal(true)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Pugin top navigation' do
4
+
5
+ before :example do
6
+ Pugin::Feature::TopNavigation.disable
7
+ end
8
+
9
+ after :example do
10
+ Pugin::Feature::TopNavigation.disable
11
+ end
12
+
13
+ it 'is initially disabled' do
14
+ expect(Pugin::Feature::TopNavigation.enabled?).to equal(false)
15
+ end
16
+
17
+ context 'without being altered' do
18
+ it "returns false when checked if it's enabled" do
19
+ expect(Pugin::Feature::TopNavigation.enabled?).to equal(false)
20
+ end
21
+ it "returns true when checked if it's disabled" do
22
+ expect(Pugin::Feature::TopNavigation.disabled?).to equal(true)
23
+ end
24
+ end
25
+
26
+ context 'when being enabled' do
27
+
28
+ before :each do
29
+ Pugin::Feature::TopNavigation.enable
30
+ end
31
+
32
+ it "returns true when checked if it's enabled" do
33
+ expect(Pugin::Feature::TopNavigation.enabled?).to equal(true)
34
+ end
35
+ it "returns false when checked if it's disabled" do
36
+ expect(Pugin::Feature::TopNavigation.disabled?).to equal(false)
37
+ end
38
+ end
39
+
40
+ context 'when being disabled' do
41
+
42
+ before :each do
43
+ Pugin::Feature::TopNavigation.disable
44
+ end
45
+
46
+ it "returns false when checked if it's enabled" do
47
+ expect(Pugin::Feature::TopNavigation.enabled?).to equal(false)
48
+ end
49
+ it "returns true when checked if it's disabled" do
50
+ expect(Pugin::Feature::TopNavigation.disabled?).to equal(true)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Pugin feature module' do
4
+ context 'when attempting to enable a feature that exists' do
5
+
6
+ before :each do
7
+ Pugin::Feature.enable('StatusBanner')
8
+ end
9
+
10
+ it 'should successfully enable the feature' do
11
+ expect(Pugin::Feature::StatusBanner.enabled?).to equal(true)
12
+ end
13
+ end
14
+
15
+ context 'when attempting to disable a feature that exists' do
16
+ before :each do
17
+ Pugin::Feature.disable('StatusBanner')
18
+ end
19
+
20
+ it 'should successfully disable the feature' do
21
+ expect(Pugin::Feature::StatusBanner.enabled?).to equal(false)
22
+ end
23
+ end
24
+
25
+ context "when attempting to enable a feature that doesn't exist" do
26
+ it 'should raise an ArgumentError' do
27
+ expect {Pugin::Feature.enable('NonExistentFeature')}.to raise_error(ArgumentError)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'pugin/helpers/controller_helpers'
3
+
4
+ describe 'pugin/helpers/controller_helpers.rb' do
5
+
6
+ before do
7
+ class TestClass
8
+ include Pugin::Helpers::ControllerHelpers
9
+ end
10
+ end
11
+
12
+ subject { TestClass.new }
13
+
14
+ context '#enable_status_banner' do
15
+ it 'enables the status banner' do
16
+ subject.enable_status_banner
17
+ expect(Pugin::Feature::TopNavigation.enabled?).to equal(true)
18
+ end
19
+ end
20
+ context '#disable_status_banner' do
21
+
22
+ before :each do
23
+ Pugin::Feature::StatusBanner.enable
24
+ end
25
+
26
+ it 'disables the status banner' do
27
+ expect(Pugin::Feature::StatusBanner.disabled?).to equal(false)
28
+ subject.disable_status_banner
29
+ expect(Pugin::Feature::StatusBanner.disabled?).to equal(true)
30
+ end
31
+ end
32
+ context '#enable_top_navigation' do
33
+ it 'enables the top navigation' do
34
+ subject.enable_top_navigation
35
+ expect(Pugin::Feature::TopNavigation.enabled?).to equal(true)
36
+ end
37
+ end
38
+ context '#disable_top_navigation' do
39
+
40
+ before :each do
41
+ Pugin::Feature::TopNavigation.enable
42
+ end
43
+
44
+ it 'disables the top navigation' do
45
+ expect(Pugin::Feature::TopNavigation.disabled?).to equal(false)
46
+ subject.disable_top_navigation
47
+ expect(Pugin::Feature::TopNavigation.disabled?).to equal(true)
48
+ end
49
+ end
50
+ context '#reset_bandiera_features' do
51
+ before :each do
52
+ Pugin::Feature::Bandiera.instance_variable_set(:@features, {'show-register' => true, 'show-dissolution' => true})
53
+ end
54
+
55
+ it 'resets @features back to nil' do
56
+ subject.reset_bandiera_features
57
+ expect(Pugin::Feature::Bandiera.instance_variable_get(:@features)).to equal(nil)
58
+ end
59
+ end
60
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'simplecov'
2
2
  require 'coveralls'
3
+
3
4
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
4
5
  Coveralls::SimpleCov::Formatter,
5
6
  SimpleCov::Formatter::HTMLFormatter
@@ -8,6 +9,8 @@ SimpleCov.start
8
9
 
9
10
  ENV['RAILS_ENV'] ||= 'test'
10
11
 
12
+ require 'bandiera/client'
13
+
11
14
  require File.expand_path('../dummy/config/environment.rb', __FILE__)
12
15
  require 'rspec/rails'
13
16
  require 'factory_girl_rails'
@@ -6,14 +6,8 @@ describe 'pugin/components/_status.html.haml', type: :view do
6
6
  context 'while not in a dissolution' do
7
7
 
8
8
  before :each do
9
- module FlagHelper
10
- def self.dissolution?
11
- false
12
- end
13
- def self.register_to_vote?
14
- false
15
- end
16
- end
9
+ allow(Pugin::Feature::Bandiera).to receive(:dissolution?).and_return(false)
10
+ allow(Pugin::Feature::Bandiera).to receive(:register_to_vote?).and_return(false)
17
11
  end
18
12
 
19
13
  it 'renders a message not related to the dissolution' do
@@ -38,14 +32,8 @@ DATA
38
32
  context 'while in a dissolution and still able to register to vote' do
39
33
 
40
34
  before :each do
41
- module FlagHelper
42
- def self.dissolution?
43
- true
44
- end
45
- def self.register_to_vote?
46
- true
47
- end
48
- end
35
+ allow(Pugin::Feature::Bandiera).to receive(:dissolution?).and_return(true)
36
+ allow(Pugin::Feature::Bandiera).to receive(:register_to_vote?).and_return(true)
49
37
  end
50
38
 
51
39
  it 'renders a message that shows a link to register to vote' do
@@ -71,14 +59,8 @@ DATA
71
59
  context 'while in a dissolution and registration has closed' do
72
60
 
73
61
  before :each do
74
- module FlagHelper
75
- def self.dissolution?
76
- true
77
- end
78
- def self.register_to_vote?
79
- false
80
- end
81
- end
62
+ allow(Pugin::Feature::Bandiera).to receive(:dissolution?).and_return(true)
63
+ allow(Pugin::Feature::Bandiera).to receive(:register_to_vote?).and_return(false)
82
64
  end
83
65
 
84
66
  it 'renders a message that reminds the user of the general election date' do
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+ require 'haml'
3
+
4
+ describe 'pugin/constituencies/list/_list.html.haml', type: :view do
5
+
6
+ context 'with a current constituency data set' do
7
+
8
+ before :each do
9
+ constituency = Class.new
10
+ allow(constituency).to receive(:current?).and_return(true)
11
+ allow(constituency).to receive(:name).and_return('Aberavon')
12
+ allow(constituency).to receive(:graph_id).and_return('123')
13
+ allow(constituency).to receive(:members).and_return([])
14
+ @constituencies = [constituency]
15
+ end
16
+
17
+ it "shows the constituency's name as a link" do
18
+ render partial: "pugin/constituencies/list/list", collection: @constituencies, as: "constituencies".to_sym
19
+ expect(response).to include("<a href='/constituencies/123'>Aberavon</a>")
20
+ end
21
+
22
+ context 'with a current member' do
23
+
24
+ before :each do
25
+ constituency = Class.new
26
+ members = Class.new
27
+ allow(members).to receive(:display_name).and_return('Test Name')
28
+ allow(constituency).to receive(:members).and_return([members])
29
+ allow(constituency).to receive(:current?).and_return(true)
30
+ allow(constituency).to receive(:name).and_return('Aberavon')
31
+ allow(constituency).to receive(:graph_id).and_return('123')
32
+ @constituencies = [constituency]
33
+ end
34
+
35
+ it "displays the member's name" do
36
+ render partial: "pugin/constituencies/list/list", collection: @constituencies, as: "constituencies".to_sym
37
+ expect(response).to include("<h2>\n<a href='/constituencies/123'>Aberavon</a>\n</h2>")
38
+ expect(response).to include("<p>Test Name</p>")
39
+ end
40
+ end
41
+
42
+ context 'without a current member' do
43
+
44
+ before :each do
45
+ constituency = Class.new
46
+ allow(constituency).to receive(:current?).and_return(true)
47
+ allow(constituency).to receive(:name).and_return('Aberavon')
48
+ allow(constituency).to receive(:graph_id).and_return('123')
49
+ allow(constituency).to receive(:members).and_return([])
50
+ @constituencies = [constituency]
51
+ end
52
+
53
+ it 'displays the vacant i18n message' do
54
+ render partial: "pugin/constituencies/list/list", collection: @constituencies, as: "constituencies".to_sym
55
+ expect(response).to include("<h2>\n<a href='/constituencies/123'>Aberavon</a>\n</h2>")
56
+ expect(response).to include("<p>Vacant</p>")
57
+ end
58
+ end
59
+ end
60
+
61
+ context 'with a previous constituency data set' do
62
+
63
+ before :each do
64
+ constituency = Class.new
65
+ allow(constituency).to receive(:current?).and_return(false)
66
+ allow(constituency).to receive(:name).and_return('Aberavon')
67
+ allow(constituency).to receive(:graph_id).and_return('123')
68
+ @constituencies = [constituency]
69
+ end
70
+
71
+ it 'displays the previous constituency i18n message' do
72
+ render partial: "pugin/constituencies/list/list", collection: @constituencies, as: "constituencies".to_sym
73
+ expect(response).to include("<h2>\n<a href='/constituencies/123'>Aberavon</a>\n</h2>")
74
+ expect(response).to include("<p>Former constituency</p>")
75
+ end
76
+ end
77
+
78
+ end