Skip to content

Commit 7ee1f21

Browse files
committed
added the abolity to create a ds18b20 temp sensor
1 parent 09404b7 commit 7ee1f21

17 files changed

+115
-8
lines changed

Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ruby "2.4.0"
55
gem "autoprefixer-rails"
66
gem "delayed_job_active_record"
77
gem "flutie"
8-
gem "honeybadger"
8+
#gem "honeybadger"
99
gem "jquery-rails"
1010
gem "normalize-rails", "~> 3.0.0"
1111
gem "pg"
@@ -61,4 +61,4 @@ end
6161
gem 'high_voltage'
6262
gem 'bourbon', '~> 5.0.0.beta.7'
6363
gem 'neat', '~> 2.0.0.beta.1'
64-
gem 'refills', group: [:development, :test]
64+
gem 'refills', group: [:development, :test]

Gemfile.lock

-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ GEM
103103
activesupport (>= 4.1.0)
104104
hashdiff (0.3.2)
105105
high_voltage (3.0.0)
106-
honeybadger (3.1.0)
107106
i18n (0.8.1)
108107
jquery-rails (4.3.1)
109108
rails-dom-testing (>= 1, < 3)
@@ -282,7 +281,6 @@ DEPENDENCIES
282281
flutie
283282
formulaic
284283
high_voltage
285-
honeybadger
286284
jquery-rails
287285
launchy
288286
listen
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Controller for the ds18b20 model
2+
class Ds18b20sController < ApplicationController
3+
4+
def new
5+
@ds18b20 = Ds18b20.new
6+
end
7+
8+
def create
9+
temp_sensor = Ds18b20.new(ds18b20_params)
10+
temp_sensor.save
11+
redirect_to home_path
12+
end
13+
14+
private
15+
16+
def ds18b20_params
17+
params.require(:ds18b20).permit(
18+
:name,
19+
:path,
20+
:file
21+
)
22+
23+
end
24+
end

app/models/ds18b20.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Ds18b20 < ApplicationRecord
2+
end

app/views/ds18b20s/_form.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<%= form.input :name, lable: 'Name', required: true %>
2+
<%= form.input :path, required: true, :input_html => { :value => 0 } %>
3+
<%= form.input :file, required: true %>
4+
<%= form.button :submit %>

app/views/ds18b20s/new.html.erb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<%= I18n.t('views.ds18b20s.new') %>
2+
3+
<%= simple_form_for @ds18b20 do |form| %>
4+
<%= form.input :name %>
5+
<%= form.input :path %>
6+
<%= form.input :file %>
7+
<%= form.button :submit, I18n.t("views.generic.buttons.save") %>
8+
<% end %>

app/views/pages/home.html.erb

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
<h1>
22
Sensor Manager
3+
<p>
4+
5+
<%= link_to I18n.t("views.home.link.ds18b20_create"), new_ds18b20s_path%>
6+
<p>
7+
8+
<% @sensors = Ds18b20.all %>
9+
<% @sensors.each do |s| %>
10+
<%= s.name %>
11+
<% end %>
312
</h1>

config/locales/en.yml

+15
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ en:
1717

1818
titles:
1919
application: Sensor manager
20+
21+
simple_form:
22+
labels:
23+
defaults:
24+
submit: Save
25+
26+
views:
27+
home:
28+
link:
29+
ds18b20_create: New DS18B20 Temp Sensor
30+
generic:
31+
buttons:
32+
save: Save
33+
ds18b20s:
34+
new: New DS18B20 Temp Sensor

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Rails.application.routes.draw do
2+
resource :ds18b20s, only: [:new, :create]
23
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class CreateDs18b20s < ActiveRecord::Migration[5.0]
2+
def change
3+
create_table :ds18b20s do |t|
4+
t.string :name
5+
6+
t.timestamps
7+
end
8+
end
9+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddPathtoDs18b20 < ActiveRecord::Migration[5.0]
2+
def change
3+
add_column :ds18b20s, :path, :string
4+
end
5+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddFiletoDs18b20 < ActiveRecord::Migration[5.0]
2+
def change
3+
add_column :ds18b20s, :file, :string
4+
end
5+
end

db/schema.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 20170329193609) do
13+
ActiveRecord::Schema.define(version: 20170404205852) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -30,4 +30,12 @@
3030
t.index ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
3131
end
3232

33+
create_table "ds18b20s", force: :cascade do |t|
34+
t.string "name"
35+
t.datetime "created_at", null: false
36+
t.datetime "updated_at", null: false
37+
t.string "path"
38+
t.string "file"
39+
end
40+
3341
end

spec/factories.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
FactoryGirl.define do
2+
factory :ds18b20 do
3+
name "MyString"
4+
end
25
end

spec/features/using_ds18b20_spec.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
feature 'Visitor' do
44
scenario 'creates a new DS18B20 sensor' do
5-
click_link I18n.t('views.ds18b20.link.ds18b20_create')
6-
fill_in 'name', with: 'sensor1'
7-
fill_in 'path', with: '/tmp/1st_sensor.txt'
5+
visit '/'
6+
click_link I18n.t('views.home.link.ds18b20_create')
7+
fill_in 'ds18b20_name', with: 'sensor1'
8+
fill_in 'ds18b20_path', with: '/tmp/ensors_path'
9+
fill_in 'ds18b20_file', with: '1st_sensor.txt'
810
click_button I18n.t('views.generic.buttons.save')
911

1012
expect(page).to have_content('sensor1')

spec/models/ds1820b_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Ds18b20, type: :model do
4+
it { should respond_to :name }
5+
6+
7+
end

spec/models/ds18b20_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Ds18b20, type: :model do
4+
it {should respond_to :name}
5+
it {should respond_to :path}
6+
it {should respond_to :file}
7+
end

0 commit comments

Comments
 (0)