homesteading_publisher 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/spec/factories.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  FactoryGirl.define do
2
2
  factory :post do
3
- title "Post Test"
3
+ year 1979
4
+ month 9
5
+ day 18
6
+ hour 14
7
+ minute 30
8
+ second "00"
9
+ slug "test-slug"
4
10
  end
5
11
 
6
12
  factory :setting do
@@ -1,9 +1,10 @@
1
- require 'rails_helper'
1
+ require "rails_helper"
2
2
 
3
3
  describe License do
4
4
  let(:license) { create(:license) }
5
- describe '.options_for_select' do
6
- it 'gives an array' do
5
+
6
+ describe ".options_for_select" do
7
+ it "gives an array" do
7
8
  license
8
9
  expect(License.options_for_select.first).to eq ["License Name (LN)", license.id]
9
10
  end
@@ -1,10 +1,221 @@
1
1
  require "rails_helper"
2
2
 
3
3
  describe Post do
4
- describe '.validates' do
5
- let(:post) { create(:post) }
6
- it 'is valid' do
7
- expect(post.valid?).to eq true
4
+ describe "validations" do
5
+ subject { create(:post) }
6
+
7
+ it "has a valid fabricator" do
8
+ expect(subject).to be_valid
9
+ end
10
+
11
+ it "validates presence of year" do
12
+ subject.year = ""
13
+ expect(subject).not_to be_valid
14
+ end
15
+
16
+ it "validates presence of month" do
17
+ subject.month = ""
18
+ expect(subject).not_to be_valid
19
+ end
20
+
21
+ it "validates presence of day" do
22
+ subject.day = ""
23
+ expect(subject).not_to be_valid
24
+ end
25
+
26
+ it "validates presence of hour" do
27
+ subject.hour = ""
28
+ expect(subject).not_to be_valid
29
+ end
30
+
31
+ it "validates presence of minute" do
32
+ subject.minute = ""
33
+ expect(subject).not_to be_valid
34
+ end
35
+
36
+ it "validates presence of second" do
37
+ subject.second = ""
38
+ expect(subject).not_to be_valid
39
+ end
40
+
41
+ it "validates presence of slug" do
42
+ subject.slug = ""
43
+ expect(subject).not_to be_valid
44
+ end
45
+ end
46
+
47
+ describe "default_scope sort order" do
48
+ pending
49
+ # newest posts first
50
+ # default_scope { order("published_at desc") }
51
+ end
52
+
53
+ describe "#path" do
54
+ subject { create(:post) }
55
+ before { create(:setting, name: "Post Type", content: "fake-post") }
56
+
57
+ it "creates a path for post permalink URL" do
58
+ subject.year = 1979
59
+ subject.month = 9
60
+ subject.day = 18
61
+ expect(subject.path).to eq "/fake-posts/1979/09/18/test-slug"
62
+ end
63
+
64
+ context "when #published_at is nil" do
65
+ let(:path) { create(:post, published_at: nil).path }
66
+
67
+ it "it sets it to now" do
68
+ Time.stub(:now).and_return(Time.parse("Jan 31, 1986"))
69
+ expect(path).to eq "/fake-posts/1986/01/31/test-slug"
70
+ end
71
+ end
72
+
73
+ context "when #published_at is not nil" do
74
+ let(:post) { create(:post, published_at: 5.minutes.ago) }
75
+ subject { post.path }
76
+
77
+ it "is '/fake-posts/:year/:month/:day/:slug'" do
78
+ year = post.published_at.year
79
+ month = post.published_at.month.to_s.rjust(2, '0')
80
+ day = post.published_at.day.to_s.rjust(2, '0')
81
+ slug = post.slug
82
+ expect(subject).to eq "/fake-posts/#{year}/#{month}/#{day}/#{slug}"
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ describe "#params" do
89
+ subject { create(:post).params }
90
+
91
+ it "returns a hash of date and slug values" do
92
+ subject[:year] = 1979
93
+ subject[:month] = 9
94
+ subject[:day] = 18
95
+
96
+ params_hash = { slug: "test-slug", year: 1979, month: 9, day: 18 }
97
+ expect(subject).to eq params_hash
98
+ end
99
+ end
100
+
101
+ describe "#public?" do
102
+ subject { create(:post) }
103
+
104
+ context "when #private is true" do
105
+ subject { build(:post, private: true).public? }
106
+
107
+ it "is private" do
108
+ expect(subject).to eq false
109
+ end
110
+ end
111
+
112
+ context "when #private is nil" do
113
+ subject { build(:post, private: nil).public? }
114
+
115
+ it "is public" do
116
+ expect(subject).to eq true
117
+ end
118
+ end
119
+
120
+ context "when #private is false" do
121
+ subject { build(:post, private: false).public? }
122
+
123
+ it "is public" do
124
+ expect(subject).to eq true
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ describe "#name" do
131
+ subject { create(:post) }
132
+
133
+ context "when #title is populated" do
134
+ subject { build(:post, title: "Test Title").name }
135
+
136
+ it "is a title" do
137
+ expect(subject).to eq "Test Title"
138
+ end
139
+ end
140
+
141
+ context "when #title and #subtitle are populated" do
142
+ subject { build(:post, title: "Test Title", subtitle: "Test SUBTitle").name }
143
+
144
+ it "is a title + subtitle" do
145
+ expect(subject).to eq "Test Title : Test SUBTitle"
146
+ end
147
+ end
148
+
149
+ context "when neither #title nor #subtitle is populated" do
150
+ subject { build(:post, title: nil, subtitle: nil).name }
151
+
152
+ it "is blank" do
153
+ expect(subject).to eq ""
154
+ end
155
+ end
156
+ end
157
+
158
+ describe "#set_published_at_attrs" do
159
+ subject { build(:post, published_at: Time.parse("18 Sep 1979 14:30:00 UTC +00:00")) }
160
+
161
+ it "year is 1979" do
162
+ expect(subject.year).to eq "1979"
163
+ end
164
+
165
+ it "month is September" do
166
+ expect(subject.month).to eq "09"
167
+ end
168
+
169
+ it "day is the 18th" do
170
+ expect(subject.day).to eq "18"
171
+ end
172
+
173
+ it "hour is 2PM" do
174
+ expect(subject.hour).to eq "14"
175
+ end
176
+
177
+ it "minute is halp passed" do
178
+ expect(subject.minute).to eq "30"
179
+ end
180
+
181
+ it "second is zero" do
182
+ expect(subject.second).to eq "00"
183
+ end
184
+ end
185
+
186
+ describe "#set_slug" do
187
+ subject { create(:post) }
188
+
189
+ context "when #slug is populated" do
190
+ subject { build(:post, slug: "turtles-all-the-way-down", title: "Test Post Title").slug }
191
+
192
+ it "is slugged" do
193
+ expect(subject).to eq "turtles-all-the-way-down"
194
+ end
195
+ end
196
+
197
+ context "when only #title is populated" do
198
+ subject { build(:post, slug: nil, title: "Test Post Title").slug }
199
+
200
+ it "is slugged" do
201
+ expect(subject).to eq "test-post-title"
202
+ end
203
+ end
204
+
205
+ context "when only #content is populated" do
206
+ subject { build(:post, slug: nil, content: "Lorem Impsum").slug }
207
+
208
+ it "is slugged" do
209
+ expect(subject).to eq "lorem-impsum"
210
+ end
211
+ end
212
+
213
+ context "when both #title and #content are populated" do
214
+ subject { build(:post, slug: nil, title: "Test Post Title", content: "Lorem Impsum").slug }
215
+
216
+ it "is slugged" do
217
+ expect(subject).to eq "test-post-title"
218
+ end
8
219
  end
