|
7 | 7 |
|
8 | 8 | let(:admin) { create(:user, :as_admin, twitter: "@getpublify") } |
9 | 9 | let!(:blog) { create(:blog, limit_article_display: 10) } |
| 10 | + let(:note) { create(:note, user_id: admin) } |
10 | 11 |
|
11 | 12 | before do |
12 | 13 | sign_in admin |
13 | 14 | end |
14 | 15 |
|
15 | | - context "with a blog" do |
16 | | - describe "index" do |
17 | | - let!(:notes) { create_list(:note, 2) } |
| 16 | + describe "#index" do |
| 17 | + let!(:notes) { create_list(:note, 2) } |
18 | 18 |
|
19 | | - it "shows the index template" do |
20 | | - get :index |
21 | | - expect(response).to render_template("index") |
22 | | - end |
| 19 | + it "shows the index template" do |
| 20 | + get :index |
| 21 | + expect(response).to render_template("index") |
| 22 | + end |
23 | 23 |
|
24 | | - it "lists existing notes" do |
25 | | - get :index |
26 | | - expect(assigns(:notes)).to match_array notes |
27 | | - end |
| 24 | + it "lists existing notes" do |
| 25 | + get :index |
| 26 | + expect(assigns(:notes)).to match_array notes |
| 27 | + end |
28 | 28 |
|
29 | | - it "assigns a new note for the note form" do |
30 | | - get :index |
| 29 | + it "assigns a new note for the note form" do |
| 30 | + get :index |
31 | 31 |
|
32 | | - aggregate_failures do |
33 | | - expect(assigns(:note)).to be_a(Note) |
34 | | - expect(assigns(:note).author).to eq(admin.login) |
35 | | - expect(assigns(:note).user).to eq(admin) |
36 | | - end |
| 32 | + aggregate_failures do |
| 33 | + expect(assigns(:note)).to be_a(Note) |
| 34 | + expect(assigns(:note).author).to eq(admin.login) |
| 35 | + expect(assigns(:note).user).to eq(admin) |
37 | 36 | end |
| 37 | + end |
38 | 38 |
|
39 | | - it "lists notes without publication date" do |
40 | | - create(:note, published_at: nil) |
| 39 | + it "lists notes without publication date" do |
| 40 | + create(:note, published_at: nil) |
41 | 41 |
|
42 | | - get :index |
43 | | - expect(response).to be_successful |
44 | | - end |
| 42 | + get :index |
| 43 | + expect(response).to be_successful |
45 | 44 | end |
| 45 | + end |
46 | 46 |
|
47 | | - describe "create" do |
48 | | - context "a simple note" do |
49 | | - before { post :create, params: { note: { body: "Emphasis _mine_" } } } |
| 47 | + describe "#create" do |
| 48 | + context "a simple note" do |
| 49 | + before { post :create, params: { note: { body: "Emphasis _mine_" } } } |
50 | 50 |
|
51 | | - it { expect(response).to redirect_to(admin_notes_path) } |
52 | | - it { expect(flash[:notice]).to eq(I18n.t("notice.note_successfully_created")) } |
53 | | - end |
| 51 | + it { expect(response).to redirect_to(admin_notes_path) } |
| 52 | + it { expect(flash[:notice]).to eq(I18n.t("notice.note_successfully_created")) } |
| 53 | + end |
| 54 | + |
| 55 | + it "creates a note" do |
| 56 | + expect do |
| 57 | + post :create, params: { note: { body: "Emphasis _mine_" } } |
| 58 | + end.to change(Note, :count).from(0).to(1) |
| 59 | + end |
54 | 60 |
|
55 | | - it "creates a note" do |
56 | | - expect do |
57 | | - post :create, params: { note: { body: "Emphasis _mine_" } } |
58 | | - end.to change(Note, :count).from(0).to(1) |
| 61 | + context "with twitter access configured" do |
| 62 | + before do |
| 63 | + blog.twitter_consumer_key = "consumer_key" |
| 64 | + blog.twitter_consumer_secret = "consumer_secret" |
| 65 | + blog.save |
| 66 | + |
| 67 | + admin.twitter_oauth_token = "oauth_token" |
| 68 | + admin.twitter_oauth_token_secret = "oauth_token" |
| 69 | + admin.save |
59 | 70 | end |
60 | 71 |
|
61 | | - context "with twitter access configured" do |
62 | | - before do |
63 | | - blog.twitter_consumer_key = "consumer_key" |
64 | | - blog.twitter_consumer_secret = "consumer_secret" |
65 | | - blog.save |
66 | | - |
67 | | - admin.twitter_oauth_token = "oauth_token" |
68 | | - admin.twitter_oauth_token_secret = "oauth_token" |
69 | | - admin.save |
70 | | - end |
71 | | - |
72 | | - it "sends the note to twitter" do |
73 | | - expect(Note.count).to eq(0) |
74 | | - twitter_cli = double(:twitter_cli) |
75 | | - expect(Twitter::Client).to receive(:new).and_return(twitter_cli) |
76 | | - tweet = Struct.new(:attrs).new({ id_str: "2344" }) |
77 | | - expect(twitter_cli).to receive(:update).and_return(tweet) |
78 | | - post :create, params: { note: { body: "Emphasis _mine_, arguments *strong*" }, |
79 | | - push_to_twitter: "true" } |
80 | | - expect(Note.first.twitter_id).to eq("2344") |
81 | | - end |
| 72 | + it "sends the note to twitter" do |
| 73 | + expect(Note.count).to eq(0) |
| 74 | + twitter_cli = double(:twitter_cli) |
| 75 | + expect(Twitter::Client).to receive(:new).and_return(twitter_cli) |
| 76 | + tweet = Struct.new(:attrs).new({ id_str: "2344" }) |
| 77 | + expect(twitter_cli).to receive(:update).and_return(tweet) |
| 78 | + post :create, params: { note: { body: "Emphasis _mine_, arguments *strong*" }, |
| 79 | + push_to_twitter: "true" } |
| 80 | + expect(Note.first.twitter_id).to eq("2344") |
82 | 81 | end |
83 | 82 | end |
| 83 | + end |
84 | 84 |
|
85 | | - context "with an existing note from current user" do |
86 | | - let(:note) { create(:note, user_id: admin) } |
87 | | - |
88 | | - describe "edit" do |
89 | | - before { get :edit, params: { id: note.id } } |
| 85 | + describe "#edit" do |
| 86 | + before { get :edit, params: { id: note.id } } |
90 | 87 |
|
91 | | - it { expect(response).to be_successful } |
92 | | - it { expect(response).to render_template("edit") } |
93 | | - it { expect(assigns(:note)).to eq(note) } |
94 | | - it { expect(assigns(:notes)).to eq([note]) } |
95 | | - end |
| 88 | + it { expect(response).to be_successful } |
| 89 | + it { expect(response).to render_template("edit") } |
| 90 | + it { expect(assigns(:note)).to eq(note) } |
| 91 | + it { expect(assigns(:notes)).to eq([note]) } |
| 92 | + end |
96 | 93 |
|
97 | | - describe "update" do |
98 | | - before { post :update, params: { id: note.id, note: { body: "new body" } } } |
| 94 | + describe "#update" do |
| 95 | + before { post :update, params: { id: note.id, note: { body: "new body" } } } |
99 | 96 |
|
100 | | - it { expect(response).to redirect_to(action: :index) } |
101 | | - it { expect(note.reload.body).to eq("new body") } |
102 | | - end |
| 97 | + it { expect(response).to redirect_to(action: :index) } |
| 98 | + it { expect(note.reload.body).to eq("new body") } |
| 99 | + end |
103 | 100 |
|
104 | | - describe "show" do |
105 | | - before { get :show, params: { id: note.id } } |
| 101 | + describe "#show" do |
| 102 | + before { get :show, params: { id: note.id } } |
106 | 103 |
|
107 | | - it { expect(response).to render_template("show") } |
108 | | - end |
| 104 | + it { expect(response).to render_template("show") } |
| 105 | + end |
109 | 106 |
|
110 | | - describe "Destroying a note" do |
111 | | - before { post :destroy, params: { id: note.id } } |
| 107 | + describe "#destroy" do |
| 108 | + before { post :destroy, params: { id: note.id } } |
112 | 109 |
|
113 | | - it { expect(response).to redirect_to(admin_notes_path) } |
114 | | - it { expect(Note.count).to eq(0) } |
115 | | - end |
116 | | - end |
| 110 | + it { expect(response).to redirect_to(admin_notes_path) } |
| 111 | + it { expect(Note.count).to eq(0) } |
117 | 112 | end |
118 | 113 | end |
0 commit comments