9
220
  end
10
221
  end
@@ -1,10 +1,51 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Setting do
4
- let(:setting) { create(:setting) }
5
- describe '.validates' do
6
- it 'is valid' do
7
- expect(setting.valid?).to eq true
4
+ describe "validations" do
5
+ subject { create(:setting) }
6
+
7
+ it "has a valid fabricator" do
8
+ expect(subject).to be_valid
9
+ end
10
+
11
+ it "validates presence of name" do
12
+ subject.name = ""
13
+ expect(subject).not_to be_valid
14
+ end
15
+
16
+ it "validates presence of content" do
17
+ subject.content = ""
18
+ expect(subject).not_to be_valid
19
+ end
20
+ end
21
+
22
+ describe "#editable" do
23
+ subject { Setting.editable }
24
+
25
+ it "includes settings with editable set to true" do
26
+ editable_setting = create(:setting, editable: true)
27
+ expect(subject).to include(editable_setting)
28
+ end
29
+
30
+ it "excludes settings without editable set to true" do
31
+ non_editable_setting = create(:setting, editable: false)
32
+ expect(subject).not_to include(non_editable_setting)
33
+ end
34
+ end
35
+
36
+ describe "#name" do
37
+ subject { create(:setting, name: "URL Setting").name }
38
+
39
+ it "does not change name's case" do
40
+ expect(subject).to eq "URL Setting"
41
+ end
42
+ end
43
+
44
+ describe "#key" do
45
+ subject { create(:setting, name: "URL Setting").key }
46
+
47
+ it "downcases and replaces underscores with spaces" do
48
+ expect(subject).to eq "url_setting"
8
49
  end
9
50
  end
10
51
  end
data/spec/rails_helper.rb CHANGED
@@ -1,3 +1,8 @@
1
+ if ENV["CODECLIMATE_REPO_TOKEN"]
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
1
6
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
7
  ENV["RAILS_ENV"] ||= 'test'
3
8
  require 'spec_helper'
@@ -23,7 +28,6 @@ RSpec.configure do |config|
23
28
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
24
29
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
25
30
 
26
-
27
31
  # If you're not using ActiveRecord, or you'd prefer not to run each of your
28
32
  # examples within a transaction, remove the following line or assign false
29
33
  # instead of true.
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,3 @@
1
- # if ENV["CODECLIMATE_REPO_TOKEN"]
2
- # require "codeclimate-test-reporter"
3
- # CodeClimate::TestReporter.start
4
- # end
5
-
6
1
  ENV["RAILS_ENV"] ||= "test"
7
2
  require File.expand_path("../dummy/config/environment", __FILE__)
8
3
  require "rspec/rails"
@@ -1,3 +1,2 @@
1
1
  class Post < Homesteading::Post
2
-
3
2
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: homesteading_publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Becker
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-14 00:00:00.000000000 Z
12
+ date: 2015-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -152,7 +152,12 @@ files:
152
152
  - spec/dummy/config/locales/en.yml
153
153
  - spec/dummy/config/routes.rb
154
154
  - spec/dummy/config/secrets.yml
155
+ - spec/dummy/db/development.sqlite3
156
+ - spec/dummy/db/production.sqlite3
155
157
  - spec/dummy/db/schema.rb
158
+ - spec/dummy/db/test.sqlite3
159
+ - spec/dummy/log/development.log
160
+ - spec/dummy/log/test.log
156
161
  - spec/dummy/public/404.html
157
162
  - spec/dummy/public/422.html
158
163
  - spec/dummy/public/500.html
@@ -184,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
189
  version: '0'
185
190
  requirements: []
186
191
  rubyforge_project:
187
- rubygems_version: 2.2.2
192
+ rubygems_version: 2.4.6
188
193
  signing_key:
189
194
  specification_version: 4
190
195
  summary: A generic Rails Engine that all HS-* post type publisher apps build on top
@@ -218,7 +223,12 @@ test_files:
218
223
  - spec/dummy/config/routes.rb
219
224
  - spec/dummy/config/secrets.yml
220
225
  - spec/dummy/config.ru
226
+ - spec/dummy/db/development.sqlite3
227
+ - spec/dummy/db/production.sqlite3
221
228
  - spec/dummy/db/schema.rb
229
+ - spec/dummy/db/test.sqlite3
230
+ - spec/dummy/log/development.log
231
+ - spec/dummy/log/test.log
222
232
  - spec/dummy/public/404.html
223
233
  - spec/dummy/public/422.html
224
234
  - spec/dummy/public/500.